7 #include <sys/socket.h>
9 #include <netinet/in.h>
11 #include <net/gen/in.h>
12 #include <net/gen/ip_io.h>
13 #include <net/gen/tcp.h>
14 #include <net/gen/udp.h>
17 getifaddrs(struct ifaddrs
**ifap
)
22 static struct ifaddrs ifa
;
23 static struct sockaddr_in addr
, netmask
;
25 memset(&ifa
, 0, sizeof(ifa
));
26 memset(&addr
, 0, sizeof(addr
));
27 memset(&netmask
, 0, sizeof(netmask
));
30 addr
.sin_family
= netmask
.sin_family
= AF_INET
;
31 ifa
.ifa_addr
= (struct sockaddr
*) &addr
;
32 ifa
.ifa_netmask
= (struct sockaddr
*) &netmask
;
33 addr
.sin_addr
.s_addr
= 0;
34 netmask
.sin_addr
.s_addr
= 0;
38 if(!(ipd
=getenv("IP_DEVICE")))
40 if((fd
= open(ipd
, O_RDWR
)) < 0)
44 /* Code taken from commands/simple/ifconfig.c. */
46 if((flags
= fcntl(fd
, F_GETFL
)) < 0 ||
47 fcntl(fd
, F_SETFL
, flags
| O_NONBLOCK
) < 0 ||
48 ioctl(fd
, NWIOGIPCONF
, &ipconf
))
49 return 0; /* Report interface as down. */
51 addr
.sin_addr
.s_addr
= ipconf
.nwic_ipaddr
;
52 netmask
.sin_addr
.s_addr
= ipconf
.nwic_netmask
;
53 if(addr
.sin_addr
.s_addr
) ifa
.ifa_flags
= IFF_UP
;
55 /* Just report on this interface. */
63 freeifaddrs(struct ifaddrs
*ifp
)
65 /* getifaddrs points to static data, so no need to free. */