Subject: Re: IP header identification field is zero, why?

From: Eric Dumazet <[email-masked]>
Date: Thu, 08 Oct 2009 11:18:28 +0200

thomas yang a écrit :

> The IP ID for TCP is non-zero, but for UDP is zero,  strange.
> 
> I want to make the IP ID (not always zero) for UDP packets, what should I do?
> (I want to use 'IP header ID, flags, offset, protocol' to identify an
> IP packets)

As I said, you can connect() your udp socket, if you send/receive trafic to/from a given destination.

if (connected_sock)
	res = connect(sock, (struct sockaddr *)&addr, sizeof(addr));

(Only once)

Then, your sendto() can be faster (because no route lookup is performed)

   if (sendto(sock, buffer, psize, 0,
                  connected_socks ? NULL : (struct sockaddr *)&addr,
                                   sizeof(struct sockaddr_in)) != -1)

Then linux *will* generate an ID for each datagram.