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/udp.h>
18 getifaddrs(struct ifaddrs
**ifap
)
23 static struct ifaddrs ifa
;
24 static struct sockaddr_in addr
, netmask
;
26 memset(&ifa
, 0, sizeof(ifa
));
27 memset(&addr
, 0, sizeof(addr
));
28 memset(&netmask
, 0, sizeof(netmask
));
30 ifa
.ifa_name
= __UNCONST("ip");
31 addr
.sin_family
= netmask
.sin_family
= AF_INET
;
32 ifa
.ifa_addr
= (struct sockaddr
*) &addr
;
33 ifa
.ifa_netmask
= (struct sockaddr
*) &netmask
;
34 addr
.sin_addr
.s_addr
= 0;
35 netmask
.sin_addr
.s_addr
= 0;
42 if(!(ipd
= getenv("IP_DEVICE")))
43 ipd
= __UNCONST("/dev/ip");
44 if((fd
= open(ipd
, O_RDWR
)) < 0)
48 /* Code taken from commands/simple/ifconfig.c. */
50 if((flags
= fcntl(fd
, F_GETFL
)) < 0 ||
51 fcntl(fd
, F_SETFL
, flags
| O_NONBLOCK
) < 0 ||
52 ioctl(fd
, NWIOGIPCONF
, &ipconf
))
53 return 0; /* Report interface as down. */
55 addr
.sin_addr
.s_addr
= ipconf
.nwic_ipaddr
;
56 netmask
.sin_addr
.s_addr
= ipconf
.nwic_netmask
;
57 if(addr
.sin_addr
.s_addr
) ifa
.ifa_flags
= IFF_UP
;
59 /* Just report on this interface. */
67 freeifaddrs(struct ifaddrs
*ifp
)
69 /* getifaddrs points to static data, so no need to free. */