|
| IP Address classification by shridatt zambodker | #include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
main(){
int x;
char ip[40];
struct in_addr bin;
unsigned int y,a,b,c;
printf("\n Enter IP address: ");
scanf("%s",&ip);
printf("%s",ip);
x= inet_aton(ip,&bin);
printf("\n %d",x);
if (x==1)
{
printf("\n The Ip %s is valid",ip);
printf("\n After conversion to Hexadecimal %x",bin.s_addr);
y = ntohl(bin.s_addr);
printf("\n The rotated IP is %x",y);
a= y & 0X80000000;
b= y & 0Xc0000000;
c= y & 0Xe0000000;
if (a==0X00000000)
printf("\n The IP belongs to CLASS A ");
else if (b==0X80000000)
printf("\n The IP belongs to CLASS B ");
else if (c==0XC0000000)
printf("\n The IP belongs to CLASS C ");
else
printf("\n The IP does not belong to any CLASS ");
}
else
printf("\n The IP %s is invalid",ip);
} | Views 16
Rating 0
Language C
Category Miscellaneous
Compiler CC
OS Any
Last Modified 13th Jan 10 05:02:08 AM
|
|
|
|
|
|