cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in_systm.h>
#include <netinet/if_ether.h>
int main(void) {
int s;
int sd;
char iface[256] = "wlp1s0";
char packet[26];
struct sockaddr sa;
s = socket(PF_PACKET,SOCK_PACKET,htons(ETH_P_ALL));
if(s < 0){perror("socket error\n");exit(EXIT_FAILURE);}
memset(&sa,0,sizeof(sa));
sa.sa_family = PF_PACKET;
snprintf(sa.sa_data,256,"%s",iface);
memset(&packet,0,sizeof(packet));
for(int i=0;i<=100;i++){
sd = sendto(s,packet,sizeof(packet),0,&sa,sizeof(sa));
if(sd < 0){perror("sendto error\n");exit(EXIT_FAILURE);}
}
return EXIT_SUCCESS;
}
如果你要定义包裹 你就应该 把包裹定义成这样:
packet[26] = {0xff,0xff .....} 这样的数据形式