netdump - #define RETSIGTYPE void #include...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
#define RETSIGTYPE void #include <sys/types.h> #include <sys/time.h> #include <netinet/in.h> #include <pcap.h> #include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #ifndef setsignal_h #define setsignal_h RETSIGTYPE (*setsignal(int, RETSIGTYPE (*)(int)))(int); #endif char cpre580f98[] = "netdump"; void raw_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p); int packettype; char *program_name; /* Externs */ extern void bpf_dump(struct bpf_program *, int); extern char *copy_argv(char **); /* Forwards */ void program_ending(int); /* Length of saved portion of packet. */ int snaplen = 1500;; static pcap_t *pd; extern int optind; extern int opterr; extern char *optarg; int pflag = 0, aflag = 0; int arp_count = 0 ; int ip_count = 0 ; int broadcast_count = 0 ; int icmp_count=0; int tcp_count=0; int dns_count=0; int pop_count=0; int smtp_count=0; int imap_count=0; int itemp; int main(int argc, char **argv) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
int cnt, op, i, done = 0; bpf_u_int32 localnet, netmask; char *cp, *cmdbuf, *device; struct bpf_program fcode; void (*oldhandler)(int); u_char *pcap_userdata; char ebuf[PCAP_ERRBUF_SIZE]; cnt = -1; device = NULL; if ((cp = strrchr(argv[0], '/')) != NULL) program_name = cp + 1; else program_name = argv[0]; opterr = 0; while ((i = getopt(argc, argv, "pa")) != -1) { switch (i) { case 'p': pflag = 1; break; case 'a': aflag = 1; break; case '?': default: done = 1; break; } if (done) break; } if (argc > (optind)) cmdbuf = copy_argv(&argv[optind]); else cmdbuf = ""; if (device == NULL) { device = pcap_lookupdev(ebuf); if (device == NULL) error("%s", ebuf); } pd = pcap_open_live(device, snaplen, 1, 1000, ebuf); if (pd == NULL) error("%s", ebuf); i = pcap_snapshot(pd); if (snaplen < i) { warning("snaplen raised from %d to %d", snaplen, i); snaplen = i; } localnet = 0; netmask = 0; warning("%s", ebuf); } /* * Let user own process after socket has been opened. */ setuid(getuid());
Background image of page 2
error("%s", pcap_geterr(pd)); (void)setsignal(SIGTERM, program_ending); (void)setsignal(SIGINT, program_ending); /* Cooperate with nohup(1) */ if ((oldhandler = setsignal(SIGHUP, program_ending)) != SIG_DFL) (void)setsignal(SIGHUP, oldhandler); error("%s", pcap_geterr(pd));
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 11

netdump - #define RETSIGTYPE void #include...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online