Question: Make this C + + program to run multiple time. #include #include #include / / Function to convert hexadecimal string to decimal integer unsigned int
Make this Cprogram to run multiple time.
#include
#include
#include
Function to convert hexadecimal string to decimal integer
unsigned int hexToDecconst std::string& hexStr
unsigned int result;
std::stringstream ss;
ss std::hex hexStr;
ss result;
return result;
Function to convert hexadecimal IP address to decimal IP address
std::string hexIPToDecconst std::string& hexIP
std::string decIP;
for sizet i ; i hexIP.size; i
std::string byteStr hexIP.substri;
unsigned int byte hexToDecbyteStr;
decIP std::tostringbyte;
if i hexIP.size
decIP ;
return decIP;
int main
std::cout "Enter the hexadecimal IP datagram header: ;
std::string header;
std::cin header;
Validate input length
if headerlength
std::cout "Error: Illegal header size" std::endl;
return ;
Extract information
unsigned int version hexToDecheadersubstr;
if version && version
std::cout "Error: Wrong version should be or std::endl;
return ;
unsigned int headerLength hexToDecheadersubstr;
unsigned int totalLength hexToDecheadersubstr;
unsigned int dataSize totalLength headerLength;
unsigned int protocol hexToDecheadersubstr;
std::string sourceIP hexIPToDecheadersubstr;
std::string destIP hexIPToDecheadersubstr;
Display information
std::cout "Version: version std::endl;
std::cout "Header Length: headerLength std::endl;
std::cout "Total Length: totalLength std::endl;
std::cout "Size of Data: dataSize std::endl;
std::cout "Protocol: protocol std::endl;
std::cout "Source IP address: sourceIP std::endl;
std::cout "Destination IP address: destIP std::endl;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
