INFO: UDP Socket Bound to Specific UI Receives Broadcasts (156317)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0, when used with:
- the operating system: Microsoft Windows NT 3.51
- the operating system: Microsoft Windows NT 4.0
- the operating system: Microsoft Windows 2000
This article was previously published under Q156317 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.
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbAPI kbinfo kbnetwork kbtshoot kbWinsock KB156317 |
---|
|