Hi I want to implement a TCP mudole in C++, I have the classes both TCPAssignmen
ID: 3890062 • Letter: H
Question
Hi
I want to implement a TCP mudole in C++, I have the classes both TCPAssignment.cpp TCPAssignment.hpp , I need to complete some method in both of them to finish this homework
so I want to Implement my own socket()/bind()/getsockname()/close() ==> only this part
or at least socket()
these are the 2 classes.
TCPAssignment.cpp (/Desktop/abdulkarim/KENSv3-master/app/TestTCP) gedit En ) 16:04 Open Save ost.hpp> #include #include #include #include #include cerrno> «E/Networking/E.Packet.hpp> E/Networking/ENetworkutil.hpp> "TCPAssignment.hpp" nanespace E TCPAssignment::TCPAssignment (Host host) HostModule(" TCP", host), NetworkModule (this->getHostModuleNe host->getNetworkSystem()), SystenCallInterface(AF_INET, IPPROTO_TCP, host), NetworkLog(host->getNetworkSystem)) TinerModule(host->getsysten)) CPAssignment: TCPAssignment) void TCPAssignnent::initialize() void TCPAssignment::finalize() void TCPAssignnent::systencallback (UUID syscalluUID, int pid, const SystencallParaneter& param) switch(param.syscallNumber) case sOCKET: //this->syscall socket (syscalluuID, pid, param.param1 int, param.paran2 int) C++ Tab Width: 8 Ln 45, Col 2 INSExplanation / Answer
The gneral syntax of getSockName is :
So as per the ablve need to implement the given method like below.
void TCPAssignment::syscall_getsockname(UUID syscallUUID, int pid, int sockfd,
struct sockaddr *addr, socklen_t *addrlen){
struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
boolean found = false;
for (int i = 0; i < (int)socketList.size(); i++)
{
if (socketList[i]->fd == sockfd)
{
addr_in->sin_family = socketList[i]->sin_family;
addr_in->sin_port = socketList[i]->sin_port;
addr_in->sin_addr = socketList[i]->sin_addr;
*addrlen = socketList[i]->sin_addr_len;
found = true;
break;
}
}
{
returnSystemCall(syscallUUID, -1);
return;
}
returnSystemCall(syscallUUID, 0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.