在AF

编程入门 行业动态 更新时间:2024-10-22 23:00:05
本文介绍了在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

本文发布于:2023-11-26 21:00:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635179.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:AF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!