$NetBSD: patch-ac,v 1.1 2004/07/21 21:49:02 scw Exp $ --- dissipate2/siputil.cpp.orig 2004-03-04 11:22:57.000000000 +0000 +++ dissipate2/siputil.cpp 2004-07-21 12:11:34.000000000 +0100 @@ -5,6 +5,9 @@ #include #include #include +#if defined (__FreeBSD__) || defined(__NetBSD__) +#include +#endif #include #include #include @@ -12,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +29,8 @@ /* max number of network interfaces*/ #define MAX_IF 5 +#ifdef __linux__ + /* Path to the route entry in proc filesystem */ #define PROCROUTE "/proc/net/route" @@ -40,6 +46,8 @@ #define SIOCGIFCOUNT 0x8935 #endif +#endif /* not Linux */ + char iface[16]; @@ -61,6 +69,7 @@  */ char *getdefaultdev() { +#ifdef __linux__ FILE *fp = fopen( PROCROUTE, "r"); char buff[4096], gate_addr[128], net_addr[128]; char mask_addr[128]; @@ -84,19 +93,49 @@ return iface; } fclose(fp); + /* didn't find a default gateway */ return NULL; +#else + return ""; +#endif /* Linux */ } void findFqdn( void ) { - int sock, err, if_count, i, j = 0; + int if_count, i, j = 0; +#if !(defined(__FreeBSD__) || defined(__NetBSD__)) + int sock, err; struct ifconf netconf; char buffer[32*MAX_IF]; - char if_name[10][21]; - char if_addr[10][21]; +#endif + char if_name[MAX_IF][21]; + char if_addr[MAX_IF][21]; char *default_ifName; +#if defined(__FreeBSD__) || defined(__NetBSD__) + struct ifaddrs *ifp, *oifp; + + if(getifaddrs(&ifp) < 0 ) + printf( "Error with getifaddrs(): %i.\n", errno ); + oifp=ifp; /* save ifp */ + for (if_count = 0; ifp != NULL; ifp = ifp->ifa_next) { + if(ifp->ifa_addr->sa_family != AF_INET) continue; + + if ( strncmp( ifp->ifa_name, "lo", 2 ) != 0 ) { + if(j == MAX_IF) printf( "Error: cannot handle more than %d interfaces.\n",MAX_IF); + else + { + strncpy( if_name[j], ifp->ifa_name, 20); + strncpy( if_addr[j], inet_ntoa(((struct sockaddr_in *)ifp->ifa_addr)->sin_addr ), 20); + j++; + } + } + if_count++; + } + if (oifp != NULL) freeifaddrs(oifp); + +#else /* not FreeBSD or NetBSD */ netconf.ifc_len = 32 * MAX_IF; netconf.ifc_buf = buffer; sock=socket( PF_INET, SOCK_DGRAM, 0 ); @@ -104,9 +143,11 @@ if ( err < 0 ) printf( "Error in ioctl: %i.\n", errno ); close( sock ); if_count = netconf.ifc_len / 32; +#endif printf( "Found %i interfaces.\n", if_count ); //#test +#if !(defined(__FreeBSD__) || defined(__NetBSD__)) if ( if_count == 1 ) { strncpy( if_name[j], netconf.ifc_req[0].ifr_name, 20 ); strncpy( if_addr[j], inet_ntoa(((struct sockaddr_in*)(&netconf.ifc_req[0].ifr_addr))->sin_addr), 20 ); @@ -120,6 +161,8 @@ } } } +#endif /* not FreeBSD or NetBSD */ + if( j == 1 ) { dissipate_our_fqdn = strdup( if_addr[0] ); } else {