Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / The system function with the prototype:  uint16_t ntohs (uint16_t net16bitvalue) can be used to convert a  16-bit port number from the network -byte order to a host -byte order

The system function with the prototype:  uint16_t ntohs (uint16_t net16bitvalue) can be used to convert a  16-bit port number from the network -byte order to a host -byte order

Computer Science

The system function with the prototype:  uint16_t ntohs (uint16_t net16bitvalue) can be used to convert a  16-bit port number from the network -byte order to a host -byte order. Write a C function to implement the ntohs function as shown in the following program, where the utility function  byte_order returns the logical value  true  if the system has the same byte ordering as the Internet protocols;otherwise, it returns false.

typedef union { uint16_t s;  char c  [2]; } UN; 

bool byte_order  () 

{

  UN un; un.s = 0x0102;

  return (un.c  [0] == 1 && un.c  [1] == 2) ? true : false; 

}

uint16_t ntohs (uint16_t net16bitvalue)

{

  // FILL IN YOUR STATEMENTS HERE

}

int main () 

{

  uint16_t port_num;

 printf  (“ enter the port number in network -byte order: ”);

 scanf  (“%hd”, & port_num);

 printf  (“ port number in host -byte order = %d \n”, ntohs (port_num)); 

 exit (0); 

}

Option 1

Low Cost Option
Download this past answer in few clicks

2.87 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE