c569232f5a0ad9429948abc16fd5910c7dffcc86
[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[][6] = {
8         "\000ip",
9         "\001icmp",
10         "\002igmp",
11         "\003ggp",
12         "\006tcp",
13         "\014pup",
14         "\021udp",
15         "\026idp",
16         "\377raw",
17         "\0\0"
18 };
19
20 void endprotoent(void)
21 {
22         idx = 0;
23 }
24
25 void setprotoent(int stayopen)
26 {
27         idx = 0;
28 }
29
30 struct protoent *getprotoent(void)
31 {
32         static struct protoent p;
33         static const char *aliases;
34         if (!protos[idx][1]) return NULL;
35         p.p_proto = protos[idx][0];
36         p.p_name = (char *)protos[idx++]+1;
37         p.p_aliases = (char **)&aliases;
38         return &p;
39 }
40
41 struct protoent *getprotobyname(const char *name)
42 {
43         struct protoent *p;
44         endprotoent();
45         do p = getprotoent();
46         while (p && strcmp(name, p->p_name));
47         return p;
48 }
49
50 struct protoent *getprotobynumber(int num)
51 {
52         struct protoent *p;
53         endprotoent();
54         do p = getprotoent();
55         while (p && p->p_proto != num);
56         return p;
57 }