FastUDPFlows with fixed port addresses

Eddie Kohler kohler at aciri.org
Sat Jul 7 10:06:05 EDT 2001


Hi Wei,

> My problem is that, for example when I use _start_portaddr==1000, the
> actual port address of the packets belonging to the first flow is 59395.
> The 2nd and 3rd flows' port addresses are 59651 and 59907. Why are the
> port addresses of each flow incremented by 256 and not by 1? Why is the
> Actual_port_addr==(_start_portaddr*256)%(0xFFFF) and not
> Actual_port_addr==_start_portaddr?

Do you know about network byte order and the functions 'ntohs()',
'ntohl()', 'htons()', 'htonl()'?

Multibyte numbers in a packet header may be stored in a different byte
order than your host prefers. (Network byte order is most-significant-byte
first.) When assigning numbers to or extracting numbers from a packet
header, use the 'ntohl()' functions to translate between byte orders. The
last letter is "l" for "Longs" (32 bits) or "s" for "Shorts" (16 bits).
"ntoh" translates "Network-to-Host" (extracting from a header); "hton" goes
"Host-to-Network". So your lines

>   udp->uh_sport = port_addr;
>   udp->uh_dport = port_addr;

should be

    udp->uh_sport = htons(port_addr);
    udp->uh_dport = htons(port_addr);

love,
ed



More information about the click mailing list