由网友(我念你如初)分享简介:如何在 Linux 中使用 C 进行 UDP 广播?How to UDP Broadcast with C in Linux?推荐答案在很多IP栈中,比如Linux,这个代码是行不通的.您的套接字必须具有广播权限.试试这个:In many IP stack, such as Linux, this code d...
如何在 Linux 中使用 C 进行 UDP 广播?
How to UDP Broadcast with C in Linux?
推荐答案
在很多IP栈中,比如Linux,这个代码是行不通的.您的套接字必须具有广播权限.试试这个:
In many IP stack, such as Linux, this code does not work. Your socket must have broadcast permissions. Try this:
bcast_sock = socket(AF_INET, SOCK_DGRAM, 0);
int broadcastEnable=1;
int ret=setsockopt(bcast_sock, SOL_SOCKET, SO_BROADCAST, &broadcastEnable, sizeof(broadcastEnable));
/* Add other code, sockaddr, sendto() etc. */
相关推荐
最新文章