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