40 likes | 47 Views
This code example demonstrates the use of useful structures such as ConnectionList, TCPState, ConnectionToStateMapping, IPHeader, TCPHeader, and Connection. Includes functions for DFListen and SOCKConnect.
E N D
Parts of example codes Yan Gao Feb. 10, 2006
Some useful structures • ConnectionList<State> “constate.h” • TCPState “tcpstate.h” • ConnectionToStateMapping<State> “constate.h” • IPHeader “ip.h” • TCPHeader “tcp.h” • Connection “sockint.h”
Examples void DFListen(TCPHeader &tcph, Connection &c, Time ¤t_time) { unsigned char flags=0; tcph.GetFlags(flags); if(IS_SYN(flags)) { unsigned int seqnum; //Store remote side sequence number and connection info. With a new connection, tcph.GetSeqNum(seqnum); // send SYN/ACK with my sequence number Connection cnew = c; Time newto = current_time; newto.tv_sec += 5; TCPState newtcp(initSeqNum, SYN_RCVD, 8); newtcp.SetLastRecvd(seqnum); ConnectionToStateMapping<TCPState> csm(cnew, newto, newtcp, true); clist.push_front(csm); //Add new connection to list ConnectionList<TCPState>::iterator cs = clist.FindMatching(cnew); unsigned short window; tcph.GetWinSize(window); (*cs).state.SetSendRwnd(window); if(cs == clist.end()) { cerr << "Some problem finding the newly inserted tuple" << endl; } SendSynAck(cs); } }
void SOCKConnect(SockRequestResponse &req) { Time current_time; if (gettimeofday(¤t_time, 0) < 0) { cerr << "Can't obtain the current time.\n"; exit(-1); } ConnectionList<TCPState>::iterator cs = clist.FindMatching(req.connection); if(cs == clist.end()) { cerr << "Creating new connection." << endl; //Create a new connection with a timeout to receive Connection cnew = req.connection; // the SYN/ACK Time newto = current_time; newto.tv_sec += 5; TCPState newtcp(initSeqNum, SYN_SENT, 8); ConnectionToStateMapping<TCPState> csm(cnew, newto, newtcp, true); clist.push_front(csm); //Add new connection to list } cs = clist.FindMatching(req.connection); if(cs == clist.end()) { cerr << "Some problem finding the newly inserted tuple" << endl; } SendSyn(cs); SockRequestResponse repl; //Send back result code repl.type=STATUS; repl.connection=req.connection; repl.bytes=0; repl.error=EOK; MinetSend(sock,repl); }