blob: e91df303c8dc0fa2059f7adee5bd5d9ce1a646af [file] [log] [blame]
Viet-Trung Luu96b05c12016-01-11 11:26:36 -08001#include <netdb.h>
2#include <string.h>
3
4/* do we really need all these?? */
5
6static int idx;
7static const unsigned char protos[] = {
George Kulakowski17e3b042016-02-18 15:59:50 -08008 "\000ip\0"
9 "\001icmp\0"
10 "\002igmp\0"
11 "\003ggp\0"
12 "\004ipencap\0"
13 "\005st\0"
14 "\006tcp\0"
15 "\008egp\0"
16 "\014pup\0"
17 "\021udp\0"
18 "\024hmp\0"
19 "\026xns-idp\0"
20 "\033rdp\0"
21 "\035iso-tp4\0"
22 "\044xtp\0"
23 "\045ddp\0"
24 "\046idpr-cmtp\0"
25 "\051ipv6\0"
26 "\053ipv6-route\0"
27 "\054ipv6-frag\0"
28 "\055idrp\0"
29 "\056rsvp\0"
30 "\057gre\0"
31 "\062esp\0"
32 "\063ah\0"
33 "\071skip\0"
34 "\072ipv6-icmp\0"
35 "\073ipv6-nonxt\0"
36 "\074ipv6-opts\0"
37 "\111rspf\0"
38 "\121vmtp\0"
39 "\131ospf\0"
40 "\136ipip\0"
41 "\142encap\0"
42 "\147pim\0"
43 "\377raw"};
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080044
George Kulakowski17e3b042016-02-18 15:59:50 -080045void endprotoent(void) {
46 idx = 0;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080047}
48
George Kulakowski17e3b042016-02-18 15:59:50 -080049void setprotoent(int stayopen) {
50 idx = 0;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080051}
52
George Kulakowski17e3b042016-02-18 15:59:50 -080053struct protoent* getprotoent(void) {
54 static struct protoent p;
55 static const char* aliases;
56 if (idx >= sizeof protos)
57 return NULL;
58 p.p_proto = protos[idx];
59 p.p_name = (char*)&protos[idx + 1];
60 p.p_aliases = (char**)&aliases;
61 idx += strlen(p.p_name) + 2;
62 return &p;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080063}
64
George Kulakowski17e3b042016-02-18 15:59:50 -080065struct protoent* getprotobyname(const char* name) {
66 struct protoent* p;
67 endprotoent();
68 do
69 p = getprotoent();
70 while (p && strcmp(name, p->p_name));
71 return p;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080072}
73
George Kulakowski17e3b042016-02-18 15:59:50 -080074struct protoent* getprotobynumber(int num) {
75 struct protoent* p;
76 endprotoent();
77 do
78 p = getprotoent();
79 while (p && p->p_proto != num);
80 return p;
Viet-Trung Luu96b05c12016-01-11 11:26:36 -080081}