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