Annotation of embedaddon/hping2/linux_sockpacket.c, revision 1.1.1.1

1.1       misho       1: /* 
                      2:  * $smu-mark$ 
                      3:  * $name: linux_sockpacket.c$ 
                      4:  * $author: Salvatore Sanfilippo <antirez@invece.org>$ 
                      5:  * $copyright: Copyright (C) 1999 by Salvatore Sanfilippo$ 
                      6:  * $license: This software is under GPL version 2 of license$ 
                      7:  * $date: Fri Nov  5 11:55:48 MET 1999$ 
                      8:  * $rev: 8$ 
                      9:  */ 
                     10: 
                     11: #include "hping2.h"
                     12: 
                     13: #if (defined OSTYPE_LINUX) && (!defined FORCE_LIBPCAP)
                     14: #include <sys/types.h>
                     15: #include <sys/socket.h>
                     16: #include <netinet/in.h>
                     17: #include <unistd.h>            /* close */
                     18: #include <stdio.h>
                     19: 
                     20: #include "globals.h"
                     21: 
                     22: static void enlarge_recvbuf(int fd)
                     23: {
                     24:        int val = 131070;
                     25:        int len = sizeof(val);
                     26: 
                     27:        /* Don't check the error: non fatal */
                     28:        setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (const char *) &val, len);
                     29: }
                     30: 
                     31: int open_sockpacket()
                     32: {
                     33:        int s;
                     34: 
                     35:        if (opt_debug)
                     36:                printf("DEBUG: Trying to open PF_PACKET socket... ");
                     37: 
                     38:        s = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_IP));
                     39: 
                     40:        if (s == -1) {
                     41:                if (opt_debug) {
                     42:                        printf("DEBUG: failed ( 2.0.x kernel? )\n");
                     43:                        printf("DEBUG: Trying to open SOCK_PACKET socket... ");
                     44:                }
                     45:                s = socket(AF_INET, SOCK_PACKET, htons(ETH_P_IP));
                     46:        }
                     47: 
                     48:        if (s == -1) {
                     49:                perror("[open_sockpacket] socket()");
                     50:                return -1;
                     51:        }
                     52:        enlarge_recvbuf(s);
                     53: 
                     54:        if (opt_debug)
                     55:                printf("DEBUG: PF_PACKET, SOCK_RAW open OK\n");
                     56: 
                     57:        return s;
                     58: }
                     59: 
                     60: int close_sockpacket(int s)
                     61: {
                     62:        return close(s);
                     63: }
                     64: #endif /* OSTYPE_LINUX && !FORCE_LIBPCAP */

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