summaryrefslogtreecommitdiff
path: root/src/network/proto.c
blob: 031003ad0cf490b4e2e01714e27d179693e51553 (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
#include <netdb.h>
#include <string.h>

/* do we really need all these?? */

static int idx;
static const unsigned char protos[][6] = {
	"\000ip",
	"\001icmp",
	"\002igmp",
	"\003ggp",
	"\006tcp",
	"\014pup",
	"\021udp",
	"\026idp",
	"\377raw"
	"\0\0"
};

void endprotoent(void)
{
	idx = 0;
}

void setprotoent(int stayopen)
{
	idx = 0;
}

struct protoent *getprotoent(void)
{
	static struct protoent p;
	static const char *aliases;
	if (!protos[idx][1]) return NULL;
	p.p_proto = protos[idx][0];
	p.p_name = (char *)protos[idx++]+1;
	p.p_aliases = (char **)&aliases;
	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;
}