Address Conversion Routines

download Address Conversion Routines

If you can't read please download the document

Transcript of Address Conversion Routines

Algorithm Steps:Step 1: Read the host Ip addressStep 2: Use the system call inet_addr.Send the argument as host ip.Step 3: It retrun the 32 bit binary ip address.Step 4: Read the 32 bit binary ip address.Step 5: Use the system call inet_ntoa.It retrun the value as char* type. It take the argumant as struct in_addr type.step 6: It return the dotted decimal notation ip address.#include#include#includemain(){ char host[17],*ptr; long int addr; struct in_addr ad; /* netinet/in.h*/ puts("\n\nEnter the host ID"); gets(host); addr= inet_addr(host); /*convert dotted decimal notation to 32-bit ip addres*/ puts("\n\n32 Bit IP address is:"); printf("\n\n%d",addr); puts("\n\nEnter the 32 bit ip address :\n"); scanf("%d",&ad.s_addr); ptr=inet_ntoa(ad); /*convert ip to dotted decimal*/ puts("\n\nHost ip address is"); printf("\n%s",ptr);} SAMPLE INPUT OUTPUT:Enter the host ID192.43.253.232 Bit IP address is:50146240Enter the 32 bit ip address :50146240Host ip address is128.240.250.2