📄 arp.c
字号:
/* This file is part of sniffer, a packet capture utility and network moniter The author can be contacted at <mistral@stev.org> the lastest version is avilable from http://stev.org This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "config.h"#ifdef ARP#include <stdio.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include <errno.h>#include <pthread.h>#include <fcntl.h>#include <sys/stat.h>#include "sniff.h"#include "list.h"#include "locks.h"#include "in_ntoa.h"#include "lookup.h"#include "arp.h"#include "arp_48bit.h"#include "stat.h"#include "log.h"FILE *arp_log;pthread_mutex_t arp_mutex = PTHREAD_MUTEX_INITIALIZER;unsigned long int inet_addr(const char *cp);struct gen_stat arp_stat;int arp_handle(struct sniff_pkt *pkt, void *data) { struct arphdr *in; void *pointer; int proto; pkt->func = "arp_handle"; if (pkt->dataleft < sizeof(struct arphdr)) return ERR_DATA; arp_stat.packets++; arp_stat.bytes += pkt->dataleft; in = (struct arphdr *) data; pointer = data + sizeof(struct arphdr); pkt->dataleft -= sizeof(struct arphdr); proto = ntohs(in->ar_hrd); switch(proto) {#ifdef ARP_48BIT case ARPHRD_ETHER: return arp_handle_48bit(pkt, in, pointer); case ARPHRD_IEEE802: return arp_handle_48bit(pkt, in, pointer);#endif /* do we want ARP_48BIT ? */ default: #ifdef DEBUG_ARP log_error("Arp_handle: unsupported protcol\n"); #endif arp_stat.dropped++; return ERR_SUPP; break; } return -2;}/******************************************** arp_tidy() ***********************************************************/int arp_tidy() { if (arp_log) fflush(arp_log); return 0;}/*************************************** let set up all the arp stuff***************************************/int arp_init() { /* open up a file for loggin */#ifdef DEBUG arp_log = fopen("output/arp", "w");#else arp_log = fopen("output/arp", "w+");#endif if (!arp_log) { log_errno("fopen"); return -1; } SLOCK(&arp_mutex); init_stat(&arp_stat, "ARP");#ifdef ARP_48BIT if (arp_48bit_init() < 0) { SUNLOCK(&arp_mutex); return -2; }#endif SUNLOCK(&arp_mutex); return 0;}#endif /* do we want arp ? */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -