13 static int flagwasthere
;
21 fdlock
= open_write("queue/lock/tcpto");
22 if (fdlock
== -1) return 0;
23 fd
= open_read("queue/lock/tcpto");
24 if (fd
== -1) { close(fdlock
); return 0; }
25 if (lock_ex(fdlock
) == -1) { close(fdlock
); close(fd
); return 0; }
26 r
= read(fd
,tcpto_buf
,sizeof(tcpto_buf
));
28 if (r
< 0) { close(fdlock
); return 0; }
30 if (!r
) close(fdlock
);
34 int tcpto(ip
) struct ip_address
*ip
;
50 if (byte_equal(ip
->d
,4,record
))
55 when
= (unsigned long) (unsigned char) record
[11];
56 when
= (when
<< 8) + (unsigned long) (unsigned char) record
[10];
57 when
= (when
<< 8) + (unsigned long) (unsigned char) record
[9];
58 when
= (when
<< 8) + (unsigned long) (unsigned char) record
[8];
60 if (now() - when
< ((60 + (getpid() & 31)) << 6))
70 void tcpto_err(ip
,flagerr
) struct ip_address
*ip
; int flagerr
;
76 datetime_sec firstwhen
;
78 datetime_sec lastwhen
;
82 return; /* could have been added, but not worth the effort to check */
90 if (byte_equal(ip
->d
,4,record
))
96 lastwhen
= (unsigned long) (unsigned char) record
[11];
97 lastwhen
= (lastwhen
<< 8) + (unsigned long) (unsigned char) record
[10];
98 lastwhen
= (lastwhen
<< 8) + (unsigned long) (unsigned char) record
[9];
99 lastwhen
= (lastwhen
<< 8) + (unsigned long) (unsigned char) record
[8];
102 if (record
[4] && (when
< 120 + lastwhen
)) { close(fdlock
); return; }
104 if (++record
[4] > 10) record
[4] = 10;
105 record
[8] = when
; when
>>= 8;
106 record
[9] = when
; when
>>= 8;
107 record
[10] = when
; when
>>= 8;
110 if (seek_set(fdlock
,i
<< 4) == 0)
111 if (write(fdlock
,record
,16) < 16)
119 if (!flagerr
) { close(fdlock
); return; }
122 for (i
= 0;i
< n
;++i
)
124 if (!record
[4]) break;
132 for (i
= 0;i
< n
;++i
)
134 when
= (unsigned long) (unsigned char) record
[11];
135 when
= (when
<< 8) + (unsigned long) (unsigned char) record
[10];
136 when
= (when
<< 8) + (unsigned long) (unsigned char) record
[9];
137 when
= (when
<< 8) + (unsigned long) (unsigned char) record
[8];
138 when
+= (record
[4] << 10);
139 if ((firstpos
< 0) || (when
< firstwhen
))
151 record
= tcpto_buf
+ (i
<< 4);
152 byte_copy(record
,4,ip
->d
);
154 record
[8] = when
; when
>>= 8;
155 record
[9] = when
; when
>>= 8;
156 record
[10] = when
; when
>>= 8;
159 if (seek_set(fdlock
,i
<< 4) == 0)
160 if (write(fdlock
,record
,16) < 16)