INET Framework for OMNeT++/OMNEST
inet::tcp::TCPSpoof Class Reference

Sends fabricated TCP packets. More...

#include <TCPSpoof.h>

Inheritance diagram for inet::tcp::TCPSpoof:

Protected Member Functions

virtual void sendToIP (TCPSegment *tcpseg, L3Address src, L3Address dest)
 
virtual unsigned long chooseInitialSeqNum ()
 
virtual void sendSpoofPacket ()
 
virtual void initialize () override
 
virtual void handleMessage (cMessage *msg) override
 

Static Protected Attributes

static simsignal_t sentPkSignal = registerSignal("sentPk")
 

Detailed Description

Sends fabricated TCP packets.

Member Function Documentation

unsigned long inet::tcp::TCPSpoof::chooseInitialSeqNum ( )
protectedvirtual

Referenced by sendSpoofPacket().

83 {
84  // choose an initial send sequence number in the same way as TCP does
85  return (unsigned long)SIMTIME_DBL(fmod(simTime() * 250000.0, 1.0 + (double)(unsigned)0xffffffffUL)) & 0xffffffffUL;
86 }
void inet::tcp::TCPSpoof::handleMessage ( cMessage *  msg)
overrideprotectedvirtual
35 {
36  if (!msg->isSelfMessage())
37  throw cRuntimeError("Does not process incoming messages");
38 
40  delete msg;
41 }
virtual void sendSpoofPacket()
Definition: TCPSpoof.cc:43
void inet::tcp::TCPSpoof::initialize ( )
overrideprotectedvirtual
29 {
30  simtime_t t = par("t").doubleValue();
31  scheduleAt(t, new cMessage("timer"));
32 }
void inet::tcp::TCPSpoof::sendSpoofPacket ( )
protectedvirtual

Referenced by handleMessage().

44 {
45  TCPSegment *tcpseg = new TCPSegment("spoof");
46 
47  L3Address srcAddr = L3AddressResolver().resolve(par("srcAddress"));
48  L3Address destAddr = L3AddressResolver().resolve(par("destAddress"));
49  int srcPort = par("srcPort");
50  int destPort = par("destPort");
51  bool isSYN = par("isSYN");
52  unsigned long seq = par("seqNo").longValue() == -1 ? chooseInitialSeqNum() : par("seqNo").longValue();
53 
54  // one can customize the following according to concrete needs
55  tcpseg->setSrcPort(srcPort);
56  tcpseg->setDestPort(destPort);
57  tcpseg->setByteLength(TCP_HEADER_OCTETS);
58  tcpseg->setSequenceNo(seq);
59  //tcpseg->setAckNo(...);
60  tcpseg->setSynBit(isSYN);
61  tcpseg->setWindow(16384);
62 
63  sendToIP(tcpseg, srcAddr, destAddr);
64 }
virtual void sendToIP(TCPSegment *tcpseg, L3Address src, L3Address dest)
Definition: TCPSpoof.cc:66
#define TCP_HEADER_OCTETS
Definition: TCPSegment_m.h:50
virtual unsigned long chooseInitialSeqNum()
Definition: TCPSpoof.cc:82
void inet::tcp::TCPSpoof::sendToIP ( TCPSegment tcpseg,
L3Address  src,
L3Address  dest 
)
protectedvirtual

Referenced by sendSpoofPacket().

67 {
68  EV_INFO << "Sending: ";
69  //printSegmentBrief(tcpseg);
70 
71  IL3AddressType *addressType = dest.getAddressType();
72  INetworkProtocolControlInfo *controlInfo = addressType->createNetworkProtocolControlInfo();
73  controlInfo->setTransportProtocol(IP_PROT_TCP);
74  controlInfo->setSourceAddress(src);
75  controlInfo->setDestinationAddress(dest);
76  tcpseg->setControlInfo(check_and_cast<cObject *>(controlInfo));
77 
78  emit(sentPkSignal, tcpseg);
79  send(tcpseg, "ipOut");
80 }
static simsignal_t sentPkSignal
Definition: TCPSpoof.h:41
Definition: IPProtocolId_m.h:80

Member Data Documentation

simsignal_t inet::tcp::TCPSpoof::sentPkSignal = registerSignal("sentPk")
staticprotected

Referenced by sendToIP().


The documentation for this class was generated from the following files: