FreeBSD/tools/tools/netmap/pkt-gen.c
/*
 * extract the extremes from a range of ipv4 addresses.
 * addr_lo[-addr_hi][:port_lo[-port_hi]]
 */
extract the extremes from a range of ipv4 addresses.
extract the extremes from a range of ipv4 addresses .
static void
extract_ip_range(struct ip_range *r)
{
	char *ap, *pp;
	struct in_addr a;
	if (verbose)
		D("extract IP range from %s", r->name);
	r->port0 = r->port1 = 0;
	r->start = r->end = 0;
	ap = index(r->name, '-');	
	if (ap) {
		*ap++ = '\0';
	}
	pp = index(r->name, ':');
	if (pp) {
		*pp++ = '\0';
		r->port0 = r->port1 = strtol(pp, NULL, 0);
	};
	inet_aton(r->name, &a);
	r->start = r->end = ntohl(a.s_addr);
	if (ap) {
		pp = index(ap, ':');
		if (pp) {
			*pp++ = '\0';
			if (*pp)
				r->port1 = strtol(pp, NULL, 0);
		}
		if (*ap) {
			inet_aton(ap, &a);
			r->end = ntohl(a.s_addr);
		}
	}
	if (r->port0 > r->port1) {
		uint16_t tmp = r->port0;
		r->port0 = r->port1;
		r->port1 = tmp;
	}
	if (r->start > r->end) {
		uint32_t tmp = r->start;
		r->start = r->end;
		r->end = tmp;
	}
	{
		struct in_addr a;
		char buf1[16]; 
		a.s_addr = htonl(r->end);
		strncpy(buf1, inet_ntoa(a), sizeof(buf1));
		a.s_addr = htonl(r->start);
		if (1)
		    D("range is %s:%d to %s:%d",
			inet_ntoa(a), r->port0, buf1, r->port1);
	}
}
static void extract_ip_range ( struct ip_range * r ) { char * ap , * pp ; struct in_addr a ; if ( verbose ) D ( " " , r -> name ) ; r -> port0 = r -> port1 = 0 ; r -> start = r -> end = 0 ; ap = index ( r -> name , ' ' ) ; if ( ap ) { * ap ++ = ' \0 ' ; } pp = index ( r -> name , ' ' ) ; if ( pp ) { * pp ++ = ' \0 ' ; r -> port0 = r -> port1 = strtol ( pp , NULL , 0 ) ; } ; inet_aton ( r -> name , & a ) ; r -> start = r -> end = ntohl ( a . s_addr ) ; if ( ap ) { pp = index ( ap , ' ' ) ; if ( pp ) { * pp ++ = ' \0 ' ; if ( * pp ) r -> port1 = strtol ( pp , NULL , 0 ) ; } if ( * ap ) { inet_aton ( ap , & a ) ; r -> end = ntohl ( a . s_addr ) ; } } if ( r -> port0 > r -> port1 ) { uint16_t tmp = r -> port0 ; r -> port0 = r -> port1 ; r -> port1 = tmp ; } if ( r -> start > r -> end ) { uint32_t tmp = r -> start ; r -> start = r -> end ; r -> end = tmp ; } { struct in_addr a ; char buf1 [ 16 ] ; a . s_addr = htonl ( r -> end ) ; strncpy ( buf1 , inet_ntoa ( a ) , sizeof ( buf1 ) ) ; a . s_addr = htonl ( r -> start ) ; if ( 1 ) D ( " " , inet_ntoa ( a ) , r -> port0 , buf1 , r -> port1 ) ; } }
extract the extremes from a range of ipv4 addresses.
extract the extremes from a range of ipv4 addresses .
/* the first - splits start/end of range */ /* do we have ports ? */ /* grab the initial values (mandatory) */ // one ip address