feature: add ndp tool for ipv6 neighbor

This commit is contained in:
chopin 2020-10-18 15:57:04 +08:00
parent 83438cffc0
commit ebf5cedb54
4 changed files with 1563 additions and 1 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS=compat libutil libmemstat libxo libnetgraph sysctl ifconfig route top netstat ngctl ipfw arp traffic knictl
SUBDIRS=compat libutil libmemstat libxo libnetgraph sysctl ifconfig route top netstat ngctl ipfw arp traffic knictl ndp
PREFIX_BIN=/usr/local/bin
all:
@ -12,6 +12,7 @@ install:
cp -rf sbin/ ${PREFIX_BIN}/f-stack
ln -sf ${PREFIX_BIN}/f-stack/arp ${PREFIX_BIN}/ff_arp
ln -sf ${PREFIX_BIN}/f-stack/ndp ${PREFIX_BIN}/ff_ndp
ln -sf ${PREFIX_BIN}/f-stack/ifconfig ${PREFIX_BIN}/ff_ifconfig
ln -sf ${PREFIX_BIN}/f-stack/ipfw ${PREFIX_BIN}/ff_ipfw
ln -sf ${PREFIX_BIN}/f-stack/netstat ${PREFIX_BIN}/ff_netstat

View File

@ -0,0 +1,54 @@
#include <sys/cdefs.h>
#ifndef FSTACK
__FBSDID("$FreeBSD$");
#include "namespace.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <ifaddrs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#ifndef FSTACK
#include "un-namespace.h"
#endif
char *
if_indextoname(unsigned int ifindex, char *ifname)
{
struct ifaddrs *ifaddrs, *ifa;
int error = 0;
if (ifindex == 0) {
errno = ENXIO;
return(NULL);
}
if (getifaddrs(&ifaddrs) < 0)
return(NULL); /* getifaddrs properly set errno */
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK &&
ifindex == LLINDEX((struct sockaddr_dl*)ifa->ifa_addr))
break;
}
if (ifa == NULL) {
error = ENXIO;
ifname = NULL;
}
else
strncpy(ifname, ifa->ifa_name, IFNAMSIZ);
freeifaddrs(ifaddrs);
errno = error;
return(ifname);
}

22
tools/ndp/Makefile Normal file
View File

@ -0,0 +1,22 @@
# Copyright (c) 1996 WIDE Project. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modifications, are permitted provided that the above copyright notice
# and this paragraph are duplicated in all such forms and that any
# documentation, advertising materials, and other materials related to
# such distribution and use acknowledge that the software was developed
# by the WIDE Project, Japan. The name of the Project may not be used to
# endorse or promote products derived from this software without
# specific prior written permission. THIS SOFTWARE IS PROVIDED ``AS IS''
# AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
# LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE.
# $FreeBSD: releng/11.0/usr.sbin/ndp/Makefile 201390 2010-01-02 11:07:44Z ed $
TOPDIR?=${CURDIR}/../..
PROG=ndp
include ${TOPDIR}/tools/prog.mk

1485
tools/ndp/ndp.c Normal file

File diff suppressed because it is too large Load Diff