NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Utility to redirect UDP packets


     In the past people have asked how to receive UDP packets and 
relay them to another IP address while keeping track of 
replies. Basically a utility that does what rinetd does for tcp 
connections. I found a utility that does just that called udp_redirect:

     It required very minimal changes to compile under NetBSD. Mainly I 
had to include a local version of netinet/ip.h that lacked the 
"struct        ip_timestamp {" section. I must have had to do this for 
another project because I already had the modified ip.h file. Without 
the local ip.h the error is:

Highlander:~/udp_redirect# cc -o udp_redirect udp_redirect.c
In file included from udp_redirect.c:44:
/usr/include/netinet/ip.h:149: error: expected specifier-qualifier-list 
before 'n_time'

     I'm including the diff below. I think this would be a good tool to 
include in pkgsrc. I'm using it to query a router via SNMP (for mrtg).

Jason Mitchell

PTI:~/customcode/udp_redirect#diff udp_redirect.c 
 > #include "ip.h"
 >       struct sockaddr_in a, sa, da;
 >       int os;
<       int os=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);
 >       os=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP);
<       struct sockaddr_in a;
<       struct sockaddr_in sa;
<       struct sockaddr_in da; da.sin_addr.s_addr=0;
 >       da.sin_addr.s_addr=0;

And here's the section I commented out in ip.h

// struct       ip_timestamp {
//      u_int8_t ipt_code;              /* IPOPT_TS */
//      u_int8_t ipt_len;               /* size of structure (variable) */
//      u_int8_t ipt_ptr;               /* index of current entry */
//      u_int8_t ipt_flg:4,             /* flags, see below */
//               ipt_oflw:4;            /* overflow counter */
//      u_int8_t ipt_oflw:4,            /* overflow counter */
//               ipt_flg:4;             /* flags, see below */
//      union ipt_timestamp {
//               n_time ipt_time[1];
//               struct ipt_ta {
//                      struct in_addr ipt_addr;
//                      n_time ipt_time;
//               } ipt_ta[1] __attribute__((__packed__));
//      } ipt_timestamp __attribute__((__packed__));
// __attribute__((__packed__));

Home | Main Index | Thread Index | Old Index