UDP bind(2) on the same port using SO_REUSEADDR

Jon Dugan jdugan at ncsa.uiuc.edu
Tue Mar 16 21:25:12 PST 2004


  Imagine two process, A & B.

  Process A which has a UDP socket bound to a specific address of the machine
  and a particular port (host:port, say 10.10.10.1:1234). If I set
  SO_REUSEADDR for the socket in Process B I am able to use the wildcard
  address (INADDR_ANY or 0.0.0.0) in Process B to bind to the same port
  (*:port, eg.  *:1234).  You can also do the converse, process A can bind to
  the wildcard address and process B can use a specific address).

  Unix Network Programming by W. Richard Stevens mentions this on pages 195-6
  and actually says that using SO_REUSEADDR it is possible to bind to the same
  address:port tuple as another already running process.  I was unable to do
  do that.  Stevens goes on to say that the multiple binding is usually used
  for multicast, which makes sense.  Should it be allowed at all for unicast?

  I am able to do this in 4.4-RELEASE, 4.9-RELEASE and 5.1-RELEASE.

  I'm not at all certain this is a bug, but it is certainly somewhat
  non-obvious behaviour.  Is this a bug or and oddity?

  It came up because I am using rtg to poll many interfaces on a couple of
  routers on 5 second intervals (gotta love those Junipers, they don't even
  bat an eye).  rtg uses the net-snmp library.  The same machine also runs a
  radius server listening on the radius port (1812).  radiusd bound to the
  socket using a specific address.  rtg/net-snmp just ask for the next
  available port and use the wildcard address.  Once in awhile (actually every
  5-10 minutes) rtg/net-snmp would do an snmp get using port 1812 which the
  system had given to it, but radiusd would end up getting the results.  This
  causes indigestion in radiusd...

  Since I spent quite a bit of time running this down today I figured I'd
  share with the class.

Jon
-- 
Jon Dugan             |  Senior Network Engineer, NCSA Network Research
jdugan at ncsa.uiuc.edu  |  269 CAB, 605 E Springfield, Champaign, IL 61820
217-244-7715          |  http://www.ncsa.uiuc.edu/~jdugan/


More information about the freebsd-net mailing list