blob: 43aa17a42ac38e77bc238db5c79873b4c39b5d88 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include <netdb.h>
#include <string.h>
/* do we really need all these?? */
static int idx;
static const unsigned char protos[] = {
"\000ip\0"
"\001icmp\0"
"\002igmp\0"
"\003ggp\0"
"\006tcp\0"
"\014pup\0"
"\021udp\0"
"\026idp\0"
"\051ipv6\0"
"\053ipv6-route\0"
"\054ipv6-frag\0"
"\057gre\0"
"\062esp\0"
"\063ah\0"
"\072ipv6-icmp\0"
"\073ipv6-nonxt\0"
"\074ipv6-opts\0"
"\131ospf\0"
"\136ipip\0"
"\147pim\0"
"\377raw"
};
void endprotoent(void)
{
idx = 0;
}
void setprotoent(int stayopen)
{
idx = 0;
}
struct protoent *getprotoent(void)
{
static struct protoent p;
static const char *aliases;
if (idx >= sizeof protos) return NULL;
p.p_proto = protos[idx];
p.p_name = (char *)&protos[idx+1];
p.p_aliases = (char **)&aliases;
idx += strlen(p.p_name) + 2;
return &p;
}
struct protoent *getprotobyname(const char *name)
{
struct protoent *p;
endprotoent();
do p = getprotoent();
while (p && strcmp(name, p->p_name));
return p;
}
struct protoent *getprotobynumber(int num)
{
struct protoent *p;
endprotoent();
do p = getprotoent();
while (p && p->p_proto != num);
return p;
}
|