| 1 | /* arping/src/fuzz_pingip.c |
| 2 | * |
| 3 | * Copyright (C) 2016 Thomas Habets <[email protected]> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along |
| 16 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | #define _GNU_SOURCE |
| 20 | |
| 21 | #include<arpa/inet.h> |
| 22 | #include<errno.h> |
| 23 | #include<inttypes.h> |
| 24 | #include<stdio.h> |
| 25 | #include<stdlib.h> |
| 26 | #include<string.h> |
| 27 | #include<time.h> |
| 28 | #include<unistd.h> |
| 29 | |
| 30 | #include<pcap.h> |
| 31 | |
| 32 | #include"arping.h" |
| 33 | |
| 34 | int |
| 35 | main() |
| 36 | { |
| 37 | const size_t maxpacket = 1500; |
| 38 | unsigned char* const packet = calloc(1, maxpacket); |
| 39 | size_t packet_size = 0; |
| 40 | |
| 41 | // Read packet. |
| 42 | { |
| 43 | unsigned char* p = packet; |
| 44 | size_t size = maxpacket; |
| 45 | while (size > 0) { |
| 46 | const ssize_t n = read(STDIN_FILENO, p, size); |
| 47 | if (n == 0) { |
| 48 | break; |
| 49 | } |
| 50 | if (n < 0) { |
| 51 | fprintf(stderr, "read(): %s\n", strerror(errno)); |
| 52 | return 1; |
| 53 | } |
| 54 | size -= (size_t)n; |
| 55 | p += n; |
| 56 | } |
| 57 | packet_size = (size_t)(p - packet); |
| 58 | } |
| 59 | |
| 60 | struct pcap_pkthdr pkthdr; |
| 61 | pkthdr.ts.tv_sec = time(NULL); |
| 62 | pkthdr.ts.tv_usec = 0; |
| 63 | pkthdr.len = (uint32_t)packet_size; |
| 64 | pkthdr.caplen = (uint32_t)packet_size; |
| 65 | |
| 66 | dstip = htonl(0x12345678); |
| 67 | pingip_recv(NULL, &pkthdr, packet); |
| 68 | |
| 69 | free(packet); |
| 70 | return 0; |
| 71 | } |
| 72 | /* ---- Emacs Variables ---- |
| 73 | * Local Variables: |
| 74 | * c-basic-offset: 8 |
| 75 | * indent-tabs-mode: nil |
| 76 | * End: |
| 77 | */ |