在 Windows 7 上发送 UDP 广播 [英] Send UDP broadcast on Windows 7

查看:64
本文介绍了在 Windows 7 上发送 UDP 广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台 PC,有两个网卡连接到不同的网络(多宿主网络设置).我想在两个网络上发送 UDP 广播帧.帧的发送方 IP 地址必须是用于发送帧的适配器的 IP 地址.目标地址应为 LIMITED BROADCAST 地址.

I have a PC with two network cards connected to different networks (multi homed network setup). I want to send UDP broadcast frames on both networks. The senders IP address of the frames must be the IP address of the adapter, that is used to send the frame. The destination address should be the LIMITED BROADCAST address.

客户应用程序不应以管理权限运行(不接受 UAC).

The customer application should not run with administrative rights (UAC is not acceptible).

如何将这些 UDP 帧发送到 LIMITED BROADCAST 地址 (255.255.255.255)?我如何将这些帧发送到 NETWORK BROADCAST 地址 (x.y.z.255)?

How can I send these UDP frames to the LIMITED BROADCAST address (255.255.255.255)? How could I send these frames to the NETWORK BROADCAST address (x.y.z.255)?

我知道如何使用原始套接字执行此操作.但是原始套接字只能在具有管理权限的情况下使用.

I know how to do this with raw sockets. But raw sockets can only be used with administrative rights.

推荐答案

难道你不能只打开两个普通的 UDP 套接字并绑定一个到每个接口地址,然后简单地发送到广播地址吗?

Can't you just open two normal UDP sockets and bind one to each of the interface addresses and then simply send to the broadcast addresses ?

据我所知,这将处理两个网络上的发送,并确保发送的数据包具有正确的 IP 地址.如果您将单个套接字绑定到 INADDR_ANY,它就不会工作,当然,如果机器中只有一个网络适配器,它就会工作.要创建一个完整的解决方案,最好遍历可用地址并为每个地址创建一个套接字,绑定到每个地址并从每个地址发送.

This will, as far as I know, deal with the sending on both networks and it will ensure that the packets sent will have the correct ip address. It wont work if you bind a single socket to INADDR_ANY which, of course, WILL work if there's only a single network adapter in the machine. To create a complete solution it's probably best to iterate over the available addresses and create a socket for each, bind to each and send from each.

这篇关于在 Windows 7 上发送 UDP 广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆