嗨,我是Linux新手,有一个与套接字相关的项目.我面临的问题是,当我使用输入eth0 for interface和我的路由器的IP地址
运行代码时,./mycode eth0 192.168.1.1它会出错
您无权在该设备上捕获(套接字:不允许操作)
我从链接中获取的代码是:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pcap.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <netinet/if_ether.h>
#include <sys/ioctl.h>
int main(int argc,const char* argv[]) {
// Get interface name and target IP address from command line.
if (argc<2) {
fprintf(stderr,"usage: send_arp <interface> <ipv4-address>\n");
exit(1);
}
const char* if_name=argv[1];
const char* target_ip_string=argv[2];
// Construct Ethernet header (except for source MAC address).
// (Destination set to broadcast address, FF:FF:FF:FF:FF:FF.)
struct ether_header header; …Run Code Online (Sandbox Code Playgroud)