Annotation of embedaddon/arping/src/fuzz_pingip.c, revision 1.1

1.1     ! misho       1: /* arping/src/fuzz_pingip.c
        !             2:  *
        !             3:  *  Copyright (C) 2016 Thomas Habets <thomas@habets.se>
        !             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: #include<arpa/inet.h>
        !            20: #include<errno.h>
        !            21: #include<inttypes.h>
        !            22: #include<stdio.h>
        !            23: #include<stdlib.h>
        !            24: #include<string.h>
        !            25: #include<time.h>
        !            26: #include<unistd.h>
        !            27: 
        !            28: #include<pcap.h>
        !            29: 
        !            30: #include"arping.h"
        !            31: 
        !            32: int
        !            33: main()
        !            34: {
        !            35:         const size_t maxpacket = 1500;
        !            36:         char* const packet = calloc(1, maxpacket);
        !            37:         size_t packet_size = 0;
        !            38: 
        !            39:         // Read packet.
        !            40:         {
        !            41:                 char* p = packet;
        !            42:                 size_t size = maxpacket;
        !            43:                 while (size > 0) {
        !            44:                         const ssize_t n = read(STDIN_FILENO, p, size);
        !            45:                         if (n == 0) {
        !            46:                                 break;
        !            47:                         }
        !            48:                         if (n < 0) {
        !            49:                                 fprintf(stderr, "read(): %s\n", strerror(errno));
        !            50:                                 return 1;
        !            51:                         }
        !            52:                         size -= n;
        !            53:                         p += n;
        !            54:                 }
        !            55:                 packet_size = p - packet;
        !            56:         }
        !            57: 
        !            58:         struct pcap_pkthdr pkthdr;
        !            59:         pkthdr.ts.tv_sec = time(NULL);
        !            60:         pkthdr.ts.tv_usec = 0;
        !            61:         pkthdr.len = packet_size;
        !            62:         pkthdr.caplen = packet_size;
        !            63: 
        !            64:         dstip = htonl(0x12345678);
        !            65:         pingip_recv(NULL, &pkthdr, packet);
        !            66: 
        !            67:         free(packet);
        !            68:         return 0;
        !            69: }
        !            70: /* ---- Emacs Variables ----
        !            71:  * Local Variables:
        !            72:  * c-basic-offset: 8
        !            73:  * indent-tabs-mode: nil
        !            74:  * End:
        !            75:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>