include: reduce default stack size
[minix.git] / lib / libc / net / minix / getifaddrs.c
blob5a54d98159818fb80f858e60895e84156bf56035
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <fcntl.h>
5 #include <net/if.h>
6 #include <ifaddrs.h>
7 #include <sys/ioctl.h>
8 #include <sys/socket.h>
9 #include <sys/types.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>
17 int
18 getifaddrs(struct ifaddrs **ifap)
20 static int fd = -1;
21 nwio_ipconf_t ipconf;
22 int flags;
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));
29 ifa.ifa_next = NULL;
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;
37 *ifap = NULL;
39 if(fd < 0) {
40 char *ipd;
42 if(!(ipd = getenv("IP_DEVICE")))
43 ipd = __UNCONST("/dev/ip");
44 if((fd = open(ipd, O_RDWR)) < 0)
45 return -1;
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. */
61 *ifap = &ifa;
63 return 0;
66 void
67 freeifaddrs(struct ifaddrs *ifp)
69 /* getifaddrs points to static data, so no need to free. */