/** arping/src/arping.c
*
* arping
*
* By Thomas Habets <thomas@habets.pp.se>
*
* ARP 'ping' utility
*
* Broadcasts a who-has ARP packet on the network and prints answers.
* *VERY* useful when you are trying to pick an unused IP for a net that
* you don't yet have routing to. Then again, if you have no idea what I'm
* talking about then you prolly don't need it.
*
* Also finds out IP of specified MAC
*
*/
/*
* Copyright (C) 2000-2010 Thomas Habets <thomas@habets.pp.se>
*
* This library 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 library 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#if HAVE_LIBNET_H
#include <libnet.h>
#endif
#if HAVE_WIN32_LIBNET_H
#include <win32/libnet.h>
#endif
#include <pcap.h>
#if HAVE_NET_BPF_H
#include <net/bpf.h>
#endif
#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif
#ifndef IP_ALEN
#define IP_ALEN 4
#endif
#ifndef WIN32
#define WIN32 0
#endif
/**
* OS-specific interface finding using routing table. See findif_*.c
*/
const char *
arping_lookupdev(const char *ifname,
uint32_t srcip,
uint32_t dstip,
char *ebuf);
static const char *version = VERSION; /* from autoconf */
static libnet_t *libnet = 0;
static struct timeval lastpacketsent;
uint32_t srcip, dstip;
static int beep = 0;
static int reverse_beep = 0;
static int verbose = 0;
static int alsototal = 0;
/*static int pingmac = 0; */
static int finddup = 0;
static int dupfound = 0;
static unsigned int numsent = 0;
static unsigned int numrecvd = 0;
static unsigned int numdots = 0;
static int addr_must_be_same = 0;
/* RAWRAW is RAW|RRAW */
static enum { NORMAL, QUIET, RAW, RRAW, RAWRAW, DOT } display = NORMAL;
static char *target = "huh? bug in arping?";
static uint8_t ethnull[ETH_ALEN];
static uint8_t ethxmas[ETH_ALEN];
static char srcmac[ETH_ALEN];
static char dstmac[ETH_ALEN];
static char lastreplymac[ETH_ALEN];
/* doesn't need to be volatile */
volatile int time_to_die = 0;
/**
*
*/
static void
count_missing_dots()
{
while (numsent > numdots) {
putchar('.');
numdots++;
}
}
/**
*
*/
void
do_libnet_init(const char *ifname)
{
char ebuf[LIBNET_ERRBUF_SIZE];
if (verbose > 1) {
printf("libnet_init(%s)\n", ifname?ifname:"<null>");
}
if (libnet) {
/* prolly going to switch interface from temp to real */
libnet_destroy(libnet);
libnet = 0;
}
if (getuid() && geteuid()) {
fprintf(stderr, "arping: must run as root\n");
exit(1);
}
if (!(libnet = libnet_init(LIBNET_LINK,
(char*)ifname,
ebuf))) {
fprintf(stderr, "arping: libnet_init(): %s\n", ebuf);
exit(1);
}
}
/**
*
*/
const char *
arping_lookupdev_default(const char *ifname,
uint32_t srcip, uint32_t dstip,
char *ebuf)
{
#if WIN32
WCHAR buf[LIBNET_ERRBUF_SIZE + PCAP_ERRBUF_SIZE];
WCHAR* ret = (WCHAR*)pcap_lookupdev((char*)buf);
if (ret != NULL) {
wcstombs(ebuf, ret, LIBNET_ERRBUF_SIZE + PCAP_ERRBUF_SIZE);
return ebuf;
}
return NULL;
#else
return pcap_lookupdev(ebuf);
#endif
}
#if WIN32
static BOOL WINAPI arping_console_ctrl_handler(DWORD dwCtrlType)
{
if(verbose) {
printf("arping_console_ctrl_handler( %d )\n", (int)dwCtrlType);
}
time_to_die = 1;
#if 0
/* if SetConsoleCtrlHandler() does what I think, this isn't needed */
if (display == NORMAL) {
printf("\n--- %s statistics ---\n"
"%d packets transmitted, %d packets received, %3.0f%% "
"unanswered\n",target,numsent,numrecvd,
100.0 - 100.0 * (float)(numrecvd)/(float)numsent);
}
#endif
return TRUE;
}
#endif
/**
*
*/
static void sigint(int i)
{
time_to_die = 1;
}
/**
*
*/
static void
extended_usage()
{
printf("\nOptions:\n");
printf("\n"
" -0 Use this option to ping with source IP address 0.0.0.0. Use this\n"
" when you haven't configured your interface yet. Note that this\n"
" may get the MAC-ping unanswered. This is an alias for -S\n"
" 0.0.0.0.\n"
" -a Audiable ping.\n"
" -A Only count addresses matching requested address (This *WILL*\n"
" break most things you do. Only useful if you are arpinging many\n"
" hosts at once. See arping-scan-net.sh for an example).\n"
" -b Like -0 but source broadcast source address (255.255.255.255).\n"
" Note that this may get the arping unanswered since it's not nor-\n"
" mal behavior for a host.\n"
" -B Use instead of host if you want to address 255.255.255.255.\n"
" -c count\n"
" Only send count requests.\n"
" -d Find duplicate replies. Exit with 1 if there are "
"answers from\n"
" two different MAC addresses.\n"
" -D Display answers as dots and missing packets as exclamation points.\n"
" -e Like -a but beep when there is no reply.\n"
" -F Don't try to be smart about the interface name. (even if this\n"
" switch is not given, -i overrides smartness)\n"
" -h Displays a help message and exits.\n"
" -i interface\n"
" Use the specified interface.\n"
" -q Does not display messages, except error messages.\n"
" -r Raw output: only the MAC/IP address is displayed for each reply.\n"
" -R Raw output: Like -r but shows \"the other one\", can be combined\n"
" with -r.\n"
" -s MAC Set source MAC address. You may need to use -p with this.\n"
" -S IP Like -b and -0 but with set source address. Note that this may\n"
" get the arping unanswered if the target does not have routing to\n"
" the IP. If you don't own the IP you are using, you may need to\n"
" turn on promiscious mode on the interface (with -p). With this\n"
" switch you can find out what IP-address a host has without tak-\n"
" ing an IP-address yourself.\n"
" -t MAC Set target MAC address to use when pinging IP address.\n"
" -T IP Use -T as target address when pinging MACs that won't respond to\n"
" a broadcast ping but perhaps to a directed broadcast.\n"
" Example:\n"
" To check the address of MAC-A, use knowledge of MAC-B and IP-B.\n"
" $ arping -S <IP-B> -s <MAC-B> -p <MAC-A>\n"
" -p Turn on promiscious mode on interface, use this if you don't\n"
" \"own\" the MAC address you are using.\n"
" -u Show index=received/sent instead of just index=received when\n"
" pinging MACs.\n"
" -v
没有合适的资源?快使用搜索试试~ 我知道了~
arping-2.09.tar.
需积分: 50 15 下载量 149 浏览量
2013-10-18
22:56:24
上传
评论
收藏 130KB GZ 举报
温馨提示
共40个文件
values:9个
c:4个
in:4个
arping-2.09.tar.
资源推荐
资源详情
资源评论
收起资源包目录
arping-2.09.tar.gz (40个子文件)
arping-2.09
missing 11KB
.gitignore 87B
aclocal.m4 32KB
INSTALL 1KB
config.h.in 5KB
LICENSE 18KB
configure 201KB
install-sh 13KB
Makefile.in 19KB
depcomp 17KB
src
findif_bsd.c 2KB
arping.c 33KB
arping.h 369B
Makefile.in 13KB
findif_linux.c 2KB
Makefile.am 144B
findif_other.c 1KB
.be
version 25B
settings 15B
bugs
9153e3b3-283a-47f6-8726-c90993bd7829
values 222B
23fd7946-a5b5-4b48-99eb-65114e6769f7
values 166B
comments
0cd5d24d-193e-4881-9904-d9913471d753
values 110B
body 74B
e4ac34f5-f8b8-4b59-abe3-c283e341f23e
values 170B
aef2b321-4dc7-4f27-84b3-625581c5db69
values 208B
63dc1561-56ee-4250-b8cd-d938c6854073
values 199B
78b319c2-b2f1-4e75-b8d4-1a4e836ac1ed
values 230B
c827507c-539b-4d85-a382-1d55a6b81ee2
values 195B
2a69f78d-8245-41f1-bb4e-49b40fe0d850
values 198B
configure.ac 2KB
config.guess 44KB
README 11KB
config.sub 33KB
extra
arping-scan-net.sh 2KB
doc
arping.8 5KB
arping.yodl 5KB
Makefile.in 10KB
Makefile.am 133B
Makefile.am.common 75B
Makefile.am 278B
共 40 条
- 1
资源评论
战神2
- 粉丝: 3
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功