-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathm_ping.cpp
More file actions
70 lines (61 loc) · 1.85 KB
/
Copy pathm_ping.cpp
File metadata and controls
70 lines (61 loc) · 1.85 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
/*
WASTE - m_ping.cpp (Ping message builder/parser class)
Copyright (C) 2003 Nullsoft, Inc.
WASTE is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
WASTE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with WASTE; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "platform.h"
#include "m_ping.h"
C_MessagePing::~C_MessagePing()
{
}
C_MessagePing::C_MessagePing()
{
m_nick[0]=0;
m_ip=0;
m_port=0;
}
C_MessagePing::C_MessagePing(C_SHBuf *in)
{
m_nick[0]=0;
m_ip=0;
m_port=0;
unsigned char *data=(unsigned char*)in->Get();
int l=in->GetLength();
if (l < 2+4) return;
m_port = data[0]|(data[1]<<8); data+=2;
m_ip = data[0]|(data[1]<<8)|(data[2]<<16)|(data[3]<<24); data+=4;
l-=4+2;
if (l>0)
{
if (l > 32)
{
debug_printf("Ping: got ping with nick > 32\n");
}
else
{
memcpy(m_nick,data,l);
data+=l;
m_nick[l]=0;
}
}
}
C_SHBuf *C_MessagePing::Make(void)
{
C_SHBuf *buf=new C_SHBuf(2+4+strlen(m_nick));
unsigned char *data=(unsigned char *)buf->Get();
data[0]=m_port&0xff; data[1]=(m_port>>8)&0xff; data+=2;
data[0]=m_ip&0xff; data[1]=(m_ip>>8)&0xff; data[2]=(m_ip>>16)&0xff; data[3]=(m_ip>>24)&0xff; data+=4;
memcpy(data,m_nick,strlen(m_nick));
data+=strlen(m_nick);
return buf;
}