#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
static char const rcsid[] = "$Id: rv_iptoint.c,v 1.2 2004/03/10 18:04:33 wilhelm Exp $";
unsigned int rv_iptoint (char * ipstring) {
unsigned int temp;
char buffer[10];
char *point= &buffer[0];
int i;
point = strtok ( ipstring, "." );
if (point == NULL) { return 0; }
if (strcmp(point, "??") == 0) {
temp = 0xFF;
}
else {
temp = (int) strtol (point, (char**)NULL, 10);
}
for (i=0 ; i<3 ; i++) {
point = strtok ( NULL, "." );
if ( (point == NULL) ) {
return 0;
}
else if ((strcmp(point, "??") == 0) ) {
temp = temp*0x100 + 0xFF;
}
else {
temp = temp*0x100 + (int) strtol (point, (char**)NULL, 10);
}
}
return temp;
}
#include <stdio.h>
#include <strings.h>
static char const rcsid[] = "$Id: rv_inttoip.c,v 1.1 2002/08/15 23:15:48 ttraffic Exp $";
char* rv_inttoip (unsigned int ipno, char* point) {
int byte[4], i;
for (i=0 ; i<4 ; i++) {
byte[i] = ipno & 0xFF;
ipno = ipno / 0x100;
}
sprintf (point, "%d.%d.%d.%d", byte[3], byte[2], byte[1], byte[0]);
return point;
}