简体   繁体   English

无法广播以C语言工作

[英]Cant Get Broadcasting to work in C

I used the broadcaster.c from Beej's Guide to Network Programing as well as the listner.c but am unable to make have a Broadcast packet send to the server. 我使用了《 Beej网络编程指南》中broadcaster.c以及listner.c,但无法将广播数据包发送到服务器。 I have checked in Wireshark and it does send. 我已经签入Wireshark,并且确实发送。 But I cannot get the listener to receive the connection. 但是我无法让监听器接收连接。 It only seems to work for localhost and 192.168.1.56 and not for 255.255.255.255 or 192.168.1.255. 它似乎仅适用于localhost和192.168.1.56,不适用于255.255.255.255或192.168.1.255。

If you bound the socket to the broadcast address (either manually or INADDR_BROADCAST ) or INADDR_ANY on the server part, then it would receive the broadcast, otherwise Linux will not receive the packets. 如果将套接字绑定到服务器部分上的broadcast address (手动或INADDR_BROADCAST )或INADDR_ANY ,则它将接收广播,否则Linux将不会接收数据包。

Btw, routers do not forward 255.255.255.255 broadcast. 顺便说一句,路由器不转发255.255.255.255广播。 Therefore, don't use it on the infrastracture mode. 因此,请勿在基础架构模式下使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM