mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-07-23 04:35:48 +08:00
ARP(8): Port to RTEMS
This commit is contained in:
parent
246b61e977
commit
64c663c0d1
@ -1,5 +1,9 @@
|
||||
#include <machine/rtems-bsd-user-space.h>
|
||||
|
||||
#ifdef __rtems__
|
||||
#include "rtems-bsd-arp-namespace.h"
|
||||
#endif /* __rtems__ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1984, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
@ -51,6 +55,12 @@ __FBSDID("$FreeBSD$");
|
||||
*/
|
||||
|
||||
|
||||
#ifdef __rtems__
|
||||
#define __need_getopt_newlib
|
||||
#include <getopt.h>
|
||||
#include <machine/rtems-bsd-program.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
#endif /* __rtems__ */
|
||||
#include <rtems/bsd/sys/param.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/socket.h>
|
||||
@ -81,6 +91,13 @@ __FBSDID("$FreeBSD$");
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#ifdef __rtems__
|
||||
#include "rtems-bsd-arp-arp-data.h"
|
||||
static struct timespec tp;
|
||||
static int seq;
|
||||
static int s = -1;
|
||||
static pid_t pid;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
typedef void (action_fn)(struct sockaddr_dl *sdl,
|
||||
struct sockaddr_in *s_in, struct rt_msghdr *rtm);
|
||||
@ -106,7 +123,7 @@ static char *rifname;
|
||||
static time_t expire_time;
|
||||
static int flags, doing_proxy;
|
||||
|
||||
struct if_nameindex *ifnameindex;
|
||||
static struct if_nameindex *ifnameindex;
|
||||
|
||||
/* which function we're supposed to do */
|
||||
#define F_GET 1
|
||||
@ -117,12 +134,44 @@ struct if_nameindex *ifnameindex;
|
||||
|
||||
#define SETFUNC(f) { if (func) usage(); func = (f); }
|
||||
|
||||
#ifdef __rtems__
|
||||
static int main(int argc, char *argv[]);
|
||||
|
||||
RTEMS_LINKER_RWSET(bsd_prog_arp, char);
|
||||
|
||||
int
|
||||
rtems_bsd_command_arp(int argc, char *argv[])
|
||||
{
|
||||
int exit_code;
|
||||
void *data_begin;
|
||||
size_t data_size;
|
||||
|
||||
data_begin = RTEMS_LINKER_SET_BEGIN(bsd_prog_arp);
|
||||
data_size = RTEMS_LINKER_SET_SIZE(bsd_prog_arp);
|
||||
|
||||
rtems_bsd_program_lock();
|
||||
exit_code = rtems_bsd_program_call_main_with_data_restore("arp",
|
||||
main, argc, argv, data_begin, data_size);
|
||||
rtems_bsd_program_unlock();
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
#endif /* __rtems__ */
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int ch, func = 0;
|
||||
int rtn = 0;
|
||||
int aflag = 0; /* do it for all entries */
|
||||
#ifdef __rtems__
|
||||
struct getopt_data getopt_data;
|
||||
memset(&getopt_data, 0, sizeof(getopt_data));
|
||||
#define optind getopt_data.optind
|
||||
#define optarg getopt_data.optarg
|
||||
#define opterr getopt_data.opterr
|
||||
#define optopt getopt_data.optopt
|
||||
#define getopt(argc, argv, opt) getopt_r(argc, argv, "+" opt, &getopt_data)
|
||||
#endif /* __rtems__ */
|
||||
|
||||
while ((ch = getopt(argc, argv, "andfsSi:")) != -1)
|
||||
switch(ch) {
|
||||
@ -619,7 +668,9 @@ print_entry(struct sockaddr_dl *sdl,
|
||||
if (rtm->rtm_rmx.rmx_expire == 0)
|
||||
printf(" permanent");
|
||||
else {
|
||||
#ifndef __rtems__
|
||||
static struct timespec tp;
|
||||
#endif /* __rtems__ */
|
||||
if (tp.tv_sec == 0)
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
if ((expire_time = rtm->rtm_rmx.rmx_expire - tp.tv_sec) > 0)
|
||||
@ -703,12 +754,16 @@ usage(void)
|
||||
static struct rt_msghdr *
|
||||
rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl *sdl)
|
||||
{
|
||||
#ifndef __rtems__
|
||||
static int seq;
|
||||
#endif /* __rtems__ */
|
||||
int rlen;
|
||||
int l;
|
||||
struct sockaddr_in so_mask, *som = &so_mask;
|
||||
#ifndef __rtems__
|
||||
static int s = -1;
|
||||
static pid_t pid;
|
||||
#endif /* __rtems__ */
|
||||
|
||||
static struct {
|
||||
struct rt_msghdr m_rtm;
|
||||
|
14
freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h
Normal file
14
freebsd/usr.sbin/arp/rtems-bsd-arp-arp-data.h
Normal file
@ -0,0 +1,14 @@
|
||||
/* generated by userspace-header-gen.py */
|
||||
#include <rtems/linkersets.h>
|
||||
#include "rtems-bsd-arp-data.h"
|
||||
/* arp.c */
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int nflag);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static char *rifname);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static time_t expire_time);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int flags);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int doing_proxy);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static struct if_nameindex *ifnameindex);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static struct timespec tp);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int seq);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static int s);
|
||||
RTEMS_LINKER_RWSET_CONTENT(bsd_prog_arp, static pid_t pid);
|
3
freebsd/usr.sbin/arp/rtems-bsd-arp-data.h
Normal file
3
freebsd/usr.sbin/arp/rtems-bsd-arp-data.h
Normal file
@ -0,0 +1,3 @@
|
||||
/* generated by userspace-header-gen.py */
|
||||
#include <rtems/linkersets.h>
|
||||
/* arp.c */
|
2
freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h
Normal file
2
freebsd/usr.sbin/arp/rtems-bsd-arp-namespace.h
Normal file
@ -0,0 +1,2 @@
|
||||
/* generated by userspace-header-gen.py */
|
||||
/* arp.c */
|
@ -70,6 +70,7 @@ def rtems(mm):
|
||||
'rtems/rtems-bsd-rc-conf-pf.c',
|
||||
'rtems/rtems-bsd-rc-conf.c',
|
||||
'rtems/rtems-bsd-shell.c',
|
||||
'rtems/rtems-bsd-shell-arp.c',
|
||||
'rtems/rtems-bsd-shell-ifconfig.c',
|
||||
'rtems/rtems-bsd-shell-netstat.c',
|
||||
'rtems/rtems-bsd-shell-pfctl.c',
|
||||
@ -2219,6 +2220,7 @@ def user_space(mm):
|
||||
'usr.bin/netstat/sctp.c',
|
||||
'usr.bin/netstat/unix.c',
|
||||
'usr.bin/vmstat/vmstat.c',
|
||||
'usr.sbin/arp/arp.c',
|
||||
],
|
||||
mm.generator['source'](['-DINET6', '-DINET'])
|
||||
)
|
||||
|
@ -447,7 +447,8 @@ def build(bld):
|
||||
'freebsd/usr.bin/netstat/route.c',
|
||||
'freebsd/usr.bin/netstat/sctp.c',
|
||||
'freebsd/usr.bin/netstat/unix.c',
|
||||
'freebsd/usr.bin/vmstat/vmstat.c']
|
||||
'freebsd/usr.bin/vmstat/vmstat.c',
|
||||
'freebsd/usr.sbin/arp/arp.c']
|
||||
bld.objects(target = "objs01",
|
||||
features = "c",
|
||||
cflags = cflags,
|
||||
@ -1099,6 +1100,7 @@ def build(bld):
|
||||
'rtemsbsd/rtems/rtems-bsd-rc-conf-net.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-rc-conf-pf.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-rc-conf.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-arp.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-dhcpcd.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-ifconfig.c',
|
||||
'rtemsbsd/rtems/rtems-bsd-shell-netstat.c',
|
||||
|
@ -46,6 +46,8 @@
|
||||
|
||||
__BEGIN_DECLS
|
||||
|
||||
int rtems_bsd_command_arp(int argc, char **argv);
|
||||
|
||||
int rtems_bsd_command_ifconfig(int argc, char **argv);
|
||||
|
||||
int rtems_bsd_command_netstat(int argc, char **argv);
|
||||
|
@ -22,6 +22,8 @@
|
||||
extern "C" {
|
||||
#endif /* __cplusplus */
|
||||
|
||||
extern rtems_shell_cmd_t rtems_shell_ARP_Command;
|
||||
|
||||
extern rtems_shell_cmd_t rtems_shell_BSD_Command;
|
||||
|
||||
extern rtems_shell_cmd_t rtems_shell_PFCTL_Command;
|
||||
|
40
rtemsbsd/rtems/rtems-bsd-shell-arp.c
Normal file
40
rtemsbsd/rtems/rtems-bsd-shell-arp.c
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
|
||||
*
|
||||
* embedded brains GmbH
|
||||
* Dornierstr. 4
|
||||
* 82178 Puchheim
|
||||
* Germany
|
||||
* <rtems@embedded-brains.de>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON 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 ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <rtems/netcmds-config.h>
|
||||
#include <machine/rtems-bsd-commands.h>
|
||||
|
||||
rtems_shell_cmd_t rtems_shell_ARP_Command = {
|
||||
.name = "arp",
|
||||
.usage = "arp [args]",
|
||||
.topic = "net",
|
||||
.command = rtems_bsd_command_arp
|
||||
};
|
@ -357,6 +357,7 @@ Init(rtems_task_argument arg)
|
||||
|
||||
#define CONFIGURE_SHELL_USER_COMMANDS \
|
||||
&bsp_interrupt_shell_command, \
|
||||
&rtems_shell_ARP_Command, \
|
||||
&rtems_shell_BSD_Command, \
|
||||
&rtems_shell_HOSTNAME_Command, \
|
||||
&rtems_shell_PING_Command, \
|
||||
|
@ -199,6 +199,7 @@ early_initialization(void)
|
||||
|
||||
#define CONFIGURE_SHELL_USER_COMMANDS \
|
||||
&bsp_interrupt_shell_command, \
|
||||
&rtems_shell_ARP_Command, \
|
||||
&rtems_shell_BSD_Command, \
|
||||
&rtems_shell_HOSTNAME_Command, \
|
||||
&rtems_shell_PING_Command, \
|
||||
|
@ -10,6 +10,7 @@
|
||||
#define CONFIGURE_SHELL_COMMANDS_ALL
|
||||
|
||||
#define CONFIGURE_SHELL_USER_COMMANDS \
|
||||
&rtems_shell_ARP_Command, \
|
||||
&rtems_shell_SYSCTL_Command, \
|
||||
&rtems_shell_HOSTNAME_Command, \
|
||||
&rtems_shell_PING_Command, \
|
||||
|
Loading…
x
Reference in New Issue
Block a user