在AF_PACKET套接字上发送数据 [英] Sending data on AF_PACKET socket

查看:41
本文介绍了在AF_PACKET套接字上发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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_PACKET套接字上发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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