1 #include <sys/socket.h>
2 #include <netinet/in.h>
6 in_addr_t inet_network(const char *p)
8 return ntohl(inet_addr(p));
11 int inet_aton(const char *cp, struct in_addr *inp)
13 struct sockaddr_in sin;
14 if (__ipparse(&sin, AF_INET, cp) < 0) return 0;
19 struct in_addr inet_makeaddr(int net, int host)
21 uint32_t n = net, h = host;
22 if (n < 256) h |= n<<24;
23 else if (n < 65536) h |= n<<16;
25 return (struct in_addr){ h };
28 in_addr_t inet_lnaof(struct in_addr in)
30 uint32_t h = in.s_addr;
31 if (h>>24 < 128) return h & 0xffffff;
32 if (h>>24 < 192) return h & 0xffff;
36 in_addr_t inet_netof(struct in_addr in)
38 uint32_t h = in.s_addr;
39 if (h>>24 < 128) return h >> 24;
40 if (h>>24 < 192) return h >> 16;