__aeabi_ldivmod: fix sign logic
[minix.git] / lib / libc / net / minix / getifaddrs.c
bloba1ccae88af8f4ca11a924cb969d69e031f7bf0eb
1 #include <namespace.h>
3 #include <sys/ioctl.h>
4 #include <sys/socket.h>
5 #include <sys/types.h>
7 #include <net/if.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>
15 #include <fcntl.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <stdlib.h>
19 #include <ifaddrs.h>
21 #if defined(__weak_alias)
22 __weak_alias(getifaddrs,_getifaddrs)
23 __weak_alias(freeifaddrs,_freeifaddrs)
24 #endif
26 int
27 getifaddrs(struct ifaddrs **ifap)
29 static int fd = -1;
30 nwio_ipconf_t ipconf;
31 int flags;
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));
38 ifa.ifa_next = NULL;
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;
46 *ifap = NULL;
48 if(fd < 0) {
49 char *ipd;
51 if(!(ipd = getenv("IP_DEVICE")))
52 ipd = __UNCONST("/dev/ip");
53 if((fd = open(ipd, O_RDWR)) < 0)
54 return -1;
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. */
70 *ifap = &ifa;
72 return 0;
75 void
76 freeifaddrs(struct ifaddrs *ifp)
78 /* getifaddrs points to static data, so no need to free. */