/*
* Copyright (c) 2001-2002 Packet Design, LLC.
* All rights reserved.
*
* Subject to the following obligations and disclaimer of warranty,
* use and redistribution of this software, in source or object code
* forms, with or without modifications are expressly permitted by
* Packet Design; provided, however, that:
*
* (i) Any and all reproductions of the source or object code
* must include the copyright notice above and the following
* disclaimer of warranties; and
* (ii) No rights are granted, in any manner or form, to use
* Packet Design trademarks, including the mark "PACKET DESIGN"
* on advertising, endorsements, or otherwise except as such
* appears in the above copyright notice or in the software.
*
* THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
* REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
* THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
* OR NON-INFRINGEMENT. PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
* OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
* OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
* RELIABILITY OR OTHERWISE. IN NO EVENT SHALL PACKET DESIGN BE
* LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
* OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
* DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
* USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
* Author: Archie Cobbs <archie@freebsd.org>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <net/ethernet.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <err.h>
#include <pdel/net/if_util.h>
int
main(int ac, char **av)
{
struct ether_addr *ea;
const u_char *ether = NULL;
struct in_addr ip;
int publish = 0;
int temp = 0;
int ch;
while ((ch = getopt(ac, av, "tp")) != -1) {
switch (ch) {
case 't':
temp = 1;
break;
case 'p':
publish = 1;
break;
default:
goto usage;
}
}
ac -= optind;
av += optind;
/* set command */
if ((ac == 2 || ac == 3) && strcmp(av[0], "set") == 0) {
if (ac == 3) {
if ((ea = ether_aton(av[2])) == NULL)
goto usage;
ether = ea->octet;
}
if (!inet_aton(av[1], &ip))
goto usage;
if (if_set_arp(ip, ether, temp, publish) == -1)
err(1, "if_set_arp");
return (0);
}
/* flush command */
if (ac == 1 && strcmp(av[0], "flush") == 0) {
if (if_flush_arp() == -1)
err(1, "if_flush_arp");
return (0);
}
/* get command */
if (ac == 2 && strcmp(av[0], "get") == 0) {
struct ether_addr mac;
if (!inet_aton(av[1], &ip))
goto usage;
if (if_get_arp(ip, (u_char *)&mac) == -1)
err(1, "%s", inet_ntoa(ip));
printf("%s is at %s\n", inet_ntoa(ip), ether_ntoa(&mac));
return (0);
}
usage:
/* Unknown usage */
(void)fprintf(stderr, "Usage: arptest"
" < [-tp] set ip [ether] | flush | get ip >\n");
exit(1);
}
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>