1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
/*
Perl ARP Extension
Send the packet
Linux code
Programmed by Bastian Ballmann
Last update: 01.12.2004
This program is free software; you can redistribute
it and/or modify it under the terms of the
GNU General Public License version 2 as published
by the Free Software Foundation.
This program is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
*/
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <unistd.h>
#include "arp.h"
int send_packet_linux(u_char *dev, u_char *packet, u_int packetsize)
{
struct sockaddr addr;
int sock;
if(strlen(dev) == 0)
{
printf("dev is undefined. Terminating.\n");
return 0;
}
if(packetsize == 0)
{
printf("packetsize is zero. Terminating.\n");
return 0;
}
// Create socket descriptor
if( ( sock = socket(AF_INET,SOCK_TYPE,htons(ETH_P_ALL))) < 0 )
{
perror("socket");
return 0;
}
// Set dev and send the packet
strncpy(addr.sa_data,dev,sizeof(addr.sa_data));
if( (sendto(sock,packet,packetsize,0,&addr,sizeof(struct sockaddr))) < 0 )
{
perror("send");
return 0;
}
close(sock);
return 1;
}
|