FreeBSD/tools/tools/netmap/pkt-gen.c
/*
 * increment the addressed in the packet,
 * starting from the least significant field.
 *	DST_IP DST_PORT SRC_IP SRC_PORT
 */
increment the addressed in the packet,
starting from the least significant field.
increment the addressed in the packet starting from the least significant field .
static void
update_addresses(struct pkt *pkt, struct glob_arg *g)
{
	uint32_t a;
	uint16_t p;
	struct ip *ip = &pkt->ip;
	struct udphdr *udp = &pkt->udp;
    do {
	if (g->options & OPT_RANDOM_SRC) {
		udp->uh_sport = random();
		ip->ip_src.s_addr = random();
	} else {
		p = ntohs(udp->uh_sport);
		if (p < g->src_ip.port1) { 
			udp->uh_sport = htons(p + 1);
			break;
		}
		udp->uh_sport = htons(g->src_ip.port0);
		a = ntohl(ip->ip_src.s_addr);
		if (a < g->src_ip.end) { 
			ip->ip_src.s_addr = htonl(a + 1);
			break;
		}
		ip->ip_src.s_addr = htonl(g->src_ip.start);
		udp->uh_sport = htons(g->src_ip.port0);
	}
	if (g->options & OPT_RANDOM_DST) {
		udp->uh_dport = random();
		ip->ip_dst.s_addr = random();
	} else {
		p = ntohs(udp->uh_dport);
		if (p < g->dst_ip.port1) { 
			udp->uh_dport = htons(p + 1);
			break;
		}
		udp->uh_dport = htons(g->dst_ip.port0);
		a = ntohl(ip->ip_dst.s_addr);
		if (a < g->dst_ip.end) { 
			ip->ip_dst.s_addr = htonl(a + 1);
			break;
		}
	}
	ip->ip_dst.s_addr = htonl(g->dst_ip.start);
    } while (0);
}
static void update_addresses ( struct pkt * pkt , struct glob_arg * g ) { uint32_t a ; uint16_t p ; struct ip * ip = & pkt -> ip ; struct udphdr * udp = & pkt -> udp ; do { if ( g -> options & OPT_RANDOM_SRC ) { udp -> uh_sport = random ( ) ; ip -> ip_src . s_addr = random ( ) ; } else { p = ntohs ( udp -> uh_sport ) ; if ( p < g -> src_ip . port1 ) { udp -> uh_sport = htons ( p + 1 ) ; break ; } udp -> uh_sport = htons ( g -> src_ip . port0 ) ; a = ntohl ( ip -> ip_src . s_addr ) ; if ( a < g -> src_ip . end ) { ip -> ip_src . s_addr = htonl ( a + 1 ) ; break ; } ip -> ip_src . s_addr = htonl ( g -> src_ip . start ) ; udp -> uh_sport = htons ( g -> src_ip . port0 ) ; } if ( g -> options & OPT_RANDOM_DST ) { udp -> uh_dport = random ( ) ; ip -> ip_dst . s_addr = random ( ) ; } else { p = ntohs ( udp -> uh_dport ) ; if ( p < g -> dst_ip . port1 ) { udp -> uh_dport = htons ( p + 1 ) ; break ; } udp -> uh_dport = htons ( g -> dst_ip . port0 ) ; a = ntohl ( ip -> ip_dst . s_addr ) ; if ( a < g -> dst_ip . end ) { ip -> ip_dst . s_addr = htonl ( a + 1 ) ; break ; } } ip -> ip_dst . s_addr = htonl ( g -> dst_ip . start ) ; } while ( 0 ) ; }
increment the addressed in the packet,
 starting from the least significant field.
increment the addressed in the packet starting from the least significant field .
/* XXX for now it doesn't handle non-random src, random dst */ /* just inc, no wrap */ /* just inc, no wrap */ /* just inc, no wrap */ /* just inc, no wrap */ // update checksum