Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Sep 2001 13:59:02 +0100 (BST)
From:      Joshua Goodall <joshua@roughtrade.net>
To:        Paul Chvostek <paul@it.ca>
Cc:        <net@freebsd.org>
Subject:   arpwh (was: Gratuitous ARP (summary))
Message-ID:  <Pine.LNX.4.33.0109021329000.20276-101000@elm.phenome.org>
In-Reply-To: <Pine.LNX.4.33.0109020130240.20276-100000@elm.phenome.org>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]

On Sun, 2 Sep 2001, I wrote:

> I think, ultimately, the only guaranteed way is to construct your own ARP
> packet and write it at the link layer. arping uses libnet for this.

... and just for a lark, I rolled a tool using libnet to fulfill my own
requirements. sharball attached. Requires the libnet port/package.

Possibly this is a useful template for people needing similiar code.

If anyone cares enough I might make it a port, but it does duplicate
functionality available in several existing ports (dsniff, arping,
others?).

J

[-- Attachment #2 --]
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	arpwh
#	arpwh/Makefile
#	arpwh/arpwh.c
#	arpwh/arpwh.8
#
echo c - arpwh
mkdir -p arpwh > /dev/null 2>&1
echo x - arpwh/Makefile
sed 's/^X//' >arpwh/Makefile << 'END-of-arpwh/Makefile'
X# $Id: Makefile,v 1.9 2001/09/02 12:44:30 joshua Exp joshua $
X
XPROG=	arpwh
XMAN=	arpwh.8
XBINDIR=	/usr/local/sbin
XMANDIR=	/usr/local/man/man
XNOOBJ=	1
X
XLIBNETDEFS!=	libnet-config --defines
XCFLAGS+=-I/usr/local/include ${LIBNETDEFS}
XLDADD+=	-lnet
XLDFLAGS+=	-L/usr/local/lib
X
X.include <bsd.prog.mk>
END-of-arpwh/Makefile
echo x - arpwh/arpwh.c
sed 's/^X//' >arpwh/arpwh.c << 'END-of-arpwh/arpwh.c'
X/*
X * Copyright (C) 2001 Joshua Goodall <joshua@roughtrade.net>
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X *
X * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X * SUCH DAMAGE.
X *
X * $Id: arpwh.c,v 1.6 2001/09/02 11:50:31 joshua Exp joshua $
X */
X
X#include <stdio.h>
X#include <libnet.h>
X
Xu_char eth_broadcast[ETHER_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
Xu_char eth_nosrc[ETHER_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
X
Xint main __P((int, char *[]));
Xvoid usage __P((void));
X
Xint
Xmain(argc, argv)
X	int argc;
X	char *argv[];
X{
X	char err_buf[LIBNET_ERRBUF_SIZE];
X	struct ether_addr *sha;
X	struct libnet_link_int *link;
X	char   *interface;
X	char   *addressz;
X	u_char *packet;
X	u_char eth_dst[ETHER_ADDR_LEN];
X	u_char eth_src[ETHER_ADDR_LEN];
X	u_long ipaddr;
X
X	if (argc != 3)
X		usage();
X
X	interface = *++argv;
X	addressz  = *++argv;
X
X	/* Build data structures. */
X
X	link = libnet_open_link_interface(interface, err_buf);
X	if (link == NULL)
X		libnet_error(LIBNET_ERR_FATAL, "%s\n", err_buf);
X
X	sha = libnet_get_hwaddr(link, interface, err_buf);
X	if (sha == NULL)
X		libnet_error(LIBNET_ERR_FATAL, "%s\n", err_buf);
X
X	if ((ipaddr = libnet_name_resolve(addressz, 1)) == -1)
X		libnet_error(LIBNET_ERR_FATAL, "libnet_name_resolve()\n");
X	
X	memcpy(eth_dst, eth_broadcast, ETHER_ADDR_LEN);
X	memcpy(eth_src, sha->ether_addr_octet, ETHER_ADDR_LEN);
X
X	/* Build packet. */
X
X	if (libnet_init_packet(LIBNET_ETH_H + LIBNET_ARP_H, &packet) == -1)
X		libnet_error(LIBNET_ERR_FATAL, "libnet_init_packet()");
X
X	if (libnet_build_ethernet(eth_dst, eth_src, ETHERTYPE_ARP, NULL, 0,
X	    packet) == -1)
X		libnet_error(LIBNET_ERR_FATAL, "libnet_build_ethernet()\n");
X
X	if (libnet_build_arp(ARPHRD_ETHER, ETHERTYPE_IP, ETHER_ADDR_LEN,
X	    4, ARPOP_REQUEST, sha->ether_addr_octet, (u_char *)&ipaddr,
X	    /* sha->ether_addr_octet, (u_char *)&ipaddr, NULL, 0, */
X	    eth_nosrc, (u_char *)&ipaddr, NULL, 0,
X	    packet + LIBNET_ETH_H) == -1)
X		libnet_error(LIBNET_ERR_FATAL, "libnet_build_arp()\n");
X
X	/* Write packet. */
X
X	if (libnet_write_link_layer(link, interface, packet,
X	    LIBNET_ETH_H + LIBNET_ARP_H) == -1)
X		libnet_error(LIBNET_ERR_FATAL, "libnet_write_link_layer()\n");
X
X	exit(0);
X}
X
Xvoid
Xusage()
X{
X	(void)fprintf(stderr, "usage: arpwh interface address\n");
X	exit(1);
X}
END-of-arpwh/arpwh.c
echo x - arpwh/arpwh.8
sed 's/^X//' >arpwh/arpwh.8 << 'END-of-arpwh/arpwh.8'
X.\" Copyright (C) 2001 Joshua Goodall <joshua@roughtrade.net>
X.\" All rights reserved.
X.\" 
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.\" $Id: arpwh.8,v 1.4 2001/09/02 12:44:30 joshua Exp joshua $
X.\"
X.Dd September 2, 2001
X.Dt ARPWH 8
X.Os arpwh 1.2
X.Sh NAME
X.Nm arpwh
X.Nd send arp who-has
X.Sh SYNOPSIS
X.Nm
X.Ar interface host
X.Sh DESCRIPTION
XThe
X.Nm
Xutility writes a Gratuitous ARP who-has packet out of the
X.Ar interface
Xwith both the request and tell IP addresses set to the given
X.Ar host .
X.Sh DIAGNOSTICS
XThe
X.Nm
Xutility exits 0 on success, and >0 if an error occurs.
X.Sh SEE ALSO
X.Xr arp 8 ,
X.Xr ifconfig 8
X.Sh AUTHOR 
X.An Joshua Goodall Aq joshua@roughtrade.net
END-of-arpwh/arpwh.8
exit


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.33.0109021329000.20276-101000>