1 #include <sys/socket.h>
2 #include <netinet/in.h>
7 in_addr_t inet_addr(const char *p)
9 struct sockaddr_in sin;
10 if (__ipparse(&sin, AF_INET, p)) return -1;
11 return sin.sin_addr.s_addr;
14 in_addr_t inet_network(const char *p)
16 return ntohl(inet_addr(p));
19 int inet_aton(const char *cp, struct in_addr *inp)
21 return inet_pton(AF_INET, cp, (void *)inp) > 0;
24 char *inet_ntoa(struct in_addr in)
27 unsigned char *a = (void *)∈
28 snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
32 struct in_addr inet_makeaddr(int net, int host)
34 uint32_t n = net, h = host;
35 if (n < 256) h |= n<<24;
36 else if (n < 65536) h |= n<<16;
38 return (struct in_addr){ h };
41 in_addr_t inet_lnaof(struct in_addr in)
43 uint32_t h = in.s_addr;
44 if (h>>24 < 128) return h & 0xffffff;
45 if (h>>24 < 192) return h & 0xffff;
49 in_addr_t inet_netof(struct in_addr in)
51 uint32_t h = in.s_addr;
52 if (h>>24 < 128) return h >> 24;
53 if (h>>24 < 192) return h >> 16;