低级 Socket 编程中,INADDR_ANY 表示 Socket 可以绑定到任何可用IP地址,这是说它可以绑定到本机任何一个可用的IP地址呢还是说它可以同时绑定到本机所有有效的IP地址?
解决方案 »
- 求助,CDialogBar包含CTreeCtrl不能自动调整大小
- Sleep与Wait...函数的问题
- 求教图片加密
- 关于鼠标钩子问题,急啊!请经来帮帮忙,顺便拿分。
- 哪里有使用c++开发corba服务器和客户端的资料和例子?
- 如何为LISTCTRL的每行每列设置不同文本背景色?
- 怎么屏蔽Ctrl+Esc?
- AVIStreamGetFrameOpen总是返回NULL
- 将几个变量放在一个结构体中,用AfxBeginThread 传给一个线程,在线程中怎么用这个结构
- Doc的指针?
- 如何为动态创建的窗体中的动态创建的控件进行消息映射?在线等待,马上给分!
- 将鼠标放在某个工具条(或菜单)上,出现此工具条的提示信息,如何实现呀?
{
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.