UDP Socket Bound to Specific Interface Will Receive Broadcasts

Last reviewed: January 11, 1997
Article ID: Q156317
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) for Windows NT, versions 3.51, 4.0

SUMMARY

A UDP application that uses the bind() Winsock API to restrict incoming traffic to a particular interface will continue to receive broadcast messages directed to the subnet for that interface.

MORE INFORMATION

On most UNIX systems, it is possible for an application using UDP to filter out broadcasts that it would normally receive. This is accomplished by binding to a network interface explicitly instead of specifying INADDR_ANY.

The following code segment illustrates this operation:

   {
      struct sockaddr_in local;

      local.port = htons(5001); // select some port
      local.sin_family = AF_INET;
      local.sin_addr.s_addr = INADDR_ANY;

      bind(sockUDP, (struct sockaddr *)&local, sizeof(local) );

      /* start doing recvfrom()s here */

   }

If another application were to issue a broadcast datagram on the same network/subnet, port 5001, the above socket would also receive this datagram.

On the other hand, a UNIX-based sockets application would avoid receiving broadcasts by using a network interface address instead of INADDR_ANY. For example:

   local.sin_addr.s_addr = inet_addr("11.1.1.1");

assuming 11.1.1.1 is a local network interface on the same host. These applications, therefore, do not expect to see broadcasts unless they bind to INADDR_ANY.

This is not the expected behavior on Windows NT and Windows 95. On these platforms, an application using UDP datagrams for communication will continue to receive broadcasts aimed at its network, whether or not it binds to INADDR_ANY.

Note that an application that binds to a specific interface will not receive datagrams, broadcast or otherwise, that are directed to another interface and its corresponding network/subnet.

This behavior is by design.


KBCategory: kbnetwork kbtshoot
KBSubcategory: kbnocat
Additional reference words: 3.51 4.00 kbdsi



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 11, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.