c - 发送免费 ARP 消息

标签 c linux networking

我正在寻找一种在 Linux 用户空间应用程序中以编程方式(在 C 中)发送无偿 ARP 消息的方法。我注意到在

的 procfs 中有一些用于配置 ARP 的文件
/proc/sys/net/ipv4/conf/<interface_name> 

有没有办法通过对相应网络接口(interface)的 ioctl 调用来做到这一点?

最佳答案

使用 scapy :

from scapy.all import *

SELF_MAC = '02:02:02:02:02:02'    # fill in with your MAC address
BCAST_MAC = 'ff:ff:ff:ff:ff:ff'

def create_ARP_request_gratuituous(ipaddr_to_broadcast):
    arp = ARP(psrc=ipaddr_to_broadcast,
              hwsrc=SELF_MAC,
              pdst=ipaddr_to_broadcast)
    return Ether(dst=BCAST_MAC) / arp

# and then call sendp() with the result

关于c - 发送免费 ARP 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17029120/

相关文章:

linux - bash_profile 没有正常工作

apache - 将 HTTP 请求重定向到 2 个不同的服务器

networking - docker 容器是否有自己的 TCP/IP 堆栈?

docker - 无法从网络设备正确发送到kafka-docker

c - 为什么一个段有故障而另一个段没有故障?

c - 段错误: Core Dumped while initializing large size arrays

c - xpath 和命名空间的另一个问题

c - 当我删除main函数时是否可以链接到git的源代码?

c++ - 使用条件变量在 Linux 中实现 Windows 事件?

linux - Linux 中进程的所有权(给定 PID)