finish -g rewrite

pull/5/merge
David Schweikert 13 years ago
parent 7f70bc3343
commit 9d23ce7a11

@ -1019,10 +1019,8 @@ void add_cidr(char *addr)
int ret; int ret;
struct addrinfo addr_hints; struct addrinfo addr_hints;
struct addrinfo *addr_res; struct addrinfo *addr_res;
struct in_addr in_addr_tmp;
unsigned long net_addr; unsigned long net_addr;
unsigned long net_last; unsigned long net_last;
char buffer[20];
/* Split address from mask */ /* Split address from mask */
addr_end = strchr(addr, '/'); addr_end = strchr(addr, '/');
@ -1061,6 +1059,8 @@ void add_cidr(char *addr)
/* add all hosts in that network (excluding network and broadcast address) */ /* add all hosts in that network (excluding network and broadcast address) */
while(++net_addr < net_last) { while(++net_addr < net_last) {
struct in_addr in_addr_tmp;
char buffer[20];
in_addr_tmp.s_addr = htonl(net_addr); in_addr_tmp.s_addr = htonl(net_addr);
inet_ntop(AF_INET, &in_addr_tmp, buffer, sizeof(buffer)); inet_ntop(AF_INET, &in_addr_tmp, buffer, sizeof(buffer));
add_name(cpystr(buffer)); add_name(cpystr(buffer));
@ -1071,41 +1071,51 @@ void add_cidr(char *addr)
void add_range(char *start, char *end) void add_range(char *start, char *end)
{ {
// /* IP start and end points are specified */ struct addrinfo addr_hints;
// pEnd = *argv; struct addrinfo *addr_res;
// unsigned long start_long;
// /* parameters should be start and end ranges */ unsigned long end_long;
// if( ( inet_addr( pStart ) != INADDR_NONE ) && ( inet_addr( pEnd ) != INADDR_NONE ) ) int ret;
// {
// sStart.s_addr = inet_addr( pStart ); /* parse start address (IPv4 only) */
// sEnd.s_addr = inet_addr( pEnd ); memset(&addr_hints, 0, sizeof(struct addrinfo));
// addr_hints.ai_family = AF_UNSPEC;
// }/* IF */ addr_hints.ai_flags = AI_NUMERICHOST;
// else ret = getaddrinfo(start, NULL, &addr_hints, &addr_res);
// usage(); if(ret) {
// fprintf(stderr, "Error: can't parse address %s: %s\n", start, gai_strerror(ret));
// }/* ELSE */ exit(2);
// }
// /* ensure that the end point is greater or equal to the start */ if(addr_res->ai_family != AF_INET) {
// if( htonl( sEnd.s_addr ) >= htonl( sStart.s_addr ) ) fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
// { exit(2);
// /* start and end points should be determined, so generate list */ }
// unsigned int uiDiff; start_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
// struct in_addr sTemp;
// int iCount; /* parse end address (IPv4 only) */
// memset(&addr_hints, 0, sizeof(struct addrinfo));
// uiDiff = htonl( sEnd.s_addr ) - htonl( sStart.s_addr ) + 1; addr_hints.ai_family = AF_UNSPEC;
// addr_hints.ai_flags = AI_NUMERICHOST;
// for( iCount = 0; iCount < uiDiff; iCount++ ) ret = getaddrinfo(end, NULL, &addr_hints, &addr_res);
// { if(ret) {
// sTemp.s_addr = sStart.s_addr + ntohl( iCount ); fprintf(stderr, "Error: can't parse address %s: %s\n", end, gai_strerror(ret));
// pTemp = cpystr( inet_ntoa( sTemp ) ); exit(2);
// add_name( pTemp ); }
// if(addr_res->ai_family != AF_INET) {
// }/* FOR */ fprintf(stderr, "Error: -g works only with IPv4 addresses\n");
// }/* IF */ exit(2);
// else }
// usage(); end_long = ntohl(((struct sockaddr_in *) addr_res->ai_addr)->sin_addr.s_addr);
/* generate */
while(start_long <= end_long) {
struct in_addr in_addr_tmp;
char buffer[20];
in_addr_tmp.s_addr = htonl(start_long);
inet_ntop(AF_INET, &in_addr_tmp, buffer, sizeof(buffer));
add_name(cpystr(buffer));
start_long++;
}
} }

@ -0,0 +1 @@
gcc -DHAVE_CONFIG_H -D_BSD_SOURCE -D_POSIX_SOURCE -I. -Wall -std=c89 -pedantic -c -o fping.o fping.c
Loading…
Cancel
Save