-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhosts.c
104 lines (91 loc) · 1.45 KB
/
hosts.c
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "dumb.h"
struct host *hosts;
struct host *
h_addr2host(addr, create)
u_long addr;
{
int j;
struct host *h;
for(h = hosts; h; h = h->h_next){
for(j = 0; j < H_NADDRS; j++)
if(h->h_addrs[j] && addr == h->h_addrs[j])
return(h);
}
if(create){
h = NEW(struct host);
bzero(h, sizeof(*h));
h->h_addrs[0] = addr;
h->h_next = hosts;
hosts = h;
return(h);
} else
return(0);
}
struct host *
h_name2host(name, create)
char *name;
{
int j;
struct host *h;
for(h = hosts; h; h = h->h_next){
for(j = 0; j < H_NNAMES; j++)
if(h->h_names[j] && SEQ(name, h->h_names[j]))
return(h);
}
if(create){
h = NEW(struct host);
bzero(h, sizeof(*h));
h->h_names[0] = NSTR(name);
h->h_next = hosts;
hosts = h;
return(h);
} else
return(0);
}
h_addaddr(h, addr)
struct host *h;
u_long addr;
{
int i;
struct hosts *h1;
for(i = 0; i < H_NADDRS; i++){
if(h->h_addrs[i] == addr)
break;
if(h->h_addrs[i] == 0){
h->h_addrs[i] = addr;
break;
}
}
}
h_addname(h, name)
struct host *h;
char *name;
{
int i;
for(i = 0; i < H_NNAMES; i++){
if(h->h_names[i] == 0){
h->h_names[i] = NSTR(name);
break;
}
if(SEQ(name, h->h_names[i]))
break;
}
}
h_clean()
{
struct host *nhosts, *h, *h1;
nhosts = 0;
h = hosts;
while(h){
h1 = h->h_next;
h->h_flags &= ~(HF_STARTED|HF_HITFAILED);
if(h == me || h->h_flags){
h->h_next = nhosts;
nhosts = h;
} else {
free(h);
}
h = h1;
}
hosts = nhosts;
}