L
linuxer
Hello all,
I have the following program, which will take ipv4 address as input
in command line and convert it from host byte order to network byte
order. I need similar thing to be done for IPv6. Any help is
appriciated. Thanks in advance.
#include <stdio.h>
main( int argc, char *argv[] )
{
unsigned int ip, b1, b2, b3, b4;
ip=b1=b2=b3=b4=0;
if (sscanf(argv[1], "%d.%d.%d.%d", &b1, &b2, &b3, &b4)
== 4 && b1<=255U && b2<=255U && b3<=255U && b4<=255U) {
//For IPv4 address
ip = htonl( (b1<<24)|(b2<<16)|(b3<<8)|b4 );
}
printf("IP_TO_LONG:%ld\n", ip);
}
I have the following program, which will take ipv4 address as input
in command line and convert it from host byte order to network byte
order. I need similar thing to be done for IPv6. Any help is
appriciated. Thanks in advance.
#include <stdio.h>
main( int argc, char *argv[] )
{
unsigned int ip, b1, b2, b3, b4;
ip=b1=b2=b3=b4=0;
if (sscanf(argv[1], "%d.%d.%d.%d", &b1, &b2, &b3, &b4)
== 4 && b1<=255U && b2<=255U && b3<=255U && b4<=255U) {
//For IPv4 address
ip = htonl( (b1<<24)|(b2<<16)|(b3<<8)|b4 );
}
printf("IP_TO_LONG:%ld\n", ip);
}