|
Home ► Lab Exercise ► Network Lab Exercise Programs ► Implementation Of Address Conversion Routines ▼
Implementation Of Address Conversion Routines |
Algorithm Steps:
Step 1: Read the host Ip address
Step 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.
C Program To Implement Address Conversion Routines
#include
#include
#include
main()
{
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 ID
192.43.253.2
32 Bit IP address is:
50146240
Enter the 32 bit ip address :
50146240
Host ip address is
128.240.250.2
|
|
⇓Student Projects⇓
⇑Student Projects⇑
|