8 #include <sys/socket.h>
10 #include <netinet/in.h>
12 #include <net/gen/in.h>
13 #include <net/gen/ip_io.h>
14 #include <net/gen/tcp.h>
15 #include <net/gen/tcp_io.h>
16 #include <net/gen/udp.h>
17 #include <net/gen/udp_io.h>
20 getifaddrs(struct ifaddrs
**ifap
)
25 static struct ifaddrs ifa
;
26 static struct sockaddr_in addr
, netmask
;
28 memset(&ifa
, 0, sizeof(ifa
));
29 memset(&addr
, 0, sizeof(addr
));
30 memset(&netmask
, 0, sizeof(netmask
));
33 addr
.sin_family
= netmask
.sin_family
= AF_INET
;
34 ifa
.ifa_addr
= (struct sockaddr
*) &addr
;
35 ifa
.ifa_netmask
= (struct sockaddr
*) &netmask
;
36 addr
.sin_addr
.s_addr
= 0;
37 netmask
.sin_addr
.s_addr
= 0;
41 if(!(ipd
=getenv("IP_DEVICE")))
43 if((fd
= open(ipd
, O_RDWR
)) < 0)
47 /* Code taken from commands/simple/ifconfig.c. */
49 if((flags
= fcntl(fd
, F_GETFL
)) < 0 ||
50 fcntl(fd
, F_SETFL
, flags
| O_NONBLOCK
) < 0 ||
51 ioctl(fd
, NWIOGIPCONF
, &ipconf
))
52 return 0; /* Report interface as down. */
54 addr
.sin_addr
.s_addr
= ipconf
.nwic_ipaddr
;
55 netmask
.sin_addr
.s_addr
= ipconf
.nwic_netmask
;
56 if(addr
.sin_addr
.s_addr
) ifa
.ifa_flags
= IFF_UP
;
58 /* Just report on this interface. */
66 freeifaddrs(struct ifaddrs
*ifp
)
68 /* getifaddrs points to static data, so no need to free. */