set.c

来自「ip数据包截获」· C语言 代码 · 共 31 行

C
31
字号
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<sys/socket.h>#include<sys/types.h>#include<sys/ioctl.h>#include<netinet/if_ether.h>#include<netdb.h>#include<net/ethernet.h>#include<net/if.h>int set_promisc(){    int s;    struct ifreq ifr;    strcpy(ifr.ifr_name, "eth0");    s=socket(PF_PACKET,SOCK_RAW,htons(ETH_P_IP));        if (s < 0) perror ("set promisc sock\n");    if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {        printf("Could not receive flags for the interface.\n");        exit(0);    }    ifr.ifr_flags |= IFF_PROMISC;    if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0) {        printf("Could not set the PROMISC flag.\n");        exit(0);    }    printf("Setting interface :::  eth0  ::: to promisc\n");    return s;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?