我对联网还很陌生,我一直在尝试了解ARP请求。我一直在使用mininet和wirehark来测试我在做什么。
[当我使用mininet生成2台主机(h1和h2)和一台交换机时,我的ARP广播会立即收到ARP响应,而一切正常。
当我使用给定的router.py脚本在mininet上生成以下内容时-
*** Creating network
*** Adding controller
*** Adding hosts:
h1x1 h1x2 h2x1 h2x2 h3x1 h3x2 r0
*** Adding switches:
s1 s2 s3
*** Adding links:
(h1x1, s1) (h1x2, s1) (h2x1, s2) (h2x2, s2) (h3x1, s3) (h3x2, s3) (s1, r0) (s2, r0) (s3, r0)
*** Configuring hosts
h1x1 h1x2 h2x1 h2x2 h3x1 h3x2 r0
*** Starting controller
c0
*** Starting 3 switches
s1 s2 s3 ...
*** Routing Table on Router:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 r0-eth3
172.16.0.0 0.0.0.0 255.240.0.0 U 0 0 0 r0-eth2
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 r0-eth1
// ./a.out Send <InterfaceName> <DestIP> <RouterIP> <Message>
mininet> h1x1 ./a.out Send h1x1-eth0 10.0.0.1 192.168.1.100 'This is a test'
这是我在mininet上运行命令以运行ARP请求的方式。
[当我尝试使用目标IP 10.0.0.1和路由器IP 192.168.1.00运行ARP请求时,我的ARP请求正常广播,但没有收到ARP答复,而是收到了一系列ICMPv6响应。
这是我创建ARP标头的方式
struct arp_hdr construstArpRequest(char if_name[], int sockfd, struct in_addr dst, struct ifreq if_hwaddr) {
printf("Constructing ARP request --\n");
struct arp_hdr arphdr;
arphdr.ar_hrd = htons(0x0001);
arphdr.ar_pro = htons(0x0800);
arphdr.ar_hln = 6;
arphdr.ar_pln = 4;
arphdr.ar_op = htons(0x0001);
unsigned long sip = get_ip_saddr(if_name, sockfd); // source IP
memcpy(arphdr.ar_sip, &sip, 4); // source IP
memcpy(arphdr.ar_tip, &dst.s_addr, 4); // taget IP
memset(arphdr.ar_tha, 0, 6); // taget HA
memcpy(arphdr.ar_sha, if_hwaddr.ifr_hwaddr.sa_data, 6); // source HA
return arphdr;
}
并且我创建我的ARP请求
int sockfd = -1;
if((sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0){
perror("socket() failed!");
}
// connect to an internet frame
struct ifreq if_hwaddr;
memset(&if_hwaddr, 0, sizeof(struct ifreq));
strncpy(if_hwaddr.ifr_name, interfaceName, IFNAMSIZ-1);
if(ioctl(sockfd, SIOCGIFHWADDR, &if_hwaddr) < 0){
perror("SIOCGIFHWADDR");
}
struct arp_hdr arpRequest;
arpRequest = construstArpRequest(interfaceName, sockfd, router_ip, if_hwaddr);
如果我需要包含有关我实际如何发送请求的代码,我不能但不确定是否是必要的代码。在我的整个研究过程中,我遇到了一些答案,说您不会收到广播响应,因为您正在网络上运行它,是这样,如何获得目标MAC地址?
ARP请求仅针对IPv4,并且使用广播(IPv6没有广播,并且使用NDP,而不是ARP),但是路由器不会将广播转发到其他网络。
源主机将使用其配置的掩码来屏蔽目标地址,以确定目标地址是否在同一网络上。如果目标在同一网络上,它将使用ARP(在ARP表中或发送新的ARP请求)来确定目标主机的数据链路地址,并使用该地址来构建数据链路帧。如果目标位于不同的网络上,则源主机将使用ARP(在ARP表中或发送新的ARP请求)来确定其已配置网关的数据链路地址,并且它将使用网关数据链路用于建立数据链接框架的地址。
您正在尝试对其他网络上的主机使用ARP请求,但这将无法正常工作。尝试向其他网络上的目标发送ARP请求将不会获得任何响应,并且您看到了这一点(您需要为ARP请求实现超时,并在网络堆栈上向该请求进程发送一条错误消息,当它发出请求时超时)。
您看到的IPv6流量是正常的IPv6维护流量,它定期在配置IPv6的LAN上发生。