win_adv_capture.c File Reference

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <pcap.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cygwin/in.h>
#include "debug.h"
#include "mn.h"

Include dependency graph for win_adv_capture.c:

Go to the source code of this file.

Data Structures

struct  dst_data

Functions

pid_t init_pcap_for_advs (void)


Function Documentation

pid_t init_pcap_for_advs ( void   ) 

Definition at line 78 of file win_adv_capture.c.

References dst_data::addr, DEBUG(), and dst_data::s.

Referenced by mn_init().

00079 {
00080         pcap_t *fp;
00081         char error[PCAP_ERRBUF_SIZE];
00082         char *dev;
00083         struct dst_data dst;
00084         pid_t pid;
00085 
00086         pid = fork();
00087         if (pid < 0) {
00088                 DEBUG(DEBUG_INFO, "init_pcap_for_advs: fork failed: %s\n",
00089                       strerror(errno));
00090                 return -1;
00091         }
00092 
00093         if (pid > 0) {
00094                 /* in parent - return */
00095                 return pid;
00096         }
00097 
00098         dst.s = socket(AF_INET, SOCK_DGRAM, 0);
00099         if (dst.s < 0) {
00100                 perror("socket");
00101                 exit(1);
00102         }
00103         dst.addr.sin_family = AF_INET;
00104         dst.addr.sin_addr.s_addr = htonl((127 << 24 | 1));
00105         dst.addr.sin_port = htons(4344);
00106 
00107         /* FIX: should support more than one interface and also detect new
00108          * interfaces when, e.g., wireless LAN card is inserted */
00109 
00110         dev = pcap_lookupdev(error);
00111         if (dev == NULL) {
00112                 DEBUG(DEBUG_INFO,
00113                       "init_pcap_for_advs: Could not get device (%s)\n",
00114                       error);
00115                 return -1;
00116         }
00117 
00118         DEBUG(DEBUG_INFO, "init_pcap_for_advs: using device '%s'\n", dev);
00119         fp = pcap_open_live(dev, 1500, 0, 20, error);
00120         if (fp == NULL) {
00121                 DEBUG(DEBUG_INFO, "pcap_open_live failed (%s)\n", error);
00122                 return -1;
00123         }
00124 
00125         if (pcap_setfilter(fp, &agentadv_fprog) < 0) {
00126                 DEBUG(DEBUG_INFO,
00127                       "init_pcap_for_advs: Could not attach BPF\n");
00128                 return -1;
00129         }
00130 
00131         /* in child - start capturing packets */
00132         DEBUG(DEBUG_INFO, "init_pcap_for_advs: child starting to capture "
00133               "packets\n");
00134 
00135         pcap_loop(fp, 0, dispatcher_handler, (u_char *) &dst);
00136 
00137         /* never reached */
00138         DEBUG(DEBUG_INFO, "pcap_loop returned?!\n");
00139         return 0;
00140 }

Here is the call graph for this function:


Generated on Tue Jan 15 08:50:55 2008 for Virtual foreign agent generator version 0.1 by  doxygen 1.5.1