"Fossies" - the Fresh Open Source Software Archive

Member "scanlogd-2.2.8/in_linux.c" (10 Mar 2021, 954 Bytes) of package /linux/misc/scanlogd-2.2.8.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "in_linux.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.2.7_vs_2.2.8.

    1 #define _BSD_SOURCE
    2 #define _DEFAULT_SOURCE
    3 #include <stdio.h>
    4 #include <unistd.h>
    5 #include <sys/types.h>
    6 #include <sys/socket.h>
    7 #include <netinet/in_systm.h>
    8 #include <netinet/in.h>
    9 #include <netinet/ip.h>
   10 #include <netinet/tcp.h>
   11 
   12 #include "params.h"
   13 #include "in.h"
   14 
   15 #ifndef __linux__
   16 #warning "This code will only work on Linux; use an alternate make target"
   17 #endif
   18 #ifdef SCANLOGD_DEVICE
   19 #warning "SCANLOGD_DEVICE makes no sense for the Linux raw socket interface"
   20 #endif
   21 #if SCANLOGD_PROMISC
   22 #warning "SCANLOGD_PROMISC makes no sense for the Linux raw socket interface"
   23 #endif
   24 
   25 static int raw;
   26 
   27 int in_init(void)
   28 {
   29     if ((raw = socket(AF_INET, SOCK_RAW, IPPROTO_TCP)) < 0) {
   30         perror("socket");
   31         return 1;
   32     }
   33 
   34     return 0;
   35 }
   36 
   37 void in_run(void (*process_packet)(struct header *packet, int size))
   38 {
   39     struct header packet;
   40     int size;
   41 
   42     while (1)
   43     if ((size = read(raw, &packet, sizeof(packet))) >= sizeof(packet.ip))
   44         process_packet(&packet, size);
   45 }