2023年12月11日发(作者:成立公司的流程和要求)
编程实现arp协议c语言,ARP协议c语言实现源代码.doc
ARP协议的c语言实现源代码【转载】 收藏
什么是ARP协议
英文原义:Address Resolution Protocol
中文释义:(RFC-826)地址解析协议
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define src_addr "192.168.0.239"
#define device "eth0"
#define fill_buf "aaaaaaaaaaaa"
int socket_id;
char *target = src_addr;
int nd_count = 0;int recv_count = 0;struct in_addr src, dst;struct sockaddr_ll me, he;struct timeval nd_time, recv_time;struct in_addr get_src_ip(char * devices){struct sockaddr_in saddr;int sock_id = socket(AF_INET, SOCK_DGRAM, 0);if (sock_id < 0) {perror("socket");exit(2);}if (devices) {if (tsockopt(sock_id, SOL_SOCKET, SO_BINDTODEVICE, device, strlen(device)+1) == -1)perror("WARNING: interface is ignored");}int alen = sizeof(saddr);memt(&saddr, 0, sizeof(saddr));_port = htons(0x1000);_family = AF_INET;if (connect(sock_id, (struct sockaddr*)&saddr, sizeof(saddr)) == -1) {perror("connect");exit(2);}if (getsockname(sock_id, (struct sockaddr*)&saddr, &alen) == -1) {perror("getsockname");exit(2);}clo(sock_id);return _addr;}int check_device(char* if_dev, int ss){int ifindex;struct ifreq ifr;memt(&ifr, 0, sizeof(ifr));strncpy(_name, if_dev, IFNAMSIZ-1);if (ioctl(ss, SIOCGIFINDEX, &ifr) < 0) {fprintf(stderr, "arping: unknown iface %sn", if_dev);exit(2);}ifindex = _ifindex;if (ioctl(ss, SIOCGIFFLAGS, (char*)&ifr)) {perror("ioctl(SIOCGIFFLAGS)");exit(2);}if (!(_flags&IFF_UP)) {printf("Interfac
本文发布于:2023-12-11 19:06:23,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/zhishi/a/1702292783118517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:编程实现arp协议c语言,ARP协议c语言实现源代码.doc
本文 PDF 下载地址:编程实现arp协议c语言,ARP协议c语言实现源代码.pdf
留言与评论(共有 0 条评论) |