
mjl at emsi
Feb 20, 2003, 9:04 AM
Post #1 of 1
(865 views)
Permalink
|
Here is a patch to get ife-bpf.c compile on NetBSD (no _SIZEOF_ADDR_IFREQ macro there). It also contains a couple of comments I added while trying to wrap my brain around the code and a cleanup (use macro instead of hardcoded value) but those are not necessary, use at your discretion. Also, the function if_list_ips() seems to assume that AF_LINK precedes all AF_INET for a given interface -- is this guaranteed to be the case? (It just happens to be that way here, but who knows...?) mjl --- ife-bpf.c.orig 2002-01-20 21:26:36.000000000 +0100 +++ ife-bpf.c 2003-02-20 16:47:03.000000000 +0100 @@ -91,9 +91,17 @@ write(_if_bpf, buffer, 60); return i; } + +#ifndef _SIZEOF_ADDR_IFREQ +#define _SIZEOF_ADDR_IFREQ(ifr) ((ifr).ifr_addr.sa_len + IFNAMSIZ) +#endif + +/* Build a list of interfaces/IP-addresses/MAC adresses this + machine currently has configured. + ifs points to a buffer large enough to hold size entries */ int if_list_ips(struct interface *ifs, - int size) { + int size) { int count=0; struct ifconf d; struct ifreq *ifr, *end, *cur, *temp; @@ -116,6 +124,8 @@ while((ifr<end) && (count<size)) { cur= ifr; ifr = (struct ifreq *)(((char *)ifr)+_SIZEOF_ADDR_IFREQ(*ifr)); + + /* Handle LL adresses (MAC adress) */ if(cur->ifr_addr.sa_family == AF_LINK) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)&cur->ifr_addr; if(sdl->sdl_alen != ETH_ALEN) continue; @@ -125,8 +135,12 @@ memcpy(ifs[count].mac, sdl->sdl_data+sdl->sdl_nlen, ETH_ALEN); continue; } + + /* Not AF_INET or AF_LINK, then ignore it */ if(cur->ifr_addr.sa_family != AF_INET) continue; + + /* Handle AF_INET */ memcpy(&ipaddr, &(((struct sockaddr_in *)&cur->ifr_addr)->sin_addr), sizeof(struct in_addr)); memcpy(temp, cur, sizeof(struct ifreq)); @@ -151,14 +165,16 @@ return count; } +#define IFLISTSIZE 1024 + int if_down(struct interface *areq) { int i, ic; struct sockaddr_in *a; struct ifaliasreq toup; - struct interface ifs[1024]; + struct interface ifs[IFLISTSIZE]; - ic = if_list_ips(ifs, 1024); + ic = if_list_ips(ifs, IFLISTSIZE); for(i=0; i<ic; i++) { if(!memcmp(&ifs[i].ipaddr, &(areq->ipaddr), sizeof(struct in_addr))) { areq = NULL; @@ -194,9 +210,9 @@ int i, ic; struct sockaddr_in *a; struct ifaliasreq toup; - struct interface ifs[1024]; + struct interface ifs[IFLISTSIZE]; - ic = if_list_ips(ifs, 1024); + ic = if_list_ips(ifs, IFLISTSIZE); for(i=0; i<ic; i++) { if(!memcmp(&ifs[i].ipaddr, &(areq->ipaddr), sizeof(struct in_addr))) { _if_error = _if_error_exists;
|