fix the domain name length limit checks
[musl] / src / network / proto.c
1 #include <netdb.h>
2 #include <string.h>
3
4 /* do we really need all these?? */
5
6 static int idx;
7 static const unsigned char protos[][8] = {
8         "\000ip",
9         "\001icmp",
10         "\002igmp",
11         "\003ggp",
12         "\006tcp",
13         "\014pup",
14         "\021udp",
15         "\026idp",
16         "\051ipv6",
17         "\057gre",
18         "\062esp",
19         "\063ah",
20         "\072icmpv6",
21         "\136ipip",
22         "\377raw",
23         "\0\0"
24 };
25
26 void endprotoent(void)
27 {
28         idx = 0;
29 }
30
31 void setprotoent(int stayopen)
32 {
33         idx = 0;
34 }
35
36 struct protoent *getprotoent(void)
37 {
38         static struct protoent p;
39         static const char *aliases;
40         if (!protos[idx][1]) return NULL;
41         p.p_proto = protos[idx][0];
42         p.p_name = (char *)protos[idx++]+1;
43         p.p_aliases = (char **)&aliases;
44         return &p;
45 }
46
47 struct protoent *getprotobyname(const char *name)
48 {
49         struct protoent *p;
50         endprotoent();
51         do p = getprotoent();
52         while (p && strcmp(name, p->p_name));
53         return p;
54 }
55
56 struct protoent *getprotobynumber(int num)
57 {
58         struct protoent *p;
59         endprotoent();
60         do p = getprotoent();
61         while (p && p->p_proto != num);
62         return p;
63 }