Viet-Trung Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 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[] = { |
George Kulakowski | 17e3b04 | 2016-02-18 15:59:50 -0800 | [diff] [blame] | 8 | "\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 Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 44 | |
George Kulakowski | 17e3b04 | 2016-02-18 15:59:50 -0800 | [diff] [blame] | 45 | void endprotoent(void) { |
| 46 | idx = 0; |
Viet-Trung Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 47 | } |
| 48 | |
George Kulakowski | 17e3b04 | 2016-02-18 15:59:50 -0800 | [diff] [blame] | 49 | void setprotoent(int stayopen) { |
| 50 | idx = 0; |
Viet-Trung Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 51 | } |
| 52 | |
George Kulakowski | 17e3b04 | 2016-02-18 15:59:50 -0800 | [diff] [blame] | 53 | struct 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 Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 63 | } |
| 64 | |
George Kulakowski | 17e3b04 | 2016-02-18 15:59:50 -0800 | [diff] [blame] | 65 | struct 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 Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 72 | } |
| 73 | |
George Kulakowski | 17e3b04 | 2016-02-18 15:59:50 -0800 | [diff] [blame] | 74 | struct 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 Luu | 96b05c1 | 2016-01-11 11:26:36 -0800 | [diff] [blame] | 81 | } |