This repository has been archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPLayer.cpp
104 lines (81 loc) · 2.28 KB
/
IPLayer.cpp
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
// IPLayer.cpp: implementation of the CIPLayer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "PacketSender.h"
#include "IPLayer.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIPLayer::CIPLayer( char* pName )
: CBaseLayer( pName )
{
ResetHeader( );
}
CIPLayer::~CIPLayer()
{
}
void CIPLayer::ResetHeader()
{
// Version + length
m_sHeader.ip_verlen = 0x45;
// Type of service
m_sHeader.ip_tos = 0x00;
// Total length, 20 bytes = 0x14
m_sHeader.ip_len = 0x0014;
// Datagram Identification
m_sHeader.ip_id = 0x0000;
// Flags + offset
m_sHeader.ip_fragoff = 0x0000;
// Time to live
m_sHeader.ip_ttl = 0x80;
// Protocol
m_sHeader.ip_proto = IP_PROTO_SCTP;
// Checksum
m_sHeader.ip_cksum = 0x0000;
memset(m_sHeader.ip_src.addrs_i, 0, 4);
memset(m_sHeader.ip_dst.addrs_i, 0, 4);
memset(m_sHeader.ip_data, 0, IP_DATA_SIZE);
}
void CIPLayer::SetSrcIPAddress(u_char* src_ip)
{
memcpy( m_sHeader.ip_src.addrs_i, src_ip, 4);
}
void CIPLayer::SetDstIPAddress(u_char* dst_ip)
{
memcpy( m_sHeader.ip_dst.addrs_i, dst_ip, 4);
}
void CIPLayer::SetFragOff(u_short fragoff)
{
m_sHeader.ip_fragoff = fragoff;
}
BOOL CIPLayer::Send(u_char* ppayload, int nlength)
{
memcpy( m_sHeader.ip_data, ppayload, nlength ) ;
m_sHeader.ip_len = ntohs(nlength + IP_HEADER_SIZE);
BOOL bSuccess = FALSE ;
bSuccess = mp_UnderLayer->Send((u_char*)&m_sHeader, IP_HEADER_SIZE + nlength);
return bSuccess;
}
BOOL CIPLayer::Receive(u_char* ppayload)
{
PIPLayer_HEADER pFrame = (PIPLayer_HEADER) ppayload ;
BOOL bSuccess = FALSE ;
if(memcmp((char *) pFrame->ip_dst.addrs_i, (char *)m_sHeader.ip_src.addrs_i, 4) == 0 &&
memcmp((char *) pFrame->ip_src.addrs_i, (char *)m_sHeader.ip_src.addrs_i, 4) != 0 )
{
// begin: 알맞은 값을 채우시오
// * IP의 프로토콜 타입 필터
// 1. 프로토콜 타입이 SCTP인 패킷만 걸러낸다.
// 2. 걸러진 SCTP타입 패킷을 decapsulation하여, 상위 레이어로 data를 올린다.
if(pFrame->ip_proto == IP_PROTO_SCTP)
bSuccess = mp_aUpperLayer[0]->Receive((u_char*)pFrame->ip_data);
// ends
}
return bSuccess ;
}