implement mo file string lookup for translations
[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         "\131ospf",
22         "\136ipip",
23         "\147pim",
24         "\377raw",
25         "\0\0"
26 };
27
28 void endprotoent(void)
29 {
30         idx = 0;
31 }
32
33 void setprotoent(int stayopen)
34 {
35         idx = 0;
36 }
37
38 struct protoent *getprotoent(void)
39 {
40         static struct protoent p;
41         static const char *aliases;
42         if (!protos[idx][1]) return NULL;
43         p.p_proto = protos[idx][0];
44         p.p_name = (char *)protos[idx++]+1;
45         p.p_aliases = (char **)&aliases;
46         return &p;
47 }
48
49 struct protoent *getprotobyname(const char *name)
50 {
51         struct protoent *p;
52         endprotoent();
53         do p = getprotoent();
54         while (p && strcmp(name, p->p_name));
55         return p;
56 }
57
58 struct protoent *getprotobynumber(int num)
59 {
60         struct protoent *p;
61         endprotoent();
62         do p = getprotoent();
63         while (p && p->p_proto != num);
64         return p;
65 }