[erlang-questions] Local IP address in UDP packets

Serge Aleynikov serge@REDACTED
Tue Oct 10 18:08:07 CEST 2006


Hi,

We have a UDP server process that starts listening on the {0,0,0,0} 
address of a host with multiple IPs.  It needs to know the local 
destination IP address that a UDP packet was received on, as well as to 
force the source IP address for an outgoing packet to be set from a 
given local IP (using a socket bound to {0,0,0,0}).

Currently gen_udp / inet_drv don't support this feature, though this 
feature is available on some OS's with special socket options.  For 
instance, on Linux IP_PKTINFO socket option gives ancillary packet info 
containing local address.

I'd like to extend inet_drv.c to support this feature.  This brings a 
question on how to do this in a least intrusive manner without breaking 
existing gen_udp API.

I have the following proposal:

1. A new udp socket option gets introduced in inet and gen_udp:

     local_address

2. If that option is set then:

    a. packets in active mode are delivered as:

       {udp, Socket, FromIP, ToIP, InPortNo, Packet}

    b. packets in passive mode are obtained by:

       gen_udp:recv(S, Len) ->
           {ok, {FromAddress, ToAddress, Port, Packet}} | {error, Reason}

    c. packets are sent using:

       gen_udp:send(Socket, FromAddress, ToAddress, Port, Packet)

This way the new format of received tuples would *only* be effective if 
the 'local_address' option is set.

How does it sound?

Serge

-- 
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464



More information about the erlang-questions mailing list