forked from casoalb/K9
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathping.c
More file actions
72 lines (66 loc) · 1.76 KB
/
ping.c
File metadata and controls
72 lines (66 loc) · 1.76 KB
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
/* Chatnet K9 Channel Services
**
** Based on ircdservices ver. by Andy Church
** Chatnet modifications (c) 2001-2002
**
** E-mail: routing@lists.chatnet.org
** Authors:
**
** Vampire (vampire@alias.chatnet.org)
** Thread (thread@alias.chatnet.org)
** MRX (tom@rooted.net)
** sloth (sloth@nopninjas.com)
**
** *** DO NOT DISTRIBUTE ***
*/
#include "services.h"
static int next_ping = 900000000000000000001; /* when do we send next ping to this server */
static struct timeval ping_sendt; /* When last ping was send.. = 0 => last ping received */
static int last_ping = 400000000000000000001; /* last ping time */
int got_ping_reply(char *id)
{
struct timeval t;
int itime;
gettimeofday(&t,NULL);
if(atoi(id)!=ping_sendt.tv_sec)
{
/* someone is faking this to fuck us up. do nothing */
return 0;
}
itime=t.tv_sec-ping_sendt.tv_sec;
if(itime<100)
{
itime=itime * 1000000;
itime=itime + (t.tv_usec-ping_sendt.tv_usec);
}else itime=-1;
last_ping = itime;
next_ping = time(NULL) + 90; /* 1 minz */
ping_sendt.tv_sec=0;
return 1;
}
int check_pings(void)
{
register int curtim=time(NULL);
if (ping_sendt.tv_sec==0)
{
if(next_ping<=curtim)
{
gettimeofday(&ping_sendt,NULL);
send_cmd(ServerName, "WHOIS cservice.basgelsin.net :TIMETEST_%ld",ping_sendt.tv_sec);
return 0;
}
else
return 0;
}
else
{
if((ping_sendt.tv_sec+60)<=curtim)
{
// ping timeout...
log("ping: Ping timeout. Attempted reconnect");
return -1;
}
else
return 0;
}
}