4 #include <sys/socket.h>
8 #include <net/gen/in.h>
9 #include <net/gen/ip_io.h>
10 #include <net/gen/tcp.h>
11 #include <net/gen/udp.h>
13 #include <netinet/in.h>
21 #if defined(__weak_alias)
22 __weak_alias(getifaddrs
,_getifaddrs
)
23 __weak_alias(freeifaddrs
,_freeifaddrs
)
27 getifaddrs(struct ifaddrs
**ifap
)
32 static struct ifaddrs ifa
;
33 static struct sockaddr_in addr
, netmask
;
35 memset(&ifa
, 0, sizeof(ifa
));
36 memset(&addr
, 0, sizeof(addr
));
37 memset(&netmask
, 0, sizeof(netmask
));
39 ifa
.ifa_name
= __UNCONST("ip");
40 addr
.sin_family
= netmask
.sin_family
= AF_INET
;
41 ifa
.ifa_addr
= (struct sockaddr
*) &addr
;
42 ifa
.ifa_netmask
= (struct sockaddr
*) &netmask
;
43 addr
.sin_addr
.s_addr
= 0;
44 netmask
.sin_addr
.s_addr
= 0;
51 if(!(ipd
= getenv("IP_DEVICE")))
52 ipd
= __UNCONST("/dev/ip");
53 if((fd
= open(ipd
, O_RDWR
)) < 0)
57 /* Code taken from commands/simple/ifconfig.c. */
59 if((flags
= fcntl(fd
, F_GETFL
)) < 0 ||
60 fcntl(fd
, F_SETFL
, flags
| O_NONBLOCK
) < 0 ||
61 ioctl(fd
, NWIOGIPCONF
, &ipconf
))
62 return 0; /* Report interface as down. */
64 addr
.sin_addr
.s_addr
= ipconf
.nwic_ipaddr
;
65 netmask
.sin_addr
.s_addr
= ipconf
.nwic_netmask
;
66 if(addr
.sin_addr
.s_addr
) ifa
.ifa_flags
= IFF_UP
;
68 /* Just report on this interface. */
76 freeifaddrs(struct ifaddrs
*ifp
)
78 /* getifaddrs points to static data, so no need to free. */