1 / 6

Parts of example codes

Parts of example codes. Some useful structures. ConnectionList<State> “ constate.h ” TCPState “ tcpstate.h ” ConnectionToStateMapping<State> “ constate.h ” IPHeader “ ip.h ” TCPHeader “ tcp.h ” Connection “ sockint.h ”.

ulfah
Download Presentation

Parts of example codes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Parts of example codes

  2. Some useful structures • ConnectionList<State> “constate.h” • TCPState “tcpstate.h” • ConnectionToStateMapping<State> “constate.h” • IPHeader “ip.h” • TCPHeader “tcp.h” • Connection “sockint.h”

  3. void craftPacketHeader(Packet *psend,ConnectionToStateMapping<TCPState> conState, TCPHeader th, int type, unsigned short no_of_bytes ) • { • //Packet psend; • Connection c = conState.connection; • IPHeader ih; • TCPHeader tcph; • unsigned short totalLength = no_of_bytes ; • unsigned int acknum,seqnum; • unsigned char flag=0; • unsigned short winsize,up; • TCPOptions opt; • unsigned int time = Time(); • int time_offset = 4; • unsigned char hlen=5; • th.GetSeqNum(acknum);// assign value to acknum • th.GetAckNum(seqnum); • th.GetWinSize(winsize); • th.GetOptions(opt); • th.GetUrgentPtr(up); • th.GetHeaderLen(hlen); • cout<<acknum<<endl; • seqnum = conState.state.GetLastSent();

  4. if ( type == SYN_HEADER ) • { • totalLength = SYN_HEADER_LENGTH; • seqnum = conState.state.GetLastSent(); • SET_SYN(flag); • time_offset = 8; • } • else if ( type == ACK_HEADER || type == PSH_ACK_HEADER) • { • totalLength += ACK_HEADER_LENGTH; • SET_ACK(flag); • acknum = conState.state.GetLastRecvd()+ 1; • seqnum += 1; • if(type == PSH_ACK_HEADER ) • SET_PSH(flag); • } • else if ( type == FIN_ACK_HEADER ) • { • totalLength = FIN_HEADER_LENGTH; • SET_ACK(flag); • SET_FIN(flag); • acknum = conState.state.GetLastRecvd() + 1; • seqnum += 1; • } • else if ( type == SYN_ACK_HEADER ) • { • totalLength = SYN_HEADER_LENGTH; • seqnum = conState.state.GetLastSent(); • acknum = conState.state.GetLastRecvd() + 1; • SET_ACK(flag); • SET_SYN(flag); • time_offset = 8; • }

  5. ih.SetProtocol(IP_PROTO_TCP); • ih.SetSourceIP(c.src); • ih.SetDestIP(c.dest); • ih.SetTotalLength( totalLength ); • // push it onto the packet • (*psend).PushFrontHeader(ih); • tcph.SetDestPort(c.destport,(*psend)); • tcph.SetSourcePort(c.srcport,(*psend)); • tcph.SetAckNum(acknum,(*psend)); • tcph.SetSeqNum(seqnum,(*psend)); • tcph.SetFlags(flag,(*psend)); • tcph.SetWinSize(winsize-12,(*psend)); • memcpy((void *)(opt.data+time_offset+4),(void *)(opt.data+time_offset),4); • *(int *)(opt.data+time_offset) = htonl(time); • tcph.SetOptions(opt); • tcph.SetUrgentPtr(up,(*psend)); • tcph.SetHeaderLen(hlen,(*psend)); • tcph.RecomputeChecksum((*psend)); • // Now we want to have the tcp header BEHIND the IP header • (*psend).PushBackHeader(tcph); • tcph.Print(cout); • //return psend; • }

  6. Notice • Pls make your codes well commented.

More Related