#include #include #include #include #include #include #include #include #include /** * @jmeier_assignment3 * @author Joshua Meier * @version 1.0 * * @section LICENSE * * This program is free software;...

1 answer below ยป
i attached the assignment details


#include #include #include #include #include #include #include #include #include /** * @jmeier_assignment3 * @author Joshua Meier * @version 1.0 * * @section LICENSE * * This program 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. * * This program 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 at * http://www.gnu.org/copyleft/gpl.html * * @section DESCRIPTION * * This contains the main function. Add further description here.... */ /** * main function * * @param argc Number of arguments * @param argv The argument list * @return 0 EXIT_SUCCESS */ using namespace std; int main(int argc, char **argv) { /*Start Here*/ int listening = socket(AF_INET, SOCK_STREAM, 0); if(listening == -1) { cerr < "can't create a socket!"; return -1; } socketadd_in ; bind(listening, (struct sockaddr*)&server, sizeof(server)); return 0; } "can't="" create="" a="" socket!";="" return="" -1;="" }="" socketadd_in="" ;="" bind(listening,="" (struct="" sockaddr*)&server,="" sizeof(server));="" return="" 0;="">
Answered 6 days AfterMay 04, 2021

Answer To: #include #include #include #include #include #include #include #include #include /** *...

Pulkit answered on May 10 2021
140 Votes
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "Serialize.h"
/**
* @jmeier_assignment3
* @author Joshua Meier
* @version 1.0
*
* @section LICENSE
*
* This program 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.
*
* This program 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 at
* http://www.gnu.org/copyleft/gpl.html
*
* @section DESCRIPTION
*
* This contains the main function. Add further description here....
*/
/**
* main function
*
* @param argc Number of arguments
* @param argv The argument list
* @return 0 EXIT_SUCCESS
*/
#define MAXBUFLEN 100;
#define INF 65535;
struct routingEntry
{
uint16_t DRID;
uint16_t MTCCOST;
uint32_t DRIP;
uint16_t DRPORT;
uint16_t PDNG;

};
struct updatePacket
{
uint16_t NOUF;
uint32_t SRCRIP;
routingEntry RE [];
uint16_t SRCRPORT;

};
struct routingTable
{
bool doesExist;
bool active;
int uptime;
bool ne;
uint16_t DRID;
uint16_t RSN;
uint16_t PDNG;
uint16_t DTAPORT;
uint32_t DSTNIP;
uint32_t SRCRIP;
uint16_t NHID;
uint16_t MTCCOST;
uint16_t RTRPORT;

};
struct controlPacketPayload
{
char fileName[256];
uint32_t RTRIP[5];
uint16_t NDS;
uint16_t UPDTITL;
uint16_t RTRID[5];
uint32_t SFTTIP;
uint16_t RTRPORT[5];
uint16_t DTAPORT[5];
uint16_t MTC[5];
uint16_t CHNGDCOST;
uint16_t CGNGCRID;
uint16_t SQNCENMBR;
uint8_t TTL;
uint8_t TRNFID;


};
struct controlResponsePayload{
uint8_t TRNFID;
uint8_t TTL;
};
struct topologyTable{
uint16_t PDNG;
uint16_t nextHopRTRID;
uint16_t RTRID;
uint32_t DSTNIP;
uint16_t MTC;
bool NGBR;
int holdTime;
};
struct controlPacketHeader{
uint32_t DSTNIP;
uint8_t CTRLCODE;
uint8_t RSPNSTIME;
uint16_t PLLENGTH;
};
struct controlResponseHeader{
uint32_t CNTRLIP;
uint8_t CTRLCODE;
uint8_t RSPNSCODE;
uint16_t PLLENGTH;
};
class Router{
fd_set MSTDSRPTOR;
fd_set TMPRFDS;
int yes, SLCTRTRN;
int NGBRCount, stopwatch;
uint16_t WAIID;
uint16_t WAIPort;
uint32_t WAIIP;
uint16_t UPDTITL, CNTND;
uint16_t dv[10][10
];
uint16_t dvcopy[10][10];
unsigned int NERCBLY[10];
int numbytes, PRTCNT;
struct sockaddr_storage their_addr, ADDCNT;
struct sockaddr_in6 *NMPR6;
struct sockaddr_in *NMPR;
char buffer[100];
unsigned char *CTLBUFFR;
unsigned char *CTLRSPNSBUFFR;
unsigned char *CTLRSPNSPLBUFFR;
unsigned char *UPDTBUFFR;
char *LSTNPRTRP, *LSTNPRTDP;
int iSocket, SCDCTRCR, UPSCK, DTSFD, NOMFD, SCDNFDW, BTERD, FLS, SCTRF;
uint16_t RTRPORT, DTAPORT;
struct addrinfo hints, *servinfo, *p;
int rv, INRTRN;
char service [20];
char host [1024];
socklen_t addr_len, LGTCNT;
char s[INET6_ADDRSTRLEN];
char storeAddress[INET6_ADDRSTRLEN];


public: Router(){
printf("Default constructor intialised\n");
stopwatch=0;
}
public: int distanveVectorRoutingAlgorithm(uint16_t dv[][10], uint16_t CNTND, uint16_t myID, struct routingTable * lbtt){
for(int i=1; i<=ntohs(CNTND) ; i++){
int mySerialNumber;
int tempNHID=65535;
int comparator=INF;
int maxHop=65535;
for(int i=1;i<=ntohs(CNTND);i++){
if(ntohs(lbtt[i].DRID)==ntohs(myID))
{
mySerialNumber=i;
}
}


if(ntohs(lbtt[i].DRID)==ntohs(myID)) continue;

for(int j=1; j<=ntohs(CNTND); j++){
if (lbtt[j].ne==true){
if(lbtt[j].active==true){
if(ntohs(lbtt[j].DRID)!=ntohs(myID)){
if(comparator > (dv[mySerialNumber][(lbtt[j].RSN)]+dv[(lbtt[j].RSN)][(lbtt[i].RSN)])){
comparator=dv[mySerialNumber][(lbtt[j].RSN)]+dv[(lbtt[j].RSN)][(lbtt[i].RSN)];

if(lbtt[j].ne==true && NERCBLY[lbtt[j].RSN] <=dv[mySerialNumber][(lbtt[j].RSN)]){
tempNHID=(lbtt[j].DRID);
}
else if(lbtt[j].ne==false){
tempNHID=(lbtt[j].DRID);
}
}
}
}
}
}

dv[mySerialNumber][(lbtt[i].RSN)]=comparator;
if(lbtt[i].NHID==65535)
{
lbtt[i].NHID=tempNHID;
}
else
{
if(comparator!=lbtt[i].MTCCOST)
{
lbtt[i].NHID=tempNHID;
}
}

lbtt[i].MTCCOST=comparator;
if(dv[mySerialNumber][(lbtt[i].RSN)]==maxHop)
{
lbtt[i].NHID=65535;
}
}

return 0;
}
public: int transmitRoutingUpdates(struct routingTable lbtt[], uint16_t myPort, uint32_t myIP, uint16_t CNTND, int s)
{
ssize_t sentBytes,size=(2*sizeof(uint16_t))+(sizeof(struct in_addr))+(ntohs(CNTND)*sizeof(struct routingEntry));
struct updatePacket *updateMessage=(struct updatePacket*)malloc(sizeof(struct updatePacket));

updateMessage->NOUF=CNTND;
updateMessage->SRCRPORT=myPort;
updateMessage->SRCRIP=myIP;

for(int i=1; i<=ntohs(CNTND); i++)
{
updateMessage->RE[i-1].DRIP = lbtt[i].DSTNIP;
updateMessage->RE[i-1].DRPORT = lbtt[i].RTRPORT;
updateMessage->RE[i-1].PDNG=0;
updateMessage->RE[i-1].DRID = lbtt[i].DRID;
updateMessage->RE[i-1].MTCCOST = htons(lbtt[i].MTCCOST);
}

for(int i=1;i<=ntohs(CNTND);i++)
{
if(lbtt[i].ne==true)
{
if(lbtt[i].active==true)
{
struct sockaddr_in dest;
dest.sin_family=AF_INET;
dest.sin_port=lbtt[i].RTRPORT;
dest.sin_addr= *(struct in_addr *)&lbtt[i].DSTNIP;
sentBytes=sendto(s, (struct updatePacket*)updateMessage, size, 0,(struct sockaddr*)&dest, sizeof dest);
char *ip=inet_ntoa(dest.sin_addr);
printf("[PERIODIC UPDATE] - SENDING %zd bytes of routing update to [%d] on port [%u]\n", sentBytes, ntohs(lbtt[i].DRID), ntohs(lbtt[i].RTRPORT));
}
}
}
return 0;
}
public: int establishRoutingUpdates(uint16_t rp)
{

RTRPORT=ntohs(rp);
printf("LISTENING FOR ROUTING UPDATES ON ROUTER PORT[%u...]\n", RTRPORT);
LSTNPRTRP=(char*)malloc(sizeof(int)+1);
sprintf(LSTNPRTRP, "%d", RTRPORT);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_DGRAM;
hints.ai_flags = AI_PASSIVE;


if ((rv = getaddrinfo(NULL, LSTNPRTRP, &hints, &servinfo)) != 0)
{
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
return 1;
}
printf("building socket\n");
for(p = servinfo; p != NULL; p = p->ai_next)
{
if ((UPSCK = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) //SOCKET
{
printf("listener: Could not create socket\n");
continue;
}
if(setsockopt(UPSCK, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))==-1)
{
printf("setsockopt: check SO_REUSEADDR");
exit(2);
}
if(::bind(UPSCK, p->ai_addr, p->ai_addrlen) < -1) //BIND
{
close(UPSCK);
perror("server: bind\n");
continue;
}
break;
}
if (p == NULL)
{
fprintf(stderr, "listener: failed to bind socket\n");
return -1;
}
printf("all done\n");
freeaddrinfo(servinfo);
printf("freeing servinfo\n");
printf("listener: waiting to recvfrom on [%s] ...\n", LSTNPRTRP);

FD_SET(UPSCK, &MSTDSRPTOR);
printf("added UPSCK to MSTDSRPTOR\n");
if(UPSCK>NOMFD)
{
NOMFD=UPSCK;
printf("NOMFD updated to %d in UDP call control\n", NOMFD);
}
return 1;
}
public: int establisDataTransfer(uint16_t dp)
{
DTAPORT=ntohs(dp);

LSTNPRTDP=(char*)malloc(sizeof(int)+1);
sprintf(LSTNPRTDP, "%d", DTAPORT);
return 1;
FD_ZERO(&MSTDSRPTOR);
FD_ZERO(&TMPRFDS);

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;

INRTRN = getaddrinfo(NULL, LSTNPRTDP, &hints, &servinfo);
printf("returned info: %d\n",INRTRN);
if(INRTRN!=0)
{
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(INRTRN));
return 1;
}
for(p=servinfo; p!=NULL;p=p->ai_next)
{
DTSFD = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
printf("socket file descriptor :%d\n\n", DTSFD);
if(DTSFD<0)
{
perror("server: socket");
continue;
}
if(setsockopt(DTSFD, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))==-1)
{
perror("setsockopt");
exit(1);
}
if(::bind(DTSFD, p->ai_addr, p->ai_addrlen) < -1)
{
close(DTSFD);
perror("server:bind");
continue;
}
break;
}
if(p==NULL)
{
fprintf(stderr, "server: port binding failed\n");
}
freeaddrinfo(servinfo);
if(listen(SCDCTRCR,5) == -1) //LISTEN
{
perror("listen");
}
else
{
printf("LISTENING FOR DATA CONNECTIONS ON DATA PORT[%u...]\n", DTAPORT);
}
}
public: int estalblishRouter(uint16_t controlPort)
{
struct routingTable localBaseTopologyTable [6];
printf("You choose to use %hu as the control port\n", controlPort);

char *controlPortChar;
controlPortChar = (char*)malloc(sizeof(int)+1);
sprintf(controlPortChar, "%d", controlPort);
FD_ZERO(&MSTDSRPTOR);
FD_ZERO(&TMPRFDS);

memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;

INRTRN = getaddrinfo(NULL, controlPortChar, &hints, &servinfo);
printf("returned info: %d\n",INRTRN);
if(INRTRN!=0)
{
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(INRTRN));
return 1;
}
for(p=servinfo; p!=NULL;p=p->ai_next)
{
SCDCTRCR = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
printf("socket file descriptor :%d\n\n", SCDCTRCR);
if(SCDCTRCR<0)
{
perror("server: socket");
continue;
}
if(setsockopt(SCDCTRCR, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))==-1)
{
perror("setsockopt");
exit(1);
}
if(::bind(SCDCTRCR, p->ai_addr, p->ai_addrlen) < -1)
{
close(SCDCTRCR);
perror("server:bind");
continue;
}
break;
}
if(p==NULL)
{
fprintf(stderr, "server: port binding failed\n");
}
freeaddrinfo(servinfo);
if(listen(SCDCTRCR,5) == -1)
{
perror("listen");
}
else
{
printf("listening for incoming connections on CONTROL PORT (TCP)\n");
}
FD_SET(SCDCTRCR, &MSTDSRPTOR);
NOMFD=SCDCTRCR;
printf("NOMFD in FD_SET:CONTROLLER is: %d\n",NOMFD);
struct timeval selectCallTimer;

for(;;)
{
TMPRFDS = MSTDSRPTOR;
selectCallTimer.tv_sec=1.0;
selectCallTimer.tv_usec=0.0;

SLCTRTRN=select(NOMFD+1, &TMPRFDS, NULL, NULL, &selectCallTimer);


if(SLCTRTRN==-1)
{
perror("ERROR IN SELECT SYSTEM CALL");
}
else if(SLCTRTRN==0)
{

int mySerialNumber;
for(int i=1;i<=ntohs(CNTND);i++)
{
if(ntohs(localBaseTopologyTable[i].DRID)==ntohs(WAIID))
{
mySerialNumber=i;
}
}
stopwatch++;
if(stopwatch==ntohs(UPDTITL))
{
transmitRoutingUpdates(localBaseTopologyTable, WAIPort, WAIIP, CNTND, UPSCK);
stopwatch=0;
}

for(int i=1; i<=ntohs(CNTND); i++)
{
if (localBaseTopologyTable[i].ne==true)
{
if(localBaseTopologyTable[i].doesExist==true)
{
if(localBaseTopologyTable[i].active==true)
{
localBaseTopologyTable[i].uptime++;

printf("time since update: %d\n", localBaseTopologyTable[i].uptime);

if(localBaseTopologyTable[i].uptime==(ntohs(UPDTITL)*3))
{
localBaseTopologyTable[i].NHID=65535;

dv[mySerialNumber][(localBaseTopologyTable[i].RSN)]=INF;
for (int j = 1; j <=ntohs(CNTND); j++)
{
printf("setting dv to inf\n");
dv[(localBaseTopologyTable[i].RSN)][(localBaseTopologyTable[j].RSN)]=INF;
}
printf("No update received from Neighbor [%u] for %d secs, setting cost to INF\n",ntohs(localBaseTopologyTable[i].DRID), ntohs(UPDTITL)*3);

distanveVectorRoutingAlgorithm(dv, CNTND, WAIID, localBaseTopologyTable);

}
}
}
}
}

}
else
{


for(iSocket=0;iSocket<=NOMFD+1;iSocket++)
{
if(FD_ISSET(iSocket, &TMPRFDS))
{
if(iSocket==SCDCTRCR)
{
printf("found connection from CONTROLLER, SCDCTRCR value is [%d]\n",SCDCTRCR);
LGTCNT=sizeof(ADDCNT);
SCDNFDW=accept(SCDCTRCR, (sockaddr *)&ADDCNT, &LGTCNT);
if(SCDNFDW==-1)
{
perror("ERROR IN ACCEPT");
}
else
{
printf("adding SCDNFDW [%d] to MSTDSRPTOR\n", SCDNFDW);
FD_SET(SCDNFDW, &MSTDSRPTOR);
if(SCDNFDW>NOMFD)
{
NOMFD=SCDNFDW;
printf("NOMFD updated at accept to %d\n", NOMFD);
}
LGTCNT = sizeof (ADDCNT);
getpeername(SCDCTRCR, (struct sockaddr *) &ADDCNT, &LGTCNT);
if(ADDCNT.ss_family == AF_INET)
{
NMPR = (struct sockaddr_in *) &ADDCNT;
PRTCNT = ntohs(NMPR->sin_port);
inet_ntop(AF_INET, &NMPR->sin_addr, storeAddress, sizeof (storeAddress));
}
else
{
NMPR6 = (struct sockaddr_in6 *) &ADDCNT;
PRTCNT = ntohs(NMPR->sin_port);
inet_ntop(AF_INET, &NMPR->sin_addr, storeAddress, sizeof (storeAddress));
}
printf("Accepting new connection from %s: %d on socket %d\n\n", storeAddress, PRTCNT, SCDNFDW);
printf("Socket %d is bound to %s\n", SCDNFDW, storeAddress);


}

}
else if(iSocket==UPSCK)
{
ssize_t receivedBytes,size=(2*sizeof(uint16_t))+(sizeof(struct in_addr))+(ntohs(CNTND) *sizeof(struct routingEntry));
struct updatePacket *updateMessage=(updatePacket*)malloc(size);

int mySerialNumber;
for(int i=1;i<=ntohs(CNTND);i++)
{
if(ntohs(localBaseTopologyTable[i].DRID)==ntohs(WAIID))
{
mySerialNumber=i;
}
}

receivedBytes=recvfrom(iSocket, (struct updatePacket*)updateMessage, size, 0, NULL, NULL);
printf("*******************************************************************\n");
printf("[PERIODIC UPDATE] - RECEIVING %zd bytes of routing update on %u\n", receivedBytes, ntohs(WAIPort));
printf("[PERIODIC UPDATE] - number of update fields in the update: %u\n", ntohs(updateMessage->NOUF));
if(receivedBytes==size)
{
int advertiserID = 0;
int advertiserLocatedAtIndex=0;
int numberOfFields = ntohs(updateMessage->NOUF);
for(int i=1; i<=ntohs(updateMessage->NOUF); i++)
{
int advertiserCost = ntohs(updateMessage->RE[i-1].MTCCOST);
if(advertiserCost==0)
{
advertiserID=ntohs(updateMessage->RE[i-1].DRID);
printf("remote server from where update came is: %u\n",advertiserID);
}
for(int i=1;i<=ntohs(CNTND);i++)
{
if(ntohs(localBaseTopologyTable[i].DRID)==advertiserID)
{
advertiserLocatedAtIndex=i;
printf("advertiser is located at index: [%d]\n", advertiserLocatedAtIndex);
}
}
}
if (localBaseTopologyTable[advertiserLocatedAtIndex].active==true)
{

if (localBaseTopologyTable[advertiserLocatedAtIndex].doesExist==false || localBaseTopologyTable[advertiserLocatedAtIndex].uptime>(ntohs(UPDTITL)*3))
{
localBaseTopologyTable[advertiserLocatedAtIndex].doesExist=true;
dv[mySerialNumber][advertiserLocatedAtIndex]=NERCBLY[advertiserLocatedAtIndex];
printf("dv[%d][%d] set to cost %d\n", mySerialNumber, advertiserLocatedAtIndex, NERCBLY[advertiserLocatedAtIndex]);
}

for(int i=1; i<=numberOfFields; i++)
{
dv[advertiserLocatedAtIndex][(localBaseTopologyTable[i].RSN)]=ntohs(updateMessage->RE[i-1].MTCCOST);
}
localBaseTopologyTable[advertiserLocatedAtIndex].uptime=0;
printf("timer set to zero again\n");
distanveVectorRoutingAlgorithm(dv, CNTND, WAIID, localBaseTopologyTable);
}
}
memset((struct updatePacket*)updateMessage,'\0',size);

getpeername(iSocket, (struct sockaddr *) &ADDCNT, &LGTCNT);

if(ADDCNT.ss_family == AF_INET)
{
struct sockaddr_in *NMPR = (struct sockaddr_in *) &ADDCNT;
PRTCNT = ntohs(NMPR->sin_port);
inet_ntop(AF_INET, &NMPR->sin_addr, storeAddress, sizeof (storeAddress));
}
else
{
struct sockaddr_in6 *NMPR = (struct sockaddr_in6 *) &ADDCNT;
PRTCNT = ntohs(NMPR->sin6_port);
inet_ntop(AF_INET, &NMPR->sin6_addr, storeAddress, sizeof (storeAddress));
}
printf("Accepting %zd Bytes of Routing Update from %s: %d on socket %d\n\n",receivedBytes, storeAddress, PRTCNT, iSocket);

}
else if(iSocket==DTSFD)
{
LGTCNT = sizeof ADDCNT;
SCTRF = accept(DTSFD,(struct sockaddr *)&ADDCNT,&LGTCNT);
if (SCTRF == -1)
{
perror("accept");
}
else
{
printf("adding to master set\n\n");
FD_SET(SCTRF, &MSTDSRPTOR);
if (SCTRF > NOMFD)
{
NOMFD = SCTRF;
printf("NOMFD after adding to master set is: %d\n", NOMFD);

}
LGTCNT = sizeof (ADDCNT);
getpeername(DTSFD, (struct sockaddr *) &ADDCNT, &LGTCNT);
if(ADDCNT.ss_family == AF_INET)
{
struct sockaddr_in *NMPR = (struct sockaddr_in *) &ADDCNT;
PRTCNT = ntohs(NMPR->sin_port);
inet_ntop(AF_INET, &NMPR->sin_addr, storeAddress, sizeof (storeAddress));
}
else
{
struct sockaddr_in6 *NMPR = (struct sockaddr_in6 *) &ADDCNT;
PRTCNT = ntohs(NMPR->sin6_port);
inet_ntop(AF_INET, &NMPR->sin6_addr, storeAddress, sizeof (storeAddress));
}
printf("Accepting new connection from %s: %d on socket %d\n\n", storeAddress, PRTCNT, SCTRF);
printf("Socket %d is bound to %s\n", SCTRF, storeAddress);
LGTCNT = sizeof(ADDCNT);
getnameinfo((struct sockaddr *) &ADDCNT, LGTCNT, host, sizeof(host), service, sizeof(service), 0);

}
}
else
{
CTLBUFFR = new unsigned char [1024];

printf("####clearing CTLBUFFR####\n");
memset(&CTLBUFFR[0], 0, 1024);
printf("size of receive buffer is: %lu\n", sizeof(CTLBUFFR));

if((BTERD = recv(iSocket,CTLBUFFR,1024,0)) <=0)
{
if(BTERD==0)
{
printf("Remote Server Hung Up\n");

}
else
{
perror("ERROR IN RECEIVING");

}
close(iSocket);
FD_CLR(iSocket,&MSTDSRPTOR);
}


if(BTERD>1)
{

printf("received %d bytes of data from the CONTROLLER\n", BTERD);
printf("trying to unpack\n");

struct controlPacketHeader *cph = (struct controlPacketHeader *) malloc(sizeof(struct controlPacketHeader));


memcpy(&cph->DSTNIP, CTLBUFFR, 4);
CTLBUFFR+=4;
WAIIP=cph->DSTNIP;
memcpy(&cph->CTRLCODE, CTLBUFFR, 1);
CTLBUFFR+=1;
memcpy(&cph->RSPNSTIME, CTLBUFFR, 1);
CTLBUFFR+=1;
memcpy(&cph->PLLENGTH, CTLBUFFR, 2);
CTLBUFFR-=6;

printf("--------HEADER CONTAINS--------\n");
char * str = inet_ntoa(*(struct in_addr *)&cph->DSTNIP);
printf("dest IP: %s\n", str);
printf("control code: %u\n", (cph->CTRLCODE));
printf("response time: %u\n", (cph->RSPNSTIME));
printf("payload length: %u\n", ntohs(cph->PLLENGTH));
printf("unpack successful\n");


...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here