split inet_addr and inet_ntoa back into their own files
[musl] / src / network / inet_legacy.c
1 #include <sys/socket.h>
2 #include <netinet/in.h>
3 #include <arpa/inet.h>
4 #include "__dns.h"
5
6 in_addr_t inet_network(const char *p)
7 {
8         return ntohl(inet_addr(p));
9 }
10
11 int inet_aton(const char *cp, struct in_addr *inp)
12 {
13         return inet_pton(AF_INET, cp, (void *)inp) > 0;
14 }
15
16 struct in_addr inet_makeaddr(int net, int host)
17 {
18         uint32_t n = net, h = host;
19         if (n < 256) h |= n<<24;
20         else if (n < 65536) h |= n<<16;
21         else h |= n<<8;
22         return (struct in_addr){ h };
23 }
24
25 in_addr_t inet_lnaof(struct in_addr in)
26 {
27         uint32_t h = in.s_addr;
28         if (h>>24 < 128) return h & 0xffffff;
29         if (h>>24 < 192) return h & 0xffff;
30         return h & 0xff;
31 }
32
33 in_addr_t inet_netof(struct in_addr in)
34 {
35         uint32_t h = in.s_addr;
36         if (h>>24 < 128) return h >> 24;
37         if (h>>24 < 192) return h >> 16;
38         return h >> 8;
39 }