如何在SOCK_PACKET套接字上发送数据而不指定绑定到的主机?我已经构造了IP标头以显示它应该去的地方,但是write()无法正常工作.
How do I send data on a SOCK_PACKET socket without specifying which host it's bound for? I've constructed the IP header to show where it should go, but write() won't work.
推荐答案不要.使用write(),使用sendto().
Don't. use write(), use sendto().
如果使用PF_PACKET,SOCK_DGRAM,则它将为您构建链接层标头,这通常是您想要的.不过,您仍然需要构建正在使用的更高协议.
If you use PF_PACKET,SOCK_DGRAM, then it builds the link-layer headers for you, which is normally what you want. You still need to build whatever higher protocol you are using on top though.
您在目标参数中指定了一个sockaddr_ll.您可以指定链路层单播地址,多播地址或广播地址.
You specify a sockaddr_ll in the destination parameter. You can specify a link-layer unicast address, multicast address or broadcast address.
更多推荐
在AF
发布评论