summaryrefslogtreecommitdiffstats
path: root/c/src/libnetworking/rtems
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2002-05-29 17:00:30 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2002-05-29 17:00:30 +0000
commit7020377e8f2214d2adbda252c52ecd54e15d7e97 (patch)
tree0d1aff815863220cb9ad20f070a110f0c17aeedd /c/src/libnetworking/rtems
parent2001-05-29 Joel Sherrill <joel@OARcorp.com> (diff)
downloadrtems-7020377e8f2214d2adbda252c52ecd54e15d7e97.tar.bz2
2002-05-29 Ralf Corsepius <corsepiu@faw.uni-ulm.de>
Move networking libraries to c/src/exec/libnetworking * configure.ac: Reflect Moval. * Makefile.am: Reflect Moval. * wrapup/Makefile.am: Reflect Moval.
Diffstat (limited to 'c/src/libnetworking/rtems')
-rw-r--r--c/src/libnetworking/rtems/.cvsignore2
-rw-r--r--c/src/libnetworking/rtems/Makefile.am53
-rw-r--r--c/src/libnetworking/rtems/issetugid.c11
-rw-r--r--c/src/libnetworking/rtems/mkrootfs.c347
-rw-r--r--c/src/libnetworking/rtems/mkrootfs.h66
-rw-r--r--c/src/libnetworking/rtems/rtems_bootp.c31
-rw-r--r--c/src/libnetworking/rtems/rtems_bsdnet.h184
-rw-r--r--c/src/libnetworking/rtems/rtems_bsdnet_internal.h197
-rw-r--r--c/src/libnetworking/rtems/rtems_glue.c1202
-rw-r--r--c/src/libnetworking/rtems/rtems_select.c174
-rw-r--r--c/src/libnetworking/rtems/rtems_showicmpstat.c60
-rw-r--r--c/src/libnetworking/rtems/rtems_showifstat.c112
-rw-r--r--c/src/libnetworking/rtems/rtems_showipstat.c59
-rw-r--r--c/src/libnetworking/rtems/rtems_showmbuf.c65
-rw-r--r--c/src/libnetworking/rtems/rtems_showroute.c236
-rw-r--r--c/src/libnetworking/rtems/rtems_showtcpstat.c102
-rw-r--r--c/src/libnetworking/rtems/rtems_showudpstat.c48
-rw-r--r--c/src/libnetworking/rtems/rtems_syscall.c763
-rw-r--r--c/src/libnetworking/rtems/sghostname.c49
-rw-r--r--c/src/libnetworking/rtems/tftp.h43
20 files changed, 0 insertions, 3804 deletions
diff --git a/c/src/libnetworking/rtems/.cvsignore b/c/src/libnetworking/rtems/.cvsignore
deleted file mode 100644
index 282522db03..0000000000
--- a/c/src/libnetworking/rtems/.cvsignore
+++ /dev/null
@@ -1,2 +0,0 @@
-Makefile
-Makefile.in
diff --git a/c/src/libnetworking/rtems/Makefile.am b/c/src/libnetworking/rtems/Makefile.am
deleted file mode 100644
index 131d5bd14f..0000000000
--- a/c/src/libnetworking/rtems/Makefile.am
+++ /dev/null
@@ -1,53 +0,0 @@
-##
-## $Id$
-##
-
-include_rtemsdir = $(includedir)/rtems
-
-LIBNAME = lib.a
-LIB = $(ARCH)/$(LIBNAME)
-
-C_FILES = sghostname.c issetugid.c rtems_glue.c rtems_syscall.c \
- rtems_bootp.c rtems_showmbuf.c rtems_showroute.c rtems_showifstat.c \
- rtems_showipstat.c rtems_showicmpstat.c rtems_showtcpstat.c \
- rtems_showudpstat.c rtems_select.c mkrootfs.c
-C_O_FILES = $(C_FILES:%.c=$(ARCH)/%.o)
-
-OBJS = $(C_O_FILES)
-
-include_rtems_HEADERS = rtems_bsdnet.h rtems_bsdnet_internal.h tftp.h \
- mkrootfs.h
-
-PREINSTALL_FILES = $(PROJECT_INCLUDE)/rtems \
- $(include_rtems_HEADERS:%=$(PROJECT_INCLUDE)/rtems/%)
-
-$(PROJECT_INCLUDE)/rtems:
- @$(mkinstalldirs) $@
-
-$(PROJECT_INCLUDE)/rtems/%.h: %.h
- $(INSTALL_DATA) $< $@
-
-include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
-include $(top_srcdir)/../../../automake/compile.am
-include $(top_srcdir)/../../../automake/lib.am
-
-#
-# Add local stuff here using +=
-#
-
-AM_CPPFLAGS += -D_COMPILING_BSD_KERNEL_ -DKERNEL -DINET -DNFS -DDIAGNOSTIC \
- -DBOOTP_COMPAT
-
-$(LIB): $(OBJS)
- $(make-library)
-
-all-local: $(PREINSTALL_FILES) $(ARCH) $(OBJS) $(LIB)
-
-.PRECIOUS: $(LIB)
-
-EXTRA_DIST = issetugid.c rtems_bootp.c rtems_glue.c rtems_select.c \
- rtems_showicmpstat.c rtems_showifstat.c rtems_showipstat.c \
- rtems_showmbuf.c rtems_showroute.c rtems_showtcpstat.c \
- rtems_showudpstat.c rtems_syscall.c sghostname.c
-
-include $(top_srcdir)/../../../automake/local.am
diff --git a/c/src/libnetworking/rtems/issetugid.c b/c/src/libnetworking/rtems/issetugid.c
deleted file mode 100644
index 3baf0ec88b..0000000000
--- a/c/src/libnetworking/rtems/issetugid.c
+++ /dev/null
@@ -1,11 +0,0 @@
-/*
- * Dummy version of BSD routine
- *
- * $Id$
- */
-
-int
-issetugid (void)
-{
- return 0;
-}
diff --git a/c/src/libnetworking/rtems/mkrootfs.c b/c/src/libnetworking/rtems/mkrootfs.c
deleted file mode 100644
index eff49ff9a0..0000000000
--- a/c/src/libnetworking/rtems/mkrootfs.c
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- ------------------------------------------------------------------------
- $Id$
- ------------------------------------------------------------------------
-
- Copyright Cybertec Pty Ltd, 2000
- All rights reserved Cybertec Pty Ltd, 2000
-
- COPYRIGHT (c) 1989-1998.
- On-Line Applications Research Corporation (OAR).
-
- The license and distribution terms for this file may be
- found in the file LICENSE in this distribution or at
-
- http://www.OARcorp.com/rtems/license.html.
-
- This software with is provided ``as is'' and with NO WARRANTY.
-
- ------------------------------------------------------------------------
-
- Set of helpers when creating a root file system. The root filesystem
- in RTEMS is the In Memory Filesystem (IMFS). We could copy an exiting
- filesystem to here, how-ever a number of files can have target
- specific initialisation info which we need to write.
-
- */
-
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <rtems/mkrootfs.h>
-
-/*
- * A table a list of names and their modes.
- */
-
-typedef struct rtems_rootfs_dir_table
-{
- const char *name;
- int mode;
-} rtems_rootfs_dir_table;
-
-/*
- * Table of directorys to make.
- */
-
-static const rtems_rootfs_dir_table default_directories[] =
-{
- { "/bin", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH },
- { "/etc", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH },
- { "/dev", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH },
- { "/usr/bin", S_IFDIR | S_IRWXU | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH }
-};
-
-#define MKFILE_MODE (S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH)
-#define MKDIR_MODE (S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
-
-/*
- * Build a path. Taken from the BSD `mkdir' command.
- */
-
-int
-rtems_rootfs_mkdir (const char *path_orig, mode_t omode)
-{
- struct stat sb;
- mode_t numask, oumask;
- int first, last, retval;
- char path[128];
- char *p = path;
-
- if (strlen (path_orig) >= sizeof path)
- {
- printf ("root fs: mkdir path too long `%s'\n", path);
- return -1;
- }
-
- strcpy (path, path_orig);
- oumask = 0;
- retval = 0;
- if (p[0] == '/') /* Skip leading '/'. */
- ++p;
- for (first = 1, last = 0; !last ; ++p)
- {
- if (p[0] == '\0')
- last = 1;
- else if (p[0] != '/')
- continue;
- *p = '\0';
- if (p[1] == '\0')
- last = 1;
- if (first)
- {
- /*
- * POSIX 1003.2:
- * For each dir operand that does not name an existing
- * directory, effects equivalent to those cased by the
- * following command shall occcur:
- *
- * mkdir -p -m $(umask -S),u+wx $(dirname dir) &&
- * mkdir [-m mode] dir
- *
- * We change the user's umask and then restore it,
- * instead of doing chmod's.
- */
- oumask = umask(0);
- numask = oumask & ~(S_IWUSR | S_IXUSR);
- umask(numask);
- first = 0;
- }
- if (last)
- umask(oumask);
- if (stat(path, &sb))
- {
- if (errno != ENOENT)
- {
- printf ("root fs: error stat'ing path `%s', %s\n",
- path, strerror (errno));
- retval = 1;
- break;
- }
- if (mkdir(path, last ? omode : S_IRWXU | S_IRWXG | S_IRWXO) < 0)
- {
- printf ("root fs: error building path `%s', %s\n",
- path, strerror (errno));
- retval = 1;
- break;
- }
- }
- else if ((sb.st_mode & S_IFMT) != S_IFDIR)
- {
- if (last)
- errno = EEXIST;
- else
- errno = ENOTDIR;
- printf ("root fs: path `%s' contains a file, %s\n",
- path, strerror (errno));
- retval = 1;
- break;
- }
- if (!last)
- *p = '/';
- }
- if (!first && !last)
- umask(oumask);
- return retval;
-}
-
-/*
- * Create enough files to support the networking stack.
- * Points to a table of strings.
- */
-
-int
-rtems_rootfs_file_append (const char *file,
- mode_t omode,
- const int line_cnt,
- const char **lines)
-{
- struct stat sb;
- int fd;
- int i;
-
- /*
- * See is a file exists. If it does not, create the
- * file and the path to the file.
- */
-
- fd = -1;
-
- if (stat(file, &sb))
- {
- if (errno == ENOENT)
- {
- /*
- * Get the path to the file if one exists and create the
- * path. If it exists nothing happens.
- */
-
- int i = strlen (file);
-
- while (i)
- {
- if (file[i] == '/')
- {
- char path[128];
-
- if (i >= sizeof path)
- {
- printf ("root fs, path too long `%s'\n", file);
- return -1;
- }
-
- strncpy (path, file, i);
- path[i] = '\0';
-
- if (rtems_rootfs_mkdir (path, MKDIR_MODE))
- return -1;
- break;
- }
- i--;
- }
-
- if ((fd = open (file, O_CREAT | O_APPEND | O_WRONLY, omode)) < 0)
- {
- printf ("root fs, cannot create file `%s' : %s\n",
- file, strerror (errno));
- return -1;
- }
- }
- }
-
- if (fd < 0)
- {
- if ((fd = open (file, O_APPEND | O_WRONLY)) < 0)
- {
- printf ("root fs, cannot open file `%s' : %s\n",
- file, strerror (errno));
- return -1;
- }
- }
-
- for (i = 0; i < line_cnt; i++)
- {
- int len = strlen (lines[i]);
-
- if (len)
- {
- if (write (fd, lines[i], strlen (lines[i])) < 0)
- {
- close (fd);
- printf ("root fs, cannot write to `%s' : %s\n",
- file, strerror (errno));
- return -1;
- }
- }
- }
-
- return close (fd);
-}
-
-/*
- * Write hosts record.
- */
-
-int
-rtems_rootfs_append_host_rec (unsigned long cip,
- const char *cname,
- const char *dname)
-{
- char buf[128];
- char *bufp = buf;
- const char *bufl[1];
- struct in_addr ip;
-
- ip.s_addr = cip;
-
- if (cname && strlen (cname))
- {
- snprintf (bufp, sizeof (buf), "%s\t\t%s", inet_ntoa (ip), cname);
- bufp += strlen (buf);
-
- if (dname && strlen (dname))
- {
- snprintf (bufp, sizeof (buf), "\t\t%s.%s", cname, dname);
- bufp += strlen (buf);
- }
-
- strcat (buf, "\n");
-
- bufl[0] = buf;
-
- if (rtems_rootfs_file_append ("/etc/hosts", MKFILE_MODE, 1, bufl) < 0)
- return -1;
- }
- else
- {
- printf ("rootfs hosts rec append, no cname supplied\n");
- return -1;
- }
-
- return 0;
-}
-
-/*
- * Create a root file system.
- */
-
-int
-rtems_create_root_fs ()
-{
- const char *lines[1];
- int i;
-
- /*
- * Create the directories.
- */
-
- for (i = 0;
- i < (sizeof (default_directories) / sizeof (rtems_rootfs_dir_table));
- i++)
- if (rtems_rootfs_mkdir (default_directories[i].name,
- default_directories[i].mode))
- return -1;
-
- /*
- * /etc/passwd, /etc/group
- * Maybe needed by some tools.
- */
-
- lines[0] = "root::0:0:root:/root:/bin/sh\n";
-
- if (rtems_rootfs_file_append ("/etc/passwd", MKFILE_MODE, 1, lines))
- return -1;
-
- lines[0] = "root::0:root\n";
-
- if (rtems_rootfs_file_append ("/etc/group", MKFILE_MODE, 1, lines))
- return -1;
-
- /*
- * The TCP/IP stack likes this one. If DNS does not work
- * use the host file.
- */
-
- lines[0] = "hosts,bind\n";
-
- if (rtems_rootfs_file_append ("/etc/host.conf", MKFILE_MODE, 1, lines))
- return -1;
-
- /*
- * Create a `/etc/hosts' file.
- */
-
- if (rtems_rootfs_append_host_rec (0x7f000001, "localhost", "localdomain"))
- return -1;
-
- return 0;
-}
-
diff --git a/c/src/libnetworking/rtems/mkrootfs.h b/c/src/libnetworking/rtems/mkrootfs.h
deleted file mode 100644
index 919f172ebf..0000000000
--- a/c/src/libnetworking/rtems/mkrootfs.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- ------------------------------------------------------------------------
- $Id$
- ------------------------------------------------------------------------
-
- Copyright Cybertec Pty Ltd, 2000
- All rights reserved Cybertec Pty Ltd, 2000
-
- COPYRIGHT (c) 1989-1998.
- On-Line Applications Research Corporation (OAR).
-
- The license and distribution terms for this file may be
- found in the file LICENSE in this distribution or at
-
- http://www.OARcorp.com/rtems/license.html.
-
- This software with is provided ``as is'' and with NO WARRANTY.
-
- ------------------------------------------------------------------------
-
- RTEMS Root FS creatation support.
-
-*/
-
-#ifndef __RTEMS_MKROOTFS_h
-#define __RTEMS_MKROOTFS_h
-
-#include <rtems.h>
-
-/*
- * Builds the complete path, like "mkdir -p".
- */
-
-int
-rtems_rootfs_mkdir (const char *path, mode_t omode);
-
-/*
- * Appends the lines to the a file. Create the file
- * and builds the path if it does not exist.
- */
-
-int
-rtems_rootfs_file_append (const char *file,
- mode_t omode,
- const int line_cnt,
- const char **lines);
-
-/*
- * Helper for bulding an /etc/hosts file.
- */
-
-int
-rtems_rootfs_append_host_rec (unsigned long cip,
- const char *cname,
- const char *dname);
-
-/*
- * Create a few common directories, plus a :
- * /etc/passwd, /etc/group, /etc/host.conf, and
- * /etc/hosts file.
- */
-
-int
-rtems_create_root_fs ();
-
-#endif
diff --git a/c/src/libnetworking/rtems/rtems_bootp.c b/c/src/libnetworking/rtems/rtems_bootp.c
deleted file mode 100644
index 76bb79170e..0000000000
--- a/c/src/libnetworking/rtems/rtems_bootp.c
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * $Id$
- */
-
-#include <rtems.h>
-#include <rtems/error.h>
-#include <sys/types.h>
-#include <rtems/rtems_bsdnet.h>
-
-/*
- * Perform a BOOTP request
- */
-void
-rtems_bsdnet_do_bootp (void)
-{
- rtems_bsdnet_semaphore_obtain ();
- bootpc_init (FALSE);
- rtems_bsdnet_semaphore_release ();
-}
-
-/*
- * Perform a BOOTP request and update "standard" files in /etc
- * with the results.
- */
-void
-rtems_bsdnet_do_bootp_and_rootfs (void)
-{
- rtems_bsdnet_semaphore_obtain ();
- bootpc_init (TRUE);
- rtems_bsdnet_semaphore_release ();
-}
diff --git a/c/src/libnetworking/rtems/rtems_bsdnet.h b/c/src/libnetworking/rtems/rtems_bsdnet.h
deleted file mode 100644
index 0e9837ea8d..0000000000
--- a/c/src/libnetworking/rtems/rtems_bsdnet.h
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * $Id$
- */
-
-#ifndef _RTEMS_BSDNET_
-#define _RTEMS_BSDNET_
-
-#include <rtems.h>
-
-/*
- * If this file is included from inside the Network Stack proper or
- * a device driver, then __INSIDE_RTEMS_BSD_TCPIP_STACK__ should be
- * defined. This triggers a number of internally used definitions.
- */
-
-#if defined(__INSIDE_RTEMS_BSD_TCPIP_STACK__)
-#undef _COMPILING_BSD_KERNEL_
-#undef KERNEL
-#undef INET
-#undef NFS
-#undef DIAGNOSTIC
-#undef BOOTP_COMPAT
-
-#define _COMPILING_BSD_KERNEL_
-#define KERNEL
-#define INET
-#define NFS
-#define DIAGNOSTIC
-#define BOOTP_COMPAT
-#endif
-
-/*
- * Values that may be obtained by BOOTP
- */
-extern struct in_addr rtems_bsdnet_bootp_server_address;
-extern char *rtems_bsdnet_bootp_server_name;
-extern char *rtems_bsdnet_bootp_boot_file_name;
-extern struct in_addr rtems_bsdnet_ntpserver[];
-extern int rtems_bsdnet_ntpserver_count;
-extern long rtems_bsdnet_timeoffset;
-
-/*
- * Manipulate routing tables
- */
-struct sockaddr;
-struct rtentry;
-int rtems_bsdnet_rtrequest (
- int req,
- struct sockaddr *dst,
- struct sockaddr *gateway,
- struct sockaddr *netmask,
- int flags,
- struct rtentry **net_nrt);
-
-/*
- * Diagnostics
- */
-void rtems_bsdnet_show_inet_routes (void);
-void rtems_bsdnet_show_mbuf_stats (void);
-void rtems_bsdnet_show_if_stats (void);
-void rtems_bsdnet_show_ip_stats (void);
-void rtems_bsdnet_show_icmp_stats (void);
-void rtems_bsdnet_show_udp_stats (void);
-void rtems_bsdnet_show_tcp_stats (void);
-
-/*
- * Network configuration
- */
-struct rtems_bsdnet_ifconfig {
- /*
- * These three entries must be supplied for each interface.
- */
- char *name;
-
- /*
- * This function now handles attaching and detaching an interface.
- * The parameter attaching indicates the operation being invoked.
- * For older attach functions which do not have the extra parameter
- * it will be ignored.
- */
- int (*attach)(struct rtems_bsdnet_ifconfig *conf, int attaching);
-
- /*
- * Link to next interface
- */
- struct rtems_bsdnet_ifconfig *next;
-
- /*
- * The following entries may be obtained
- * from BOOTP or explicitily supplied.
- */
- char *ip_address;
- char *ip_netmask;
- void *hardware_address;
-
- /*
- * The driver assigns defaults values to the following
- * entries if they are not explicitly supplied.
- */
- int ignore_broadcast;
- int mtu;
- int rbuf_count;
- int xbuf_count;
-
- /*
- * For external ethernet controller board the following
- * parameters are needed
- */
- unsigned int port; /* port of the board */
- unsigned int irno; /* irq of the board */
- unsigned int bpar; /* memory of the board */
-
- /*
- * Driver control block pointer. Typcially this points to the driver's
- * controlling structure. You set this when you have the structure allocated
- * externally to the driver.
- */
- void *drv_ctrl;
-
-};
-
-struct rtems_bsdnet_config {
- /*
- * This entry points to the head of the ifconfig chain.
- */
- struct rtems_bsdnet_ifconfig *ifconfig;
-
- /*
- * This entry should be rtems_bsdnet_do_bootp if BOOTP
- * is being used to configure the network, and NULL
- * if BOOTP is not being used.
- */
- void (*bootp)(void);
-
- /*
- * The remaining items can be initialized to 0, in
- * which case the default value will be used.
- */
- rtems_task_priority network_task_priority; /* 100 */
- unsigned long mbuf_bytecount; /* 64 kbytes */
- unsigned long mbuf_cluster_bytecount; /* 128 kbytes */
- char *hostname; /* BOOTP */
- char *domainname; /* BOOTP */
- char *gateway; /* BOOTP */
- char *log_host; /* BOOTP */
- char *name_server[3]; /* BOOTP */
- char *ntp_server[3]; /* BOOTP */
-};
-
-/*
- * Default global device configuration structure. This is scanned
- * by the initialize network function. Check the network demo's for
- * an example of the structure. Like the RTEMS configuration tables,
- * they are not part of RTEMS but part of your application or bsp
- * code.
- */
-extern struct rtems_bsdnet_config rtems_bsdnet_config;
-
-/*
- * Initialise the BSD stack, attach and `up' interfaces
- * in the `rtems_bsdnet_config'. RTEMS must already be initialised.
- */
-int rtems_bsdnet_initialize_network (void);
-
-/*
- * Dynamic interface control. Drivers must free any resources such as
- * memory, interrupts, io regions claimed during the `attach' and/or
- * `up' operations when asked to `detach'.
- * You must configure the interface after attaching it.
- */
-void rtems_bsdnet_attach (struct rtems_bsdnet_ifconfig *ifconfig);
-void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifconfig);
-
-/*
- * Interface configuration. The commands are listed in `sys/sockio.h'.
- */
-int rtems_bsdnet_ifconfig (const char *ifname, unsigned32 cmd, void *param);
-
-void rtems_bsdnet_do_bootp (void);
-void rtems_bsdnet_do_bootp_and_rootfs (void);
-
-int rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority);
-
-#endif /* _RTEMS_BSDNET_ */
diff --git a/c/src/libnetworking/rtems/rtems_bsdnet_internal.h b/c/src/libnetworking/rtems/rtems_bsdnet_internal.h
deleted file mode 100644
index 4b8c4fa652..0000000000
--- a/c/src/libnetworking/rtems/rtems_bsdnet_internal.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Declarations to fit FreeBSD to RTEMS.
- *
- *******************************************************************
- * WARNING *
- * This file should *never* be included by any application program *
- *******************************************************************
- *
- * $Id$
- */
-
-#ifndef _RTEMS_BSDNET_INTERNAL_H_
-#define _RTEMS_BSDNET_INTERNAL_H_
-
-#include <rtems.h>
-
-typedef unsigned int vm_offset_t;
-typedef long long vm_ooffset_t;
-typedef unsigned int vm_pindex_t;
-typedef unsigned int vm_size_t;
-
-#define _BSD_OFF_T_ rtems_signed32
-#define _BSD_PID_T_ rtems_id
-#define _BSD_VA_LIST_ char *
-
-/* make sure we get the network versions of these */
-#include "../machine/types.h"
-#include "../machine/param.h"
-
-#include <sys/time.h>
-/*
-struct itimerval {
- struct timeval it_interval;
- struct timeval it_value;
-};
-*/
-struct mdproc {
- int md_flags;
- int *md_regs;
-};
-
-#define USHRT_MAX 65535
-
-/*
- * Other RTEMS/BSD glue
- */
-struct socket;
-extern int soconnsleep (struct socket *so);
-extern void soconnwakeup (struct socket *so);
-#define splnet() 0
-#define splimp() 0
-#define splx(_s) do { (_s) = 0; } while(0)
-
-#define ovbcopy(f,t,n) bcopy(f,t,n)
-#define copyout(f,t,n) (memcpy(t,f,n),0)
-#define copyin(f,t,n) (memcpy(t,f,n),0)
-
-#define random() rtems_bsdnet_random()
-#define panic rtems_panic
-#define suser(a,b) 0
-
-void microtime (struct timeval *tv);
-#define hz rtems_bsdnet_ticks_per_second
-#define tick rtems_bsdnet_microseconds_per_tick
-
-#define log rtems_bsdnet_log
-
-/*
- * Since we can't have two sys/types.h files, we'll hack around
- * and copy the contents of the BSD sys/types.h to here....
- */
-#include <sys/cdefs.h>
-
-typedef u_int64_t u_quad_t; /* quads */
-typedef int64_t quad_t;
-typedef quad_t * qaddr_t;
-
-typedef void __sighandler_t __P((int));
-typedef __sighandler_t *sig_t; /* type of pointer to a signal function */
-#define NSIG 32
-struct sigaltstack {
- char *ss_sp; /* signal stack base */
- int ss_size; /* signal stack length */
- int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
-};
-
-#ifdef KERNEL
-typedef int boolean_t;
-typedef struct vm_page *vm_page_t;
-#endif
-
-#ifndef _POSIX_SOURCE
-/*
- * minor() gives a cookie instead of an index since we don't want to
- * change the meanings of bits 0-15 or waste time and space shifting
- * bits 16-31 for devices that don't use them.
- */
-#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */
-#define minor(x) ((int)((x)&0xffff00ff)) /* minor number */
-#define makedev(x,y) ((dev_t)(((x) << 8) | (y))) /* create dev_t */
-#endif
-
-#include <machine/endian.h>
-
-typedef quad_t rlim_t; /* resource limit */
-typedef u_int32_t fixpt_t; /* fixed point number */
-
-/*
- * Forward structure declarations for function prototypes. We include the
- * common structures that cross subsystem boundaries here; others are mostly
- * used in the same place that the structure is defined.
- */
-struct proc;
-struct pgrp;
-struct ucred;
-struct rusage;
-struct file;
-struct buf;
-struct tty;
-struct uio;
-struct rtems_bsdnet_ifconfig;
-
-/*
- * Redo kernel memory allocation
- */
-#define malloc rtems_bsdnet_malloc
-#define free rtems_bsdnet_free
-
-#define M_NOWAIT 0x0001
-void *rtems_bsdnet_malloc (unsigned long size, int type, int flags);
-void rtems_bsdnet_free (void *addr, int type);
-
-void rtems_bsdnet_semaphore_obtain (void);
-void rtems_bsdnet_semaphore_release (void);
-void rtems_bsdnet_schednetisr (int n);
-int rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep);
-
-unsigned long rtems_bsdnet_seconds_since_boot (void);
-unsigned long rtems_bsdnet_random (void);
-
-rtems_id rtems_bsdnet_newproc (
- char *name,
- int stacksize,
- void (*entry)(void *),
- void *arg
-);
-
-rtems_status_code rtems_bsdnet_event_receive (
- rtems_event_set event_in,
- rtems_option option_set,
- rtems_interval ticks,
- rtems_event_set *event_out
-);
-
-/*
- * Network configuration
- */
-extern int rtems_bsdnet_ticks_per_second;
-extern int rtems_bsdnet_microseconds_per_tick;
-extern struct in_addr rtems_bsdnet_log_host_address;
-extern char *rtems_bsdnet_domain_name;
-extern struct in_addr rtems_bsdnet_nameserver[];
-extern int rtems_bsdnet_nameserver_count;
-
-/*
- * Internal IOCTL command
- */
-#define SIO_RTEMS_SHOW_STATS _IO('i', 250)
-
-/*
- * Some extra prototypes
- */
-int sethostname (char *name, size_t namelen);
-void domaininit (void *);
-void ifinit (void *);
-void ipintr (void);
-void arpintr (void);
-void bootpc_init(int );
-int socket (int, int, int);
-int ioctl (int, int, ...);
-
-/*
- * Events used by networking routines.
- * Everything will break if the application
- * tries to use these events or if the `sleep'
- * events are equal to any of the NETISR * events.
- */
-#define SBWAIT_EVENT RTEMS_EVENT_24
-#define SOSLEEP_EVENT RTEMS_EVENT_25
-#define NETISR_IP_EVENT (1 << NETISR_IP)
-#define NETISR_ARP_EVENT (1 << NETISR_ARP)
-#define NETISR_EVENTS (NETISR_IP_EVENT|NETISR_ARP_EVENT)
-#if (SBWAIT_EVENT & SOSLEEP_EVENT & NETISR_EVENTS)
-# error "Network event conflict"
-#endif
-
-#endif /* _RTEMS_BSDNET_INTERNAL_H_ */
diff --git a/c/src/libnetworking/rtems/rtems_glue.c b/c/src/libnetworking/rtems/rtems_glue.c
deleted file mode 100644
index 52c3361366..0000000000
--- a/c/src/libnetworking/rtems/rtems_glue.c
+++ /dev/null
@@ -1,1202 +0,0 @@
-/*
- * $Id$
- */
-
-#define RTEMS_FAST_MUTEX
-
-#ifdef RTEMS_FAST_MUTEX
-#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ 1
-#endif
-
-#include <string.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <errno.h>
-
-#include <rtems.h>
-#include <rtems/libio.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/domain.h>
-#include <sys/mbuf.h>
-#include <sys/socketvar.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/callout.h>
-#include <sys/proc.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <net/route.h>
-#include <netinet/in.h>
-#include <vm/vm.h>
-#include <arpa/inet.h>
-
-#include <net/netisr.h>
-#include <net/route.h>
-
-/*
- * Memory allocation
- */
-static int nmbuf = (64 * 1024) / MSIZE;
- int nmbclusters = (128 * 1024) / MCLBYTES;
-
-/*
- * Socket buffering parameters
- */
-unsigned long sb_efficiency = 8;
-
-/*
- * Network task synchronization
- */
-static rtems_id networkSemaphore;
-#ifdef RTEMS_FAST_MUTEX
-Semaphore_Control *the_networkSemaphore;
-#endif
-static rtems_id networkDaemonTid;
-static rtems_unsigned32 networkDaemonPriority;
-static void networkDaemon (void *task_argument);
-
-/*
- * Network timing
- */
-int rtems_bsdnet_ticks_per_second;
-int rtems_bsdnet_microseconds_per_tick;
-
-/*
- * Callout processing
- */
-static rtems_interval ticksWhenCalloutsLastChecked;
-static struct callout *callfree, calltodo;
-
-/*
- * FreeBSD variables
- */
-int nfs_diskless_valid;
-
-/*
- * BOOTP values
- */
-struct in_addr rtems_bsdnet_log_host_address;
-struct in_addr rtems_bsdnet_bootp_server_address;
-char *rtems_bsdnet_bootp_boot_file_name;
-char *rtems_bsdnet_bootp_server_name;
-char *rtems_bsdnet_domain_name;
-struct in_addr rtems_bsdnet_nameserver[sizeof rtems_bsdnet_config.name_server /
- sizeof rtems_bsdnet_config.name_server[0]];
-int rtems_bsdnet_nameserver_count;
-struct in_addr rtems_bsdnet_ntpserver[sizeof rtems_bsdnet_config.ntp_server /
- sizeof rtems_bsdnet_config.ntp_server[0]];
-int rtems_bsdnet_ntpserver_count;
-long rtems_bsdnet_timeoffset;
-
-/*
- * Perform FreeBSD memory allocation.
- * FIXME: This should be modified to keep memory allocation statistics.
- */
-#undef malloc
-#undef free
-extern void *malloc (size_t);
-extern void free (void *);
-void *
-rtems_bsdnet_malloc (unsigned long size, int type, int flags)
-{
- void *p;
- int try = 0;
-
- for (;;) {
- p = malloc (size);
- if (p || (flags & M_NOWAIT))
- return p;
- rtems_bsdnet_semaphore_release ();
- if (++try >= 30) {
- printf ("rtems_bsdnet_malloc still waiting.\n");
- try = 0;
- }
- rtems_task_wake_after (rtems_bsdnet_ticks_per_second);
- rtems_bsdnet_semaphore_obtain ();
- }
-}
-
-/*
- * Free FreeBSD memory
- * FIXME: This should be modified to keep memory allocation statistics.
- */
-void
-rtems_bsdnet_free (void *addr, int type)
-{
- free (addr);
-}
-
-/*
- * Do the initializations required by the BSD code
- */
-static int
-bsd_init (void)
-{
- int i;
- char *p;
-
- /*
- * Set up mbuf cluster data strutures
- */
- p = malloc ((nmbclusters*MCLBYTES)+MCLBYTES-1);
- if (p == NULL) {
- printf ("Can't get network cluster memory.\n");
- return -1;
- }
- p = (char *)(((unsigned long)p + (MCLBYTES-1)) & ~(MCLBYTES-1));
- mbutl = (struct mbuf *)p;
- for (i = 0; i < nmbclusters; i++) {
- ((union mcluster *)p)->mcl_next = mclfree;
- mclfree = (union mcluster *)p;
- p += MCLBYTES;
- mbstat.m_clfree++;
- }
- mbstat.m_clusters = nmbclusters;
- mclrefcnt = malloc (nmbclusters);
- if (mclrefcnt == NULL) {
- printf ("Can't get mbuf cluster reference counts memory.\n");
- return -1;
- }
- memset (mclrefcnt, '\0', nmbclusters);
-
- /*
- * Set up mbuf data structures
- */
-
- p = malloc(nmbuf * MSIZE + MSIZE - 1);
- p = (char *)(((unsigned int)p + MSIZE - 1) & ~(MSIZE - 1));
- if (p == NULL) {
- printf ("Can't get network memory.\n");
- return -1;
- }
- for (i = 0; i < nmbuf; i++) {
- ((struct mbuf *)p)->m_next = mmbfree;
- mmbfree = (struct mbuf *)p;
- p += MSIZE;
- }
- mbstat.m_mbufs = nmbuf;
- mbstat.m_mtypes[MT_FREE] = nmbuf;
-
- /*
- * Set up domains
- */
- {
- extern struct domain routedomain;
- extern struct domain inetdomain;
-
- routedomain.dom_next = domains;
- domains = &routedomain;
- inetdomain.dom_next = domains;
- domains = &inetdomain;
- domaininit (NULL);
- }
-
- /*
- * Set up interfaces
- */
- ifinit (NULL);
- return 0;
-}
-
-/*
- * Initialize and start network operations
- */
-static int
-rtems_bsdnet_initialize (void)
-{
- rtems_status_code sc;
-
- /*
- * Set the priority of all network tasks
- */
- if (rtems_bsdnet_config.network_task_priority == 0)
- networkDaemonPriority = 100;
- else
- networkDaemonPriority = rtems_bsdnet_config.network_task_priority;
-
- /*
- * Set the memory allocation limits
- */
- if (rtems_bsdnet_config.mbuf_bytecount)
- nmbuf = rtems_bsdnet_config.mbuf_bytecount / MSIZE;
- if (rtems_bsdnet_config.mbuf_cluster_bytecount)
- nmbclusters = rtems_bsdnet_config.mbuf_cluster_bytecount / MCLBYTES;
-
- /*
- * Create the task-synchronization semaphore
- */
- sc = rtems_semaphore_create (rtems_build_name('B', 'S', 'D', 'n'),
- 0,
- RTEMS_PRIORITY |
- RTEMS_BINARY_SEMAPHORE |
- RTEMS_INHERIT_PRIORITY |
- RTEMS_NO_PRIORITY_CEILING |
- RTEMS_LOCAL,
- 0,
- &networkSemaphore);
- if (sc != RTEMS_SUCCESSFUL) {
- printf ("Can't create network seamphore: `%s'\n", rtems_status_text (sc));
- return -1;
- }
-#ifdef RTEMS_FAST_MUTEX
- {
- Objects_Locations location;
- the_networkSemaphore = _Semaphore_Get( networkSemaphore, &location );
- _Thread_Enable_dispatch();
- }
-#endif
-
- /*
- * Compute clock tick conversion factors
- */
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &rtems_bsdnet_ticks_per_second);
- if (rtems_bsdnet_ticks_per_second <= 0)
- rtems_bsdnet_ticks_per_second = 1;
- rtems_bsdnet_microseconds_per_tick = 1000000 / rtems_bsdnet_ticks_per_second;
-
- /*
- * Ensure that `seconds' is greater than 0
- */
- rtems_task_wake_after (rtems_bsdnet_ticks_per_second);
-
- /*
- * Set up BSD-style sockets
- */
- if (bsd_init () < 0)
- return -1;
-
- /*
- * Start network daemon
- */
- networkDaemonTid = rtems_bsdnet_newproc ("ntwk", 4096, networkDaemon, NULL);
-
- /*
- * Let other network tasks begin
- */
- rtems_bsdnet_semaphore_release ();
- return 0;
-}
-
-/*
- * Obtain network mutex
- */
-void
-rtems_bsdnet_semaphore_obtain (void)
-{
-#ifdef RTEMS_FAST_MUTEX
- ISR_Level level;
- _ISR_Disable (level);
- _CORE_mutex_Seize (
- &the_networkSemaphore->Core_control.mutex,
- networkSemaphore,
- 1, /* wait */
- 0, /* forever */
- level
- );
- if (_Thread_Executing->Wait.return_code)
- rtems_panic ("Can't obtain network semaphore\n");
-#else
- rtems_status_code sc;
-
- sc = rtems_semaphore_obtain (networkSemaphore, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't obtain network semaphore: `%s'\n", rtems_status_text (sc));
-#endif
-}
-
-/*
- * Release network mutex
- */
-void
-rtems_bsdnet_semaphore_release (void)
-{
-#ifdef RTEMS_FAST_MUTEX
- int i;
-
- _Thread_Disable_dispatch();
- i = _CORE_mutex_Surrender (
- &the_networkSemaphore->Core_control.mutex,
- networkSemaphore,
- NULL
- );
- _Thread_Enable_dispatch();
- if (i)
- rtems_panic ("Can't release network semaphore\n");
-#else
- rtems_status_code sc;
-
- sc = rtems_semaphore_release (networkSemaphore);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't release network semaphore: `%s'\n", rtems_status_text (sc));
-#endif
-}
-
-/*
- * Wait for something to happen to a socket buffer
- */
-int
-sbwait(sb)
- struct sockbuf *sb;
-{
- rtems_event_set events;
- rtems_id tid;
- rtems_status_code sc;
-
- /*
- * Soak up any pending events.
- * The sleep/wakeup synchronization in the FreeBSD
- * kernel has no memory.
- */
- rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &events);
-
- /*
- * Set this task as the target of the wakeup operation.
- */
- rtems_task_ident (RTEMS_SELF, 0, &tid);
- sb->sb_sel.si_pid = tid;
-
- /*
- * Show that socket is waiting
- */
- sb->sb_flags |= SB_WAIT;
-
- /*
- * Release the network semaphore.
- */
- rtems_bsdnet_semaphore_release ();
-
- /*
- * Wait for the wakeup event.
- */
- sc = rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, sb->sb_timeo, &events);
-
- /*
- * Reobtain the network semaphore.
- */
- rtems_bsdnet_semaphore_obtain ();
-
- /*
- * Return the status of the wait.
- */
- switch (sc) {
- case RTEMS_SUCCESSFUL: return 0;
- case RTEMS_TIMEOUT: return EWOULDBLOCK;
- default: return ENXIO;
- }
-}
-
-
-/*
- * Wake up the task waiting on a socket buffer.
- */
-void
-sowakeup(so, sb)
- register struct socket *so;
- register struct sockbuf *sb;
-{
- if (sb->sb_flags & SB_WAIT) {
- sb->sb_flags &= ~SB_WAIT;
- rtems_event_send (sb->sb_sel.si_pid, SBWAIT_EVENT);
- }
- if (sb->sb_wakeup) {
- (*sb->sb_wakeup) (so, sb->sb_wakeuparg);
- }
-}
-
-/*
- * For now, a socket can be used by only one task at a time.
- */
-int
-sb_lock(sb)
- register struct sockbuf *sb;
-{
- rtems_panic ("Socket buffer is already in use.");
- return 0;
-}
-void
-wakeup (void *p)
-{
- rtems_panic ("Wakeup called");
-}
-
-/*
- * Wait for a connection/disconnection event.
- */
-int
-soconnsleep (struct socket *so)
-{
- rtems_event_set events;
- rtems_id tid;
- rtems_status_code sc;
-
- /*
- * Soak up any pending events.
- * The sleep/wakeup synchronization in the FreeBSD
- * kernel has no memory.
- */
- rtems_event_receive (SOSLEEP_EVENT, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &events);
-
- /*
- * Set this task as the target of the wakeup operation.
- */
- if (so->so_pgid)
- rtems_panic ("Another task is already sleeping on that socket");
- rtems_task_ident (RTEMS_SELF, 0, &tid);
- so->so_pgid = tid;
-
- /*
- * Wait for the wakeup event.
- */
- sc = rtems_bsdnet_event_receive (SOSLEEP_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, so->so_rcv.sb_timeo, &events);
-
- /*
- * Relinquish ownership of the socket.
- */
- so->so_pgid = 0;
-
- switch (sc) {
- case RTEMS_SUCCESSFUL: return 0;
- case RTEMS_TIMEOUT: return EWOULDBLOCK;
- default: return ENXIO;
- }
-}
-
-/*
- * Wake up a task waiting for a connection/disconnection to complete.
- */
-void
-soconnwakeup (struct socket *so)
-{
- if (so->so_pgid)
- rtems_event_send (so->so_pgid, SOSLEEP_EVENT);
-}
-
-/*
- * Send an event to the network daemon.
- * This corresponds to sending a software interrupt in the BSD kernel.
- */
-void
-rtems_bsdnet_schednetisr (int n)
-{
- rtems_event_send (networkDaemonTid, 1 << n);
-}
-
-/*
- * The network daemon
- * This provides a context to run BSD software interrupts
- */
-static void
-networkDaemon (void *task_argument)
-{
- rtems_event_set events;
- rtems_interval now;
- int ticksPassed;
- unsigned32 timeout;
- struct callout *c;
-
- for (;;) {
- c = calltodo.c_next;
- if (c)
- timeout = c->c_time;
- else
- timeout = RTEMS_NO_TIMEOUT;
- rtems_bsdnet_event_receive (NETISR_EVENTS,
- RTEMS_EVENT_ANY | RTEMS_WAIT,
- timeout,
- &events);
- if (events & NETISR_IP_EVENT)
- ipintr ();
- if (events & NETISR_ARP_EVENT)
- arpintr ();
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
- ticksPassed = now - ticksWhenCalloutsLastChecked;
- if (ticksPassed != 0) {
- ticksWhenCalloutsLastChecked = now;
-
- c = calltodo.c_next;
- if (c) {
- c->c_time -= ticksPassed;
- while ((c = calltodo.c_next) != NULL && c->c_time <= 0) {
- void *arg;
- void (*func) (void *);
-
- func = c->c_func;
- arg = c->c_arg;
- calltodo.c_next = c->c_next;
- c->c_next = callfree;
- callfree = c;
- (*func)(arg);
- }
- }
- }
- }
-}
-
-/*
- * Structure passed to task-start stub
- */
-struct newtask {
- void (*entry)(void *);
- void *arg;
-};
-
-/*
- * Task-start stub
- */
-static void
-taskEntry (rtems_task_argument arg)
-{
- struct newtask t;
-
- /*
- * Pick up task information and free
- * the memory allocated to pass the
- * information to this task.
- */
- t = *(struct newtask *)arg;
- free ((struct newtask *)arg);
-
- /*
- * Enter the competition for the network semaphore
- */
- rtems_bsdnet_semaphore_obtain ();
-
- /*
- * Enter the task
- */
- (*t.entry)(t.arg);
- rtems_panic ("Network task returned!\n");
-}
-
-/*
- * Start a network task
- */
-rtems_id
-rtems_bsdnet_newproc (char *name, int stacksize, void(*entry)(void *), void *arg)
-{
- struct newtask *t;
- char nm[4];
- rtems_id tid;
- rtems_status_code sc;
-
- strncpy (nm, name, 4);
- sc = rtems_task_create (rtems_build_name(nm[0], nm[1], nm[2], nm[3]),
- networkDaemonPriority,
- stacksize,
- RTEMS_PREEMPT|RTEMS_NO_TIMESLICE|RTEMS_NO_ASR|RTEMS_INTERRUPT_LEVEL(0),
- RTEMS_NO_FLOATING_POINT|RTEMS_LOCAL,
- &tid);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't create network daemon `%s': `%s'\n", name, rtems_status_text (sc));
-
- /*
- * Set up task arguments
- */
- t = malloc (sizeof *t);
- t->entry = entry;
- t->arg = arg;
-
- /*
- * Start the task
- */
- sc = rtems_task_start (tid, taskEntry, (rtems_task_argument)t);
- if (sc != RTEMS_SUCCESSFUL)
- rtems_panic ("Can't start network daemon `%s': `%s'\n", name, rtems_status_text (sc));
-
- /*
- * Let our caller know the i.d. of the new task
- */
- return tid;
-}
-
-rtems_status_code rtems_bsdnet_event_receive (
- rtems_event_set event_in,
- rtems_option option_set,
- rtems_interval ticks,
- rtems_event_set *event_out)
-{
- rtems_status_code sc;
-
- rtems_bsdnet_semaphore_release ();
- sc = rtems_event_receive (event_in, option_set, ticks, event_out);
- rtems_bsdnet_semaphore_obtain ();
- return sc;
-}
-
-/*
- * Return time since startup
- */
-void
-microtime (struct timeval *t)
-{
- rtems_interval now;
-
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
- t->tv_sec = now / rtems_bsdnet_ticks_per_second;
- t->tv_usec = (now % rtems_bsdnet_ticks_per_second) * rtems_bsdnet_microseconds_per_tick;
-}
-
-unsigned long
-rtems_bsdnet_seconds_since_boot (void)
-{
- rtems_interval now;
-
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
- return now / rtems_bsdnet_ticks_per_second;
-}
-
-/*
- * Fake random number generator
- */
-unsigned long
-rtems_bsdnet_random (void)
-{
- rtems_interval now;
-
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
- return (now * 99991);
-}
-
-/*
- * Callout list processing
- */
-void
-timeout(void (*ftn)(void *), void *arg, int ticks)
-{
- register struct callout *new, *p, *t;
-
- if (ticks <= 0)
- ticks = 1;
-
- /* Fill in the next free callout structure. */
- if (callfree == NULL) {
- callfree = malloc (sizeof *callfree);
- if (callfree == NULL)
- rtems_panic ("No memory for timeout table entry");
- callfree->c_next = NULL;
- }
-
- new = callfree;
- callfree = new->c_next;
- new->c_arg = arg;
- new->c_func = ftn;
-
- /*
- * The time for each event is stored as a difference from the time
- * of the previous event on the queue. Walk the queue, correcting
- * the ticks argument for queue entries passed. Correct the ticks
- * value for the queue entry immediately after the insertion point
- * as well. Watch out for negative c_time values; these represent
- * overdue events.
- */
- for (p = &calltodo;
- (t = p->c_next) != NULL && ticks > t->c_time; p = t)
- if (t->c_time > 0)
- ticks -= t->c_time;
- new->c_time = ticks;
- if (t != NULL)
- t->c_time -= ticks;
-
- /* Insert the new entry into the queue. */
- p->c_next = new;
- new->c_next = t;
-}
-
-/*
- * Ticks till specified time
- * XXX: This version worries only about seconds, but that's good
- * enough for the way the network code uses this routine.
- */
-int
-hzto(struct timeval *tv)
-{
- long diff = tv->tv_sec - rtems_bsdnet_seconds_since_boot();
-
- if (diff <= 0)
- return 1;
- return diff * rtems_bsdnet_ticks_per_second;
-}
-
-/*
- * Kernel debugging
- */
-int rtems_bsdnet_log_priority;
-void
-rtems_bsdnet_log (int priority, const char *fmt, ...)
-{
- va_list args;
-
- if (priority & rtems_bsdnet_log_priority) {
- va_start (args, fmt);
- vprintf (fmt, args);
- va_end (args);
- }
-}
-
-/*
- * IP header checksum routine for processors which don't have an inline version
- */
-u_int
-in_cksum_hdr (const void *ip)
-{
- rtems_unsigned32 sum;
- const rtems_unsigned16 *sp;
- int i;
-
- sum = 0;
- sp = (rtems_unsigned16 *)ip;
- for (i = 0 ; i < 10 ; i++)
- sum += *sp++;
- while (sum > 0xFFFF)
- sum = (sum & 0xffff) + (sum >> 16);
- return ~sum & 0xFFFF;
-}
-
-/*
- * Manipulate routing tables
- */
-int rtems_bsdnet_rtrequest (
- int req,
- struct sockaddr *dst,
- struct sockaddr *gateway,
- struct sockaddr *netmask,
- int flags,
- struct rtentry **net_nrt)
-{
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- error = rtrequest (req, dst, gateway, netmask, flags, net_nrt);
- rtems_bsdnet_semaphore_release ();
- if (error) {
- errno = error;
- return -1;
- }
- return 0;
-}
-
-static int
-rtems_bsdnet_setup (void)
-{
- struct rtems_bsdnet_ifconfig *ifp;
- short flags;
- struct sockaddr_in address;
- struct sockaddr_in netmask;
- struct sockaddr_in broadcast;
- struct sockaddr_in gateway;
- int i;
- extern char *strdup (const char *cp);
-
- /*
- * Set local parameters
- */
- if (rtems_bsdnet_config.hostname)
- sethostname (rtems_bsdnet_config.hostname,
- strlen (rtems_bsdnet_config.hostname));
- if (rtems_bsdnet_config.domainname)
- rtems_bsdnet_domain_name =
- strdup (rtems_bsdnet_config.domainname);
- if (rtems_bsdnet_config.log_host)
- rtems_bsdnet_log_host_address.s_addr =
- inet_addr (rtems_bsdnet_config.log_host);
- for (i = 0 ; i < sizeof rtems_bsdnet_config.name_server /
- sizeof rtems_bsdnet_config.name_server[0] ; i++) {
- if (!rtems_bsdnet_config.name_server[i])
- break;
- rtems_bsdnet_nameserver[rtems_bsdnet_nameserver_count++].s_addr
- = inet_addr (rtems_bsdnet_config.name_server[i]);
- }
- for (i = 0 ; i < sizeof rtems_bsdnet_config.ntp_server /
- sizeof rtems_bsdnet_config.ntp_server[0] ; i++) {
- if (!rtems_bsdnet_config.ntp_server[i])
- break;
- rtems_bsdnet_ntpserver[rtems_bsdnet_ntpserver_count++].s_addr
- = inet_addr (rtems_bsdnet_config.ntp_server[i]);
- }
-
- /*
- * Configure interfaces
- */
- for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) {
- if (ifp->ip_address == NULL)
- continue;
-
- /*
- * Bring interface up
- */
- flags = IFF_UP;
- if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFFLAGS, &flags) < 0) {
- printf ("Can't bring %s up: %s\n", ifp->name, strerror (errno));
- continue;
- }
-
- /*
- * Set interface netmask
- */
- memset (&netmask, '\0', sizeof netmask);
- netmask.sin_len = sizeof netmask;
- netmask.sin_family = AF_INET;
- netmask.sin_addr.s_addr = inet_addr (ifp->ip_netmask);
- if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFNETMASK, &netmask) < 0) {
- printf ("Can't set %s netmask: %s\n", ifp->name, strerror (errno));
- continue;
- }
-
- /*
- * Set interface address
- */
- memset (&address, '\0', sizeof address);
- address.sin_len = sizeof address;
- address.sin_family = AF_INET;
- address.sin_addr.s_addr = inet_addr (ifp->ip_address);
- if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFADDR, &address) < 0) {
- printf ("Can't set %s address: %s\n", ifp->name, strerror (errno));
- continue;
- }
-
- /*
- * Set interface broadcast address if the interface has the
- * broadcast flag set.
- */
- if (rtems_bsdnet_ifconfig (ifp->name, SIOCGIFFLAGS, &flags) < 0) {
- printf ("Can't read %s flags: %s\n", ifp->name, strerror (errno));
- continue;
- }
- if (flags & IFF_BROADCAST) {
- memset (&broadcast, '\0', sizeof broadcast);
- broadcast.sin_len = sizeof broadcast;
- broadcast.sin_family = AF_INET;
- broadcast.sin_addr.s_addr =
- address.sin_addr.s_addr | ~netmask.sin_addr.s_addr;
- if (rtems_bsdnet_ifconfig (ifp->name, SIOCSIFBRDADDR, &broadcast) < 0) {
- struct in_addr in_addr;
- in_addr.s_addr = broadcast.sin_addr.s_addr;
- printf ("Can't set %s broadcast address %s: %s\n",
- ifp->name, inet_ntoa (in_addr), strerror (errno));
- }
- }
- }
-
- /*
- * Set default route
- */
- if (rtems_bsdnet_config.gateway) {
- address.sin_addr.s_addr = INADDR_ANY;
- netmask.sin_addr.s_addr = INADDR_ANY;
- memset (&gateway, '\0', sizeof gateway);
- gateway.sin_len = sizeof gateway;
- gateway.sin_family = AF_INET;
- gateway.sin_addr.s_addr = inet_addr (rtems_bsdnet_config.gateway);
- if (rtems_bsdnet_rtrequest (
- RTM_ADD,
- (struct sockaddr *)&address,
- (struct sockaddr *)&gateway,
- (struct sockaddr *)&netmask,
- (RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL) < 0) {
- printf ("Can't set default route: %s\n", strerror (errno));
- return -1;
- }
- }
- return 0;
-}
-
-/*
- * Initialize the network
- */
-int
-rtems_bsdnet_initialize_network (void)
-{
- struct rtems_bsdnet_ifconfig *ifp;
-
- /*
- * Start network tasks.
- * Initialize BSD network data structures.
- */
- if (rtems_bsdnet_initialize () < 0)
- return -1;
-
- /*
- * Attach interfaces
- */
- for (ifp = rtems_bsdnet_config.ifconfig ; ifp ; ifp = ifp->next) {
- rtems_bsdnet_attach (ifp);
- }
-
- /*
- * Bring up the network
- */
- if (rtems_bsdnet_setup () < 0)
- return -1;
- if (rtems_bsdnet_config.bootp)
- (*rtems_bsdnet_config.bootp)();
- return 0;
-}
-
-/*
- * Attach a network interface.
- */
-void rtems_bsdnet_attach (struct rtems_bsdnet_ifconfig *ifp)
-{
- if (ifp) {
- rtems_bsdnet_semaphore_obtain ();
- (ifp->attach)(ifp, 1);
- rtems_bsdnet_semaphore_release ();
- }
-}
-
-/*
- * Detach a network interface.
- */
-void rtems_bsdnet_detach (struct rtems_bsdnet_ifconfig *ifp)
-{
- if (ifp) {
- rtems_bsdnet_semaphore_obtain ();
- (ifp->attach)(ifp, 0);
- rtems_bsdnet_semaphore_release ();
- }
-}
-
-/*
- * Interface Configuration.
- */
-int rtems_bsdnet_ifconfig (const char *ifname, unsigned32 cmd, void *param)
-{
- int s, r = 0;
- struct ifreq ifreq;
-
- /*
- * Configure interfaces
- */
- s = socket (AF_INET, SOCK_DGRAM, 0);
- if (s < 0)
- return -1;
-
- strncpy (ifreq.ifr_name, ifname, IFNAMSIZ);
-
- rtems_bsdnet_semaphore_obtain ();
-
- switch (cmd) {
- case SIOCSIFADDR:
- case SIOCSIFNETMASK:
- memcpy (&ifreq.ifr_addr, param, sizeof (struct sockaddr));
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case OSIOCGIFADDR:
- case SIOCGIFADDR:
- case OSIOCGIFNETMASK:
- case SIOCGIFNETMASK:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- memcpy (param, &ifreq.ifr_addr, sizeof (struct sockaddr));
- break;
-
- case SIOCGIFFLAGS:
- case SIOCSIFFLAGS:
- if ((r = ioctl (s, SIOCGIFFLAGS, &ifreq)) < 0)
- break;
- if (cmd == SIOCGIFFLAGS) {
- *((short*) param) = ifreq.ifr_flags;
- break;
- }
- ifreq.ifr_flags |= *((short*) param);
- r = ioctl (s, SIOCSIFFLAGS, &ifreq);
- break;
-
- case SIOCSIFDSTADDR:
- memcpy (&ifreq.ifr_dstaddr, param, sizeof (struct sockaddr));
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case OSIOCGIFDSTADDR:
- case SIOCGIFDSTADDR:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- memcpy (param, &ifreq.ifr_dstaddr, sizeof (struct sockaddr));
- break;
-
- case SIOCSIFBRDADDR:
- memcpy (&ifreq.ifr_broadaddr, param, sizeof (struct sockaddr));
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case OSIOCGIFBRDADDR:
- case SIOCGIFBRDADDR:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- memcpy (param, &ifreq.ifr_broadaddr, sizeof (struct sockaddr));
- break;
-
- case SIOCSIFMETRIC:
- ifreq.ifr_metric = *((int*) param);
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case SIOCGIFMETRIC:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- *((int*) param) = ifreq.ifr_metric;
- break;
-
- case SIOCSIFMTU:
- ifreq.ifr_mtu = *((int*) param);
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case SIOCGIFMTU:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- *((int*) param) = ifreq.ifr_mtu;
- break;
-
- case SIOCSIFPHYS:
- ifreq.ifr_phys = *((int*) param);
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case SIOCGIFPHYS:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- *((int*) param) = ifreq.ifr_phys;
- break;
-
- case SIOCSIFMEDIA:
- ifreq.ifr_media = *((int*) param);
- r = ioctl (s, cmd, &ifreq);
- break;
-
- case SIOCGIFMEDIA:
- if ((r = ioctl (s, cmd, &ifreq)) < 0)
- break;
- *((int*) param) = ifreq.ifr_media;
- break;
-
- default:
- errno = EOPNOTSUPP;
- r = -1;
- break;
- }
-
- rtems_bsdnet_semaphore_release ();
-
- close (s);
- return r;
-}
-
-/*
- * Parse a network driver name into a name and a unit number
- */
-int
-rtems_bsdnet_parse_driver_name (const struct rtems_bsdnet_ifconfig *config, char **namep)
-{
- const char *cp = config->name;
- char c;
- int unitNumber = 0;
-
- if (cp == NULL) {
- printf ("No network driver name.\n");
- return -1;
- }
- while ((c = *cp++) != '\0') {
- if ((c >= '0') && (c <= '9')) {
- int len = cp - config->name;
- if ((len < 2) || (len > 50))
- break;
- for (;;) {
- unitNumber = (unitNumber * 10) + (c - '0');
- c = *cp++;
- if (c == '\0') {
- char *unitName = malloc (len);
- if (unitName == NULL) {
- printf ("No memory.\n");
- return -1;
- }
- strncpy (unitName, config->name, len - 1);
- unitName[len-1] = '\0';
- *namep = unitName;
- return unitNumber;
- }
- if ((c < '0') || (c > '9'))
- break;
- }
- break;
- }
- }
- printf ("Bad network driver name `%s'.\n", config->name);
- return -1;
-}
-
-/*
- * Handle requests for more network memory
- * XXX: Another possibility would be to use a semaphore here with
- * a release in the mbuf free macro. I have chosen this `polling'
- * approach because:
- * 1) It is simpler.
- * 2) It adds no complexity to the free macro.
- * 3) Running out of mbufs should be a rare
- * condition -- predeployment testing of
- * an application should indicate the
- * required mbuf pool size.
- * XXX: Should there be a panic if a task is stuck in the loop for
- * more than a minute or so?
- */
-int
-m_mballoc (int nmb, int nowait)
-{
- if (nowait)
- return 0;
- m_reclaim ();
- if (mmbfree == NULL) {
- int try = 0;
- int print_limit = 30 * rtems_bsdnet_ticks_per_second;
-
- mbstat.m_wait++;
- for (;;) {
- rtems_bsdnet_semaphore_release ();
- rtems_task_wake_after (1);
- rtems_bsdnet_semaphore_obtain ();
- if (mmbfree)
- break;
- if (++try >= print_limit) {
- printf ("Still waiting for mbuf.\n");
- try = 0;
- }
- }
- }
- else {
- mbstat.m_drops++;
- }
- return 1;
-}
-
-int
-m_clalloc(ncl, nowait)
-{
- if (nowait)
- return 0;
- m_reclaim ();
- if (mclfree == NULL) {
- int try = 0;
- int print_limit = 30 * rtems_bsdnet_ticks_per_second;
-
- mbstat.m_wait++;
- for (;;) {
- rtems_bsdnet_semaphore_release ();
- rtems_task_wake_after (1);
- rtems_bsdnet_semaphore_obtain ();
- if (mclfree)
- break;
- if (++try >= print_limit) {
- printf ("Still waiting for mbuf cluster.\n");
- try = 0;
- }
- }
- }
- else {
- mbstat.m_drops++;
- }
- return 1;
-}
diff --git a/c/src/libnetworking/rtems/rtems_select.c b/c/src/libnetworking/rtems/rtems_select.c
deleted file mode 100644
index 9a58456e00..0000000000
--- a/c/src/libnetworking/rtems/rtems_select.c
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * $Id$
- */
-
-#include <string.h>
-#include <stdarg.h>
-/* #include <stdlib.h> */
-#include <stdio.h>
-
-#include <rtems.h>
-#include <rtems/libio.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-
-#include <sys/errno.h>
-#include <sys/fcntl.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/protosw.h>
-#include <sys/proc.h>
-#include <sys/filio.h>
-
-#include <net/if.h>
-#include <net/route.h>
-
-/*
- *********************************************************************
- * RTEMS implementation of select() system call *
- *********************************************************************
- */
-
-/*
- * This implementation is quite restricted:
- * Works on sockets only -- no support for other devices!
- * A given socket can be in a read-select or a read/recv* by only
- * one task at a time.
- * A given socket can be in a write-select or a write/send* by only
- * one task at a time.
- *
- * NOTE - select() is a very expensive system call. It should be avoided
- * if at all possible. In many cases, rewriting the application
- * to use multiple tasks (one per socket) is a better solution.
- */
-
-static __inline int imin(int a, int b) { return (a < b ? a : b); }
-struct socket *rtems_bsdnet_fdToSocket(int fd);
-
-static int
-socket_select (struct socket *so, int which, rtems_id tid)
-{
- switch (which) {
-
- case FREAD:
- if (soreadable(so))
- return (1);
- so->so_rcv.sb_flags |= SB_WAIT;
- so->so_rcv.sb_sel.si_pid = tid;
- break;
-
- case FWRITE:
- if (sowriteable(so))
- return (1);
- so->so_rcv.sb_flags |= SB_WAIT;
- so->so_snd.sb_sel.si_pid = tid;
- break;
-
- case 0:
- if (so->so_oobmark || (so->so_state & SS_RCVATMARK))
- return (1);
- so->so_rcv.sb_sel.si_pid = tid;
- break;
- }
- return (0);
-}
-
-static int
-selscan (rtems_id tid, fd_mask **ibits, fd_mask **obits, int nfd, int *retval)
-{
- struct socket *so;
- int msk, i, fd;
- fd_mask bits, bit;
- int n = 0;
- static int flag[3] = { FREAD, FWRITE, 0 };
-
- for (msk = 0; msk < 3; msk++) {
- if (ibits[msk] == NULL)
- continue;
- for (i = 0; i < nfd; i += NFDBITS) {
- bits = ibits[msk][i/NFDBITS];
- for (fd = i, bit = 1 ; bits && (fd < nfd) ; fd++, bit <<= 1) {
- if ((bits & bit) == 0)
- continue;
- bits &= ~bit;
- so = rtems_bsdnet_fdToSocket (fd);
- if (so == NULL)
- return (EBADF);
- if (socket_select (so, flag[msk], tid)) {
- obits[msk][fd/NFDBITS] |=
- (1 << (fd % NFDBITS));
- n++;
- }
- }
- }
- }
- *retval = n;
- return (0);
-}
-
-int
-select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *tv)
-{
- fd_mask *ibits[3], *obits[3];
- fd_set ob[3];
- int error, timo;
- int retval;
- rtems_id tid;
- rtems_interval then, now;
- rtems_event_set events;
-
- if (nfds < 0)
- return (EINVAL);
- if (tv) {
- timo = tv->tv_sec * hz + tv->tv_usec / tick;
- if (timo == 0)
- timo = 1;
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &then);
- }
- else {
- timo = 0;
- }
-
-#define getbits(name,i) if (name) { \
- ibits[i] = &name->fds_bits[0]; \
- obits[i] = &ob[i].fds_bits[0]; \
- FD_ZERO(&ob[i]); \
- } \
- else ibits[i] = NULL
- getbits (readfds, 0);
- getbits (writefds, 1);
- getbits (exceptfds, 2);
-#undef getbits
-
- rtems_task_ident (RTEMS_SELF, 0, &tid);
- rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_NO_WAIT, RTEMS_NO_TIMEOUT, &events);
- for (;;) {
- rtems_bsdnet_semaphore_obtain ();
- error = selscan(tid, ibits, obits, nfds, &retval);
- rtems_bsdnet_semaphore_release ();
- if (error || retval)
- break;
- if (timo) {
- rtems_clock_get (RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now);
- timo -= now - then;
- if (timo <= 0)
- break;
- then = now;
- }
- rtems_event_receive (SBWAIT_EVENT, RTEMS_EVENT_ANY | RTEMS_WAIT, timo, &events);
- }
-
-#define putbits(name,i) if (name) *name = ob[i]
- putbits (readfds, 0);
- putbits (writefds, 1);
- putbits (exceptfds, 2);
-#undef putbits
- if (error) {
- errno = error;
- retval = -1;
- }
- return (retval);
-}
diff --git a/c/src/libnetworking/rtems/rtems_showicmpstat.c b/c/src/libnetworking/rtems/rtems_showicmpstat.c
deleted file mode 100644
index 1faea2512b..0000000000
--- a/c/src/libnetworking/rtems/rtems_showicmpstat.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/mbuf.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h>
-#include <netinet/icmp_var.h>
-
-/*
- * Display ICMP statistics
- * Don't lock the rest of the network tasks out while printing.
- * It's no big deal if the values change while being printed.
- */
-static void
-showicmpstat (const char *name, unsigned long n)
-{
- if (n)
- printf ("%35s%12lu\n", name, n);
-}
-
-void
-rtems_bsdnet_show_icmp_stats (void)
-{
- int i;
- char cbuf[20];
-
- printf ("************ ICMP Statistics ************\n");
- showicmpstat ("Calls to icmp_error()", icmpstat.icps_error);
- showicmpstat ("Errors not sent -- old was icmp", icmpstat.icps_oldicmp);
- for (i = 0 ; i <= ICMP_MAXTYPE ; i++) {
- if (icmpstat.icps_outhist[i]) {
- sprintf (cbuf, "Type %d sent", i);
- showicmpstat (cbuf, icmpstat.icps_outhist[i]);
- }
- }
- showicmpstat ("icmp_code out of range", icmpstat.icps_badcode);
- showicmpstat ("packet < ICMP_MINLEN", icmpstat.icps_tooshort);
- showicmpstat ("bad checksum", icmpstat.icps_checksum);
- showicmpstat ("calculated bound mismatch", icmpstat.icps_badlen);
- showicmpstat ("number of responses", icmpstat.icps_reflect);
- showicmpstat ("b/mcast echo requests dropped", icmpstat.icps_bmcastecho);
- showicmpstat ("b/mcast tstamp requests dropped", icmpstat.icps_bmcasttstamp);
- for (i = 0 ; i <= ICMP_MAXTYPE ; i++) {
- if (icmpstat.icps_inhist[i]) {
- sprintf (cbuf, "Type %d received", i);
- showicmpstat (cbuf, icmpstat.icps_inhist[i]);
- }
- }
-
- printf ("\n");
-}
diff --git a/c/src/libnetworking/rtems/rtems_showifstat.c b/c/src/libnetworking/rtems/rtems_showifstat.c
deleted file mode 100644
index 20055517f6..0000000000
--- a/c/src/libnetworking/rtems/rtems_showifstat.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/socket.h>
-#include <sys/ioctl.h>
-#include <net/if.h>
-#include <netinet/in.h>
-
-/*
- * Display an address
- */
-static int
-showaddress (char *name, struct sockaddr *a)
-{
- struct sockaddr_in *sa;
-
- if (!a || (a->sa_family != AF_INET))
- return 0;
- printf ("%s:", name);
- sa = (struct sockaddr_in *)a;
- printf ("%-16s", inet_ntoa (sa->sin_addr));
- return 1;
-}
-
-/*
- * Display interface statistics
- */
-void
-rtems_bsdnet_show_if_stats (void)
-{
- struct ifnet *ifp;
- struct ifaddr *ifa;
- unsigned short bit, flags;
- int printed;
-
- printf ("************ INTERFACE STATISTICS ************\n");
- for (ifp = ifnet; ifp; ifp = ifp->if_next) {
- printf ("***** %s%d *****\n", ifp->if_name, ifp->if_unit);
- for (ifa = ifp->if_addrlist ; ifa ; ifa = ifa->ifa_next) {
- printed = showaddress ("Address", ifa->ifa_addr);
- if (ifp->if_flags & IFF_BROADCAST)
- printed |= showaddress ("Broadcast Address", ifa->ifa_broadaddr);
- if (ifp->if_flags & IFF_POINTOPOINT)
- printed |= showaddress ("Destination Address", ifa->ifa_dstaddr);
- printed |= showaddress ("Net mask", ifa->ifa_netmask);
- if (printed)
- printf ("\n");
- }
-
- printf ("Flags:");
- for (bit = 1, flags = ifp->if_flags ; flags ; bit <<= 1) {
- char *cp;
- char xbuf[20];
- switch (flags & bit) {
- case 0: cp = NULL; break;
- case IFF_UP: cp = "Up"; break;
- case IFF_BROADCAST: cp = "Broadcast"; break;
- case IFF_DEBUG: cp = "Debug"; break;
- case IFF_LOOPBACK: cp = "Loopback"; break;
- case IFF_POINTOPOINT: cp = "Point-to-point"; break;
- case IFF_RUNNING: cp = "Running"; break;
- case IFF_NOARP: cp = "No-ARP"; break;
- case IFF_PROMISC: cp = "Promiscuous"; break;
- case IFF_ALLMULTI: cp = "All-multicast"; break;
- case IFF_OACTIVE: cp = "Active"; break;
- case IFF_SIMPLEX: cp = "Simplex"; break;
- case IFF_LINK0: cp = "Link0"; break;
- case IFF_LINK1: cp = "Link1"; break;
- case IFF_LINK2: cp = "Link2"; break;
- case IFF_MULTICAST: cp = "Multicast"; break;
- default: sprintf (xbuf, "%#x", bit); cp = xbuf; break;
- }
- if (cp) {
- flags &= ~bit;
- printf (" %s", cp);
- }
- }
- printf ("\n");
-
- printf ("Send queue limit:%-4d length:%-4d Dropped:%-8d\n",
- ifp->if_snd.ifq_maxlen,
- ifp->if_snd.ifq_len,
- ifp->if_snd.ifq_drops);
-
- /*
- * FIXME: Could print if_data statistics here,
- * but right now the drivers maintain their
- * own statistics.
- */
-
- /*
- * Grab the network semaphore.
- * In most cases this is not necessary, but it's
- * easier to always call the driver ioctl function
- * while holding the semaphore than to try
- * and explain why some ioctl commands are invoked
- * while holding the semaphore and others are
- * invoked while not holding the semaphore.
- */
- rtems_bsdnet_semaphore_obtain ();
- (*ifp->if_ioctl)(ifp, SIO_RTEMS_SHOW_STATS, NULL);
- rtems_bsdnet_semaphore_release ();
- }
- printf ("\n");
-}
diff --git a/c/src/libnetworking/rtems/rtems_showipstat.c b/c/src/libnetworking/rtems/rtems_showipstat.c
deleted file mode 100644
index 2dd499a8c0..0000000000
--- a/c/src/libnetworking/rtems/rtems_showipstat.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/mbuf.h>
-#include <netinet/in_systm.h>
-#include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-
-/*
- * Display IP statistics
- * Don't lock the rest of the network tasks out while printing.
- * It's no big deal if the values change while being printed.
- */
-static void
-showipstat (const char *name, unsigned long n)
-{
- if (n)
- printf ("%35s%12lu\n", name, n);
-}
-
-void
-rtems_bsdnet_show_ip_stats (void)
-{
- printf ("************ IP Statistics ************\n");
- showipstat ("total packets received", ipstat.ips_total);
- showipstat ("checksum bad", ipstat.ips_badsum);
- showipstat ("packet too short", ipstat.ips_tooshort);
- showipstat ("not enough data", ipstat.ips_toosmall);
- showipstat ("ip header length < data size", ipstat.ips_badhlen);
- showipstat ("ip length < ip header length", ipstat.ips_badlen);
- showipstat ("fragments received", ipstat.ips_fragments);
- showipstat ("frags dropped (dups, out of space)", ipstat.ips_fragdropped);
- showipstat ("fragments timed out", ipstat.ips_fragtimeout);
- showipstat ("packets forwarded", ipstat.ips_forward);
- showipstat ("packets rcvd for unreachable dest", ipstat.ips_cantforward);
- showipstat ("packets forwarded on same net", ipstat.ips_redirectsent);
- showipstat ("unknown or unsupported protocol", ipstat.ips_noproto);
- showipstat ("datagrams delivered to upper level", ipstat.ips_delivered);
- showipstat ("total ip packets generated here", ipstat.ips_localout);
- showipstat ("lost packets due to nobufs, etc.", ipstat.ips_odropped);
- showipstat ("total packets reassembled ok", ipstat.ips_reassembled);
- showipstat ("datagrams successfully fragmented", ipstat.ips_fragmented);
- showipstat ("output fragments created", ipstat.ips_ofragments);
- showipstat ("don't fragment flag was set, etc.", ipstat.ips_cantfrag);
- showipstat ("error in option processing", ipstat.ips_badoptions);
- showipstat ("packets discarded due to no route", ipstat.ips_noroute);
- showipstat ("ip version != 4", ipstat.ips_badvers);
- showipstat ("total raw ip packets generated", ipstat.ips_rawout);
- showipstat ("ip length > max ip packet size", ipstat.ips_toolong);
- printf ("\n");
-}
diff --git a/c/src/libnetworking/rtems/rtems_showmbuf.c b/c/src/libnetworking/rtems/rtems_showmbuf.c
deleted file mode 100644
index 39523bd00a..0000000000
--- a/c/src/libnetworking/rtems/rtems_showmbuf.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/mbuf.h>
-
-/*
- * Display MBUF statistics
- * Don't lock the rest of the network tasks out while printing.
- * It's no big deal if the values change while being printed.
- */
-void
-rtems_bsdnet_show_mbuf_stats (void)
-{
- int i;
- int printed = 0;
- char *cp;
-
- printf ("************ MBUF STATISTICS ************\n");
- printf ("mbufs:%4lu clusters:%4lu free:%4lu\n",
- mbstat.m_mbufs, mbstat.m_clusters, mbstat.m_clfree);
- printf ("drops:%4lu waits:%4lu drains:%4lu\n",
- mbstat.m_drops, mbstat.m_wait, mbstat.m_drain);
- for (i = 0 ; i < 20 ; i++) {
- switch (i) {
- case MT_FREE: cp = "free"; break;
- case MT_DATA: cp = "data"; break;
- case MT_HEADER: cp = "header"; break;
- case MT_SOCKET: cp = "socket"; break;
- case MT_PCB: cp = "pcb"; break;
- case MT_RTABLE: cp = "rtable"; break;
- case MT_HTABLE: cp = "htable"; break;
- case MT_ATABLE: cp = "atable"; break;
- case MT_SONAME: cp = "soname"; break;
- case MT_SOOPTS: cp = "soopts"; break;
- case MT_FTABLE: cp = "ftable"; break;
- case MT_RIGHTS: cp = "rights"; break;
- case MT_IFADDR: cp = "ifaddr"; break;
- case MT_CONTROL: cp = "control"; break;
- case MT_OOBDATA: cp = "oobdata"; break;
- default: cp = NULL; break;
- }
- if ((cp != NULL) || (mbstat.m_mtypes[i] != 0)) {
- char cbuf[16];
- if (cp == NULL) {
- sprintf (cbuf, "Type %d", i);
- cp = cbuf;
- }
- printf ("%10s:%-8u", cp, mbstat.m_mtypes[i]);
- if (++printed == 4) {
- printf ("\n");
- printed = 0;
- }
- }
- }
- if (printed)
- printf ("\n");
- printf ("\n");
-}
diff --git a/c/src/libnetworking/rtems/rtems_showroute.c b/c/src/libnetworking/rtems/rtems_showroute.c
deleted file mode 100644
index c0d0b231e8..0000000000
--- a/c/src/libnetworking/rtems/rtems_showroute.c
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/domain.h>
-
-#include <net/if.h>
-#include <net/if_dl.h>
-#include <net/route.h>
-
-#include <netinet/in.h>
-
-#include <arpa/inet.h>
-
-/*
- * We'll use the application versions of realloc and free.
- */
-#undef free
-#undef malloc
-#include <stdlib.h>
-
-/*
- * Information per route
- */
-struct rinfo {
- struct sockaddr dst;
- union {
- struct sockaddr sa;
- struct sockaddr_in sin;
- struct sockaddr_dl sdl;
- } un;
- unsigned long pksent;
- unsigned long expire;
- int flags;
- char ifname[16];
- short ifunit;
- short refcnt;
-};
-
-/*
- * Information per display
- */
-struct dinfo {
- int capacity;
- int count;
- struct rinfo *routes;
-};
-
-/*
- * Copy address
- */
-static void
-copyAddress (void *to, void *from, int tolen)
-{
- int ncopy;
- struct sockaddr dummy;
-
- if (from == NULL) {
- /*
- * Create a fake address of unspecified type
- */
- from = &dummy;
- dummy.sa_len = 4;
- dummy.sa_family = AF_UNSPEC;
- }
- ncopy = ((struct sockaddr *)from)->sa_len;
- if (ncopy > tolen)
- ncopy = tolen;
- memcpy (to, from, ncopy);
-}
-
-/*
- * Package everything up before printing it.
- * We don't want to block all network operations till
- * the printing completes!
- */
-static int
-show_inet_route (rn, vw)
- struct radix_node *rn;
- void *vw;
-{
- struct rtentry *rt = (struct rtentry *)rn;
- struct ifnet *ifp;
- struct dinfo *dp = (struct dinfo *)vw;
- struct rinfo *r;
-
- /*
- * Get a pointer to a new route info structure
- */
- if (dp->count >= dp->capacity) {
- r = realloc (dp->routes, (sizeof *r) * (dp->capacity + 20));
- if (r == 0)
- return ENOMEM;
- dp->capacity += 20;
- dp->routes = r;
- }
- r = dp->routes + dp->count++;
-
- /*
- * Fill in the route info structure
- */
- copyAddress (&r->dst, rt_key(rt), sizeof r->dst);
- if (rt->rt_flags & (RTF_GATEWAY | RTF_HOST)) {
- copyAddress (&r->un, rt->rt_gateway, sizeof r->un);
- }
- else {
- /*
- * Create a fake address to hold the mask
- */
- struct sockaddr_in dummy;
-
- dummy.sin_family = AF_INET;
- dummy.sin_len = sizeof dummy;
- dummy.sin_addr = ((struct sockaddr_in *)rt_mask(rt))->sin_addr;
- copyAddress (&r->un, &dummy, sizeof r->un);
- }
- r->flags = rt->rt_flags;
- r->refcnt = rt->rt_refcnt;
- r->pksent = rt->rt_rmx.rmx_pksent;
- r->expire = rt->rt_rmx.rmx_expire;
- ifp = rt->rt_ifp;
- strncpy (r->ifname, ifp->if_name, sizeof r->ifname);
- r->ifunit = ifp->if_unit;
- return 0;
-}
-
-/*
- * Convert link address to ASCII
- */
-static char *
-link_ascii (struct sockaddr_dl *sdl, char *buf, int bufsize)
-{
- char *cp;
- int i;
- int first = 1;
- int nleft = sdl->sdl_alen;
- unsigned char *ap = LLADDR (sdl);
- static const char hextab[16] = "0123456789ABCDEF";
-
- cp = buf;
- while (nleft && (bufsize > 4)) {
- if (first) {
- first = 0;
- }
- else {
- *cp++ = ':';
- bufsize--;
- }
- i = *ap++;
- *cp++ = hextab[(i >> 4) & 0xf];
- *cp++ = hextab[i & 0xf];
- nleft--;
- bufsize -= 2;
- }
- *cp = '\0';
- return buf;
-}
-
-void
-rtems_bsdnet_show_inet_routes (void)
-{
- struct radix_node_head *rnh;
- struct dinfo d;
- struct rinfo *r;
- int i, error;
-
- /*
- * For now we'll handle only AF_INET
- */
- rnh = rt_tables[AF_INET];
- if (!rnh)
- return;
- d.count = d.capacity = 0;
- d.routes = NULL;
- rtems_bsdnet_semaphore_obtain ();
- error = rnh->rnh_walktree(rnh, show_inet_route, &d);
- rtems_bsdnet_semaphore_release ();
- if (error) {
- printf ("Can't get route info: %s\n", strerror (error));
- return;
- }
- if (d.count == 0) {
- printf ("No routes!\n");
- return;
- }
- printf ("Destination Gateway/Mask/Hw Flags Refs Use Expire Interface\n");
- for (i = 0, r = d.routes ; i < d.count ; i++, r++) {
- char buf[30];
- char *cp, *fc, flagbuf[10];
- const char *addr;
- unsigned long flagbit;
- struct sockaddr_in *sin;
-
- sin = (struct sockaddr_in *)&r->dst;
- if (sin->sin_addr.s_addr == INADDR_ANY)
- addr = "default";
- else
- addr = inet_ntop (AF_INET, &sin->sin_addr, buf, sizeof buf);
- printf ("%-16s", addr);
- switch (r->un.sa.sa_family) {
- case AF_INET:
- addr = inet_ntop (AF_INET, &r->un.sin.sin_addr, buf, sizeof buf);
- break;
-
- case AF_LINK:
- addr = link_ascii (&r->un.sdl, buf, sizeof buf);
- break;
-
- default:
- addr = "";
- break;
- }
- printf ("%-19s", addr);
- fc = "UGHRDM XLS";
- for (flagbit = 0x1, cp = flagbuf ; *fc ; flagbit <<= 1, fc++) {
- if ((r->flags & flagbit) && (*fc != ' '))
- *cp++ = *fc;
- }
- *cp = '\0';
- printf ("%-10s%3d%9ld%7ld %.*s%d\n", flagbuf,
- r->refcnt, r->pksent,
- r->expire,
- (int)sizeof r->ifname, r->ifname,
- r->ifunit);
- }
- free (d.routes);
-}
diff --git a/c/src/libnetworking/rtems/rtems_showtcpstat.c b/c/src/libnetworking/rtems/rtems_showtcpstat.c
deleted file mode 100644
index b9a0366819..0000000000
--- a/c/src/libnetworking/rtems/rtems_showtcpstat.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/tcp.h>
-#include <netinet/tcp_timer.h>
-#include <netinet/tcp_seq.h>
-#include <netinet/tcp_var.h>
-
-/*
- * Display TCP statistics
- * Don't lock the rest of the network tasks out while printing.
- * It's no big deal if the values change while being printed.
- */
-static void
-showtcpstat (const char *name, unsigned long n)
-{
- if (n)
- printf ("%35s%12lu\n", name, n);
-}
-
-void
-rtems_bsdnet_show_tcp_stats (void)
-{
- printf ("************ TCP Statistics ************\n");
- showtcpstat ("connections initiated", tcpstat.tcps_connattempt);
- showtcpstat ("connections accepted", tcpstat.tcps_accepts);
- showtcpstat ("connections established", tcpstat.tcps_connects);
- showtcpstat ("connections dropped", tcpstat.tcps_drops);
- showtcpstat ("embryonic connections dropped", tcpstat.tcps_conndrops);
- showtcpstat ("conn. closed (includes drops)", tcpstat.tcps_closed);
- showtcpstat ("segs where we tried to get rtt", tcpstat.tcps_segstimed);
- showtcpstat ("times we succeeded", tcpstat.tcps_rttupdated);
- showtcpstat ("delayed acks sent", tcpstat.tcps_delack);
- showtcpstat ("conn. dropped in rxmt timeout", tcpstat.tcps_timeoutdrop);
- showtcpstat ("retransmit timeouts", tcpstat.tcps_rexmttimeo);
- showtcpstat ("persist timeouts", tcpstat.tcps_persisttimeo);
- showtcpstat ("keepalive timeouts", tcpstat.tcps_keeptimeo);
- showtcpstat ("keepalive probes sent", tcpstat.tcps_keepprobe);
- showtcpstat ("connections dropped in keepalive", tcpstat.tcps_keepdrops);
-
- showtcpstat ("total packets sent", tcpstat.tcps_sndtotal);
- showtcpstat ("data packets sent", tcpstat.tcps_sndpack);
- showtcpstat ("data bytes sent", tcpstat.tcps_sndbyte);
- showtcpstat ("data packets retransmitted", tcpstat.tcps_sndrexmitpack);
- showtcpstat ("data bytes retransmitted", tcpstat.tcps_sndrexmitbyte);
- showtcpstat ("ack-only packets sent", tcpstat.tcps_sndacks);
- showtcpstat ("window probes sent", tcpstat.tcps_sndprobe);
- showtcpstat ("packets sent with URG only", tcpstat.tcps_sndurg);
- showtcpstat ("window update-only packets sent", tcpstat.tcps_sndwinup);
- showtcpstat ("control (SYN|FIN|RST) packets sent", tcpstat.tcps_sndctrl);
-
- showtcpstat ("total packets received", tcpstat.tcps_rcvtotal);
- showtcpstat ("packets received in sequence", tcpstat.tcps_rcvpack);
- showtcpstat ("bytes received in sequence", tcpstat.tcps_rcvbyte);
- showtcpstat ("packets received with ccksum errs", tcpstat.tcps_rcvbadsum);
- showtcpstat ("packets received with bad offset", tcpstat.tcps_rcvbadoff);
- showtcpstat ("packets received too short", tcpstat.tcps_rcvshort);
- showtcpstat ("duplicate-only packets received", tcpstat.tcps_rcvduppack);
- showtcpstat ("duplicate-only bytes received", tcpstat.tcps_rcvdupbyte);
- showtcpstat ("packets with some duplicate data", tcpstat.tcps_rcvpartduppack);
- showtcpstat ("dup. bytes in part-dup. packets", tcpstat.tcps_rcvpartdupbyte);
- showtcpstat ("out-of-order packets received", tcpstat.tcps_rcvoopack);
- showtcpstat ("out-of-order bytes received", tcpstat.tcps_rcvoobyte);
- showtcpstat ("packets with data after window", tcpstat.tcps_rcvpackafterwin);
- showtcpstat ("bytes rcvd after window", tcpstat.tcps_rcvbyteafterwin);
- showtcpstat ("packets rcvd after \"close\"", tcpstat.tcps_rcvafterclose);
- showtcpstat ("rcvd window probe packets", tcpstat.tcps_rcvwinprobe);
- showtcpstat ("rcvd duplicate acks", tcpstat.tcps_rcvdupack);
- showtcpstat ("rcvd acks for unsent data", tcpstat.tcps_rcvacktoomuch);
- showtcpstat ("rcvd ack packets", tcpstat.tcps_rcvackpack);
- showtcpstat ("bytes acked by rcvd acks", tcpstat.tcps_rcvackbyte);
- showtcpstat ("rcvd window update packets", tcpstat.tcps_rcvwinupd);
- showtcpstat ("segments dropped due to PAWS", tcpstat.tcps_pawsdrop);
- showtcpstat ("times hdr predict ok for acks", tcpstat.tcps_predack);
- showtcpstat ("times hdr predict ok for data pkts", tcpstat.tcps_preddat);
- showtcpstat ("pcb cache misses", tcpstat.tcps_pcbcachemiss);
- showtcpstat ("times cached RTT in route updated", tcpstat.tcps_cachedrtt);
- showtcpstat ("times cached rttvar updated", tcpstat.tcps_cachedrttvar);
- showtcpstat ("times cached ssthresh updated", tcpstat.tcps_cachedssthresh);
- showtcpstat ("times RTT initialized from route", tcpstat.tcps_usedrtt);
- showtcpstat ("times RTTVAR initialized from rt", tcpstat.tcps_usedrttvar);
- showtcpstat ("times ssthresh initialized from rt", tcpstat.tcps_usedssthresh);
- showtcpstat ("timeout in persist state", tcpstat.tcps_persistdrop);
- showtcpstat ("bogus SYN, e.g. premature ACK", tcpstat.tcps_badsyn);
- showtcpstat ("resends due to MTU discovery", tcpstat.tcps_mturesent);
- showtcpstat ("listen queue overflows", tcpstat.tcps_listendrop);
- printf ("\n");
-}
diff --git a/c/src/libnetworking/rtems/rtems_showudpstat.c b/c/src/libnetworking/rtems/rtems_showudpstat.c
deleted file mode 100644
index 1fc2d15a0b..0000000000
--- a/c/src/libnetworking/rtems/rtems_showudpstat.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * $Id$
- */
-
-#include <sys/param.h>
-#include <sys/queue.h>
-#include <sys/systm.h>
-#include <sys/kernel.h>
-#include <sys/sysctl.h>
-#include <sys/proc.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_var.h>
-#include <netinet/udp.h>
-#include <netinet/udp_var.h>
-
-/*
- * Display UDP statistics
- * Don't lock the rest of the network tasks out while printing.
- * It's no big deal if the values change while being printed.
- */
-static void
-showudpstat (const char *name, unsigned long n)
-{
- if (n)
- printf ("%35s%12lu\n", name, n);
-}
-
-void
-rtems_bsdnet_show_udp_stats (void)
-{
- printf ("************ UDP Statistics ************\n");
- showudpstat ("total input packets", udpstat.udps_ipackets);
- showudpstat ("packet shorter than header", udpstat.udps_hdrops);
- showudpstat ("checksum error", udpstat.udps_badsum);
- showudpstat ("data length larger than packet", udpstat.udps_badlen);
- showudpstat ("no socket on port", udpstat.udps_noport);
- showudpstat ("of above, arrived as broadcast", udpstat.udps_noportbcast);
- showudpstat ("not delivered, input socket full", udpstat.udps_fullsock);
- showudpstat ("input packets missing pcb cache", udpstat.udpps_pcbcachemiss);
- showudpstat ("input packets not for hashed pcb", udpstat.udpps_pcbhashmiss);
- showudpstat ("total output packets", udpstat.udps_opackets);
- printf ("\n");
-}
diff --git a/c/src/libnetworking/rtems/rtems_syscall.c b/c/src/libnetworking/rtems/rtems_syscall.c
deleted file mode 100644
index acba1f8322..0000000000
--- a/c/src/libnetworking/rtems/rtems_syscall.c
+++ /dev/null
@@ -1,763 +0,0 @@
-/*
- * $Id$
- */
-
-#include <string.h>
-#include <stdarg.h>
-/* #include <stdlib.h> */
-#include <stdio.h>
-
-#include <rtems.h>
-#include <rtems/libio.h>
-#include <rtems/error.h>
-#include <rtems/rtems_bsdnet.h>
-
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <sys/protosw.h>
-#include <sys/proc.h>
-#include <sys/fcntl.h>
-#include <sys/filio.h>
-
-#include <net/if.h>
-#include <net/route.h>
-
-/*
- * Hooks to RTEMS I/O system
- */
-static const rtems_filesystem_file_handlers_r socket_handlers;
-int rtems_bsdnet_makeFdForSocket(void *so, const rtems_filesystem_file_handlers_r *h);
-struct socket *rtems_bsdnet_fdToSocket(int fd);
-
-/*
- * Package system call argument into mbuf.
- */
-static int
-sockargstombuf (struct mbuf **mp, const void *buf, int buflen, int type)
-{
- struct mbuf *m;
-
- if ((u_int)buflen > MLEN)
- return (EINVAL);
- m = m_get(M_WAIT, type);
- if (m == NULL)
- return (ENOBUFS);
- m->m_len = buflen;
- memcpy (mtod(m, caddr_t), buf, buflen);
- *mp = m;
- if (type == MT_SONAME) {
- struct sockaddr *sa;
- sa = mtod(m, struct sockaddr *);
- sa->sa_len = buflen;
- }
- return 0;
-}
-
-/*
- *********************************************************************
- * BSD-style entry points *
- *********************************************************************
- */
-int
-socket (int domain, int type, int protocol)
-{
- int fd;
- int error;
- struct socket *so;
-
- rtems_bsdnet_semaphore_obtain ();
- error = socreate(domain, &so, type, protocol, NULL);
- if (error == 0) {
- fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
- if (fd < 0)
- soclose (so);
- }
- else {
- errno = error;
- fd = -1;
- }
- rtems_bsdnet_semaphore_release ();
- return fd;
-}
-
-int
-bind (int s, struct sockaddr *name, int namelen)
-{
- int error;
- int ret = -1;
- struct socket *so;
- struct mbuf *nam;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
- error = sockargstombuf (&nam, name, namelen, MT_SONAME);
- if (error == 0) {
- error = sobind (so, nam);
- if (error == 0)
- ret = 0;
- else
- errno = error;
- m_freem (nam);
- }
- else {
- errno = error;
- }
- }
- rtems_bsdnet_semaphore_release ();
- return ret;
-}
-
-int
-connect (int s, struct sockaddr *name, int namelen)
-{
- int error;
- int ret = -1;
- struct socket *so;
- struct mbuf *nam;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
- errno = EALREADY;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- error = sockargstombuf (&nam, name, namelen, MT_SONAME);
- if (error) {
- errno = error;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- error = soconnect (so, nam);
- if (error)
- goto bad;
- if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
- m_freem(nam);
- errno = EINPROGRESS;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
- error = soconnsleep (so);
- if (error)
- break;
- }
- if (error == 0) {
- error = so->so_error;
- so->so_error = 0;
- }
- bad:
- so->so_state &= ~SS_ISCONNECTING;
- m_freem (nam);
- if (error)
- errno = error;
- else
- ret = 0;
- rtems_bsdnet_semaphore_release ();
- return ret;
-}
-
-int
-listen (int s, int backlog)
-{
- int error;
- int ret = -1;
- struct socket *so;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) != NULL) {
- error = solisten (so, backlog);
- if (error == 0)
- ret = 0;
- else
- errno = error;
- }
- rtems_bsdnet_semaphore_release ();
- return ret;
-}
-
-int
-accept (int s, struct sockaddr *name, int *namelen)
-{
- int fd;
- struct socket *head, *so;
- struct mbuf *nam;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((head = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if ((head->so_options & SO_ACCEPTCONN) == 0) {
- errno = EINVAL;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if ((head->so_state & SS_NBIO) && head->so_comp.tqh_first == NULL) {
- errno = EWOULDBLOCK;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- while (head->so_comp.tqh_first == NULL && head->so_error == 0) {
- if (head->so_state & SS_CANTRCVMORE) {
- head->so_error = ECONNABORTED;
- break;
- }
- head->so_error = soconnsleep (head);
- }
- if (head->so_error) {
- errno = head->so_error;
- head->so_error = 0;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
-
- so = head->so_comp.tqh_first;
- TAILQ_REMOVE(&head->so_comp, so, so_list);
- head->so_qlen--;
-
- fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
- if (fd < 0) {
- TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
- head->so_qlen++;
- soconnwakeup (head);
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- so->so_state &= ~SS_COMP;
- so->so_head = NULL;
-
- nam = m_get(M_WAIT, MT_SONAME);
- (void) soaccept(so, nam);
- if (name) {
- /* check length before it is destroyed */
- if (*namelen > nam->m_len)
- *namelen = nam->m_len;
- memcpy (name, mtod(nam, caddr_t), *namelen);
- }
- m_freem(nam);
- rtems_bsdnet_semaphore_release ();
- return (fd);
-
-}
-
-/*
- * Shutdown routine
- */
-
-int
-shutdown (int s, int how)
-{
- struct socket *so;
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- error = soshutdown(so, how);
- rtems_bsdnet_semaphore_release ();
- if (error) {
- errno = error;
- return -1;
- }
- return 0;
-}
-
-/*
- * All `transmit' operations end up calling this routine.
- */
-ssize_t
-sendmsg (int s, const struct msghdr *mp, int flags)
-{
- int ret = -1;
- int error;
- struct uio auio;
- struct iovec *iov;
- struct socket *so;
- struct mbuf *to, *control;
- int i;
- int len;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- auio.uio_iov = mp->msg_iov;
- auio.uio_iovcnt = mp->msg_iovlen;
- auio.uio_segflg = UIO_USERSPACE;
- auio.uio_rw = UIO_WRITE;
- auio.uio_offset = 0;
- auio.uio_resid = 0;
- iov = mp->msg_iov;
- for (i = 0; i < mp->msg_iovlen; i++, iov++) {
- if ((auio.uio_resid += iov->iov_len) < 0) {
- errno = EINVAL;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- }
- if (mp->msg_name) {
- error = sockargstombuf (&to, mp->msg_name, mp->msg_namelen, MT_SONAME);
- if (error) {
- errno = error;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- }
- else {
- to = NULL;
- }
- if (mp->msg_control) {
- if (mp->msg_controllen < sizeof (struct cmsghdr)) {
- errno = EINVAL;
- if (to)
- m_freem(to);
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- sockargstombuf (&control, mp->msg_control, mp->msg_controllen, MT_CONTROL);
- }
- else {
- control = NULL;
- }
- len = auio.uio_resid;
- error = sosend (so, to, &auio, (struct mbuf *)0, control, flags);
- if (error) {
- if (auio.uio_resid != len && (error == EINTR || error == EWOULDBLOCK))
- error = 0;
- }
- if (error)
- errno = error;
- else
- ret = len - auio.uio_resid;
- if (to)
- m_freem(to);
- rtems_bsdnet_semaphore_release ();
- return (ret);
-}
-
-/*
- * Send a message to a host
- */
-ssize_t
-sendto (int s, const void *buf, size_t buflen, int flags, const struct sockaddr *to, int tolen)
-{
- struct msghdr msg;
- struct iovec iov;
-
- iov.iov_base = (void *)buf;
- iov.iov_len = buflen;
- msg.msg_name = (caddr_t)to;
- msg.msg_namelen = tolen;
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- return sendmsg (s, &msg, flags);
-}
-
-/*
- * Send a message to a connected host
- */
-ssize_t
-send (int s, const void *buf, size_t buflen, int flags)
-{
- return sendto (s, buf, buflen, flags, NULL, 0);
-}
-
-/*
- * All `receive' operations end up calling this routine.
- */
-ssize_t
-recvmsg (int s, struct msghdr *mp, int flags)
-{
- int ret = -1;
- int error;
- struct uio auio;
- struct iovec *iov;
- struct socket *so;
- struct mbuf *from = NULL, *control = NULL;
- int i;
- int len;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- auio.uio_iov = mp->msg_iov;
- auio.uio_iovcnt = mp->msg_iovlen;
- auio.uio_segflg = UIO_USERSPACE;
- auio.uio_rw = UIO_READ;
- auio.uio_offset = 0;
- auio.uio_resid = 0;
- iov = mp->msg_iov;
- for (i = 0; i < mp->msg_iovlen; i++, iov++) {
- if ((auio.uio_resid += iov->iov_len) < 0) {
- errno = EINVAL;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- }
- len = auio.uio_resid;
- mp->msg_flags = flags;
- error = soreceive (so, &from, &auio, (struct mbuf **)NULL,
- mp->msg_control ? &control : (struct mbuf **)NULL,
- &mp->msg_flags);
- if (error) {
- if (auio.uio_resid != len && (error == EINTR || error == EWOULDBLOCK))
- error = 0;
- }
- if (error) {
- errno = error;
- }
- else {
- ret = len - auio.uio_resid;
- if (mp->msg_name) {
- len = mp->msg_namelen;
- if ((len <= 0) || (from == NULL)) {
- len = 0;
- }
- else {
- if (len > from->m_len)
- len = from->m_len;
- memcpy (mp->msg_name, mtod(from, caddr_t), len);
- }
- mp->msg_namelen = len;
- }
- if (mp->msg_control) {
- struct mbuf *m;
- caddr_t ctlbuf;
-
- len = mp->msg_controllen;
- m = control;
- mp->msg_controllen = 0;
- ctlbuf = (caddr_t) mp->msg_control;
-
- while (m && (len > 0)) {
- unsigned int tocopy;
-
- if (len >= m->m_len)
- tocopy = m->m_len;
- else {
- mp->msg_flags |= MSG_CTRUNC;
- tocopy = len;
- }
- memcpy(ctlbuf, mtod(m, caddr_t), tocopy);
- ctlbuf += tocopy;
- len -= tocopy;
- m = m->m_next;
- }
- mp->msg_controllen = ctlbuf - mp->msg_control;
- }
- }
- if (from)
- m_freem (from);
- if (control)
- m_freem (control);
- rtems_bsdnet_semaphore_release ();
- return (ret);
-}
-
-/*
- * Receive a message from a host
- */
-ssize_t
-recvfrom (int s, void *buf, size_t buflen, int flags, const struct sockaddr *from, int *fromlen)
-{
- struct msghdr msg;
- struct iovec iov;
- int ret;
-
- iov.iov_base = buf;
- iov.iov_len = buflen;
- msg.msg_name = (caddr_t)from;
- if (fromlen)
- msg.msg_namelen = *fromlen;
- else
- msg.msg_namelen = 0;
- msg.msg_iov = &iov;
- msg.msg_iovlen = 1;
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
- ret = recvmsg (s, &msg, flags);
- if ((from != NULL) && (fromlen != NULL) && (ret >= 0))
- *fromlen = msg.msg_namelen;
- return ret;
-}
-
-/*
- * Receive a message from a connected host
- */
-ssize_t
-recv (int s, void *buf, size_t buflen, int flags)
-{
- return recvfrom (s, buf, buflen, flags, NULL, NULL);
-}
-
-int
-setsockopt (int s, int level, int name, const void *val, int len)
-{
- struct socket *so;
- struct mbuf *m = NULL;
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if (len > MLEN) {
- errno = EINVAL;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if (val) {
- error = sockargstombuf (&m, val, len, MT_SOOPTS);
- if (error) {
- errno = error;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- }
- error = sosetopt(so, level, name, m);
- if (error) {
- errno = error;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- rtems_bsdnet_semaphore_release ();
- return 0;
-}
-
-int
-getsockopt (int s, int level, int name, void *aval, int *avalsize)
-{
- struct socket *so;
- struct mbuf *m = NULL, *m0;
- char *val = aval;
- int i, op, valsize;
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if (val)
- valsize = *avalsize;
- else
- valsize = 0;
- if (((error = sogetopt(so, level, name, &m)) == 0) && val && valsize && m) {
- op = 0;
- while (m && op < valsize) {
- i = valsize - op;
- if (i > m->m_len)
- i = m->m_len;
- memcpy (val, mtod(m, caddr_t), i);
- op += i;
- val += i;
- m0 = m;
- MFREE (m0, m);
- }
- *avalsize = op;
- }
- if (m != NULL)
- (void) m_free(m);
- if (error) {
- errno = error;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- rtems_bsdnet_semaphore_release ();
- return 0;
-}
-
-static int
-getpeersockname (int s, struct sockaddr *name, int *namelen, int pflag)
-{
- struct socket *so;
- struct mbuf *m;
- int len = *namelen;
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = rtems_bsdnet_fdToSocket (s)) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- m = m_getclr(M_WAIT, MT_SONAME);
- if (m == NULL) {
- errno = ENOBUFS;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if (pflag)
- error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, m);
- else
- error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, m);
- if (error) {
- m_freem(m);
- errno = error;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- if (len > m->m_len) {
- len = m->m_len;
- *namelen = len;
- }
- memcpy (name, mtod(m, caddr_t), len);
- m_freem (m);
- rtems_bsdnet_semaphore_release ();
- return 0;
-}
-
-int
-getpeername (int s, struct sockaddr *name, int *namelen)
-{
- return getpeersockname (s, name, namelen, 1);
-}
-int
-getsockname (int s, struct sockaddr *name, int *namelen)
-{
- return getpeersockname (s, name, namelen, 0);
-}
-
-/*
- ************************************************************************
- * RTEMS I/O HANDLER ROUTINES *
- ************************************************************************
- */
-static int
-rtems_bsdnet_close (rtems_libio_t *iop)
-{
- struct socket *so;
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = iop->data1) == NULL) {
- errno = EBADF;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- error = soclose (so);
- rtems_bsdnet_semaphore_release ();
- if (error) {
- errno = error;
- return -1;
- }
- return 0;
-}
-
-static int
-rtems_bsdnet_read (rtems_libio_t *iop, void *buffer, unsigned32 count)
-{
- return recv (iop->data0, buffer, count, 0);
-}
-
-static int
-rtems_bsdnet_write (rtems_libio_t *iop, const void *buffer, unsigned32 count)
-{
- return send (iop->data0, buffer, count, 0);
-}
-
-static int
-so_ioctl (rtems_libio_t *iop, struct socket *so, unsigned32 command, void *buffer)
-{
- switch (command) {
- case FIONBIO:
- if (*(int *)buffer) {
- iop->flags |= O_NONBLOCK;
- so->so_state |= SS_NBIO;
- }
- else {
- iop->flags &= ~O_NONBLOCK;
- so->so_state &= ~SS_NBIO;
- }
- return 0;
-
- case FIONREAD:
- *(int *)buffer = so->so_rcv.sb_cc;
- return 0;
- }
-
- if (IOCGROUP(command) == 'i')
- return ifioctl (so, command, buffer, NULL);
- if (IOCGROUP(command) == 'r')
- return rtioctl (command, buffer, NULL);
- return (*so->so_proto->pr_usrreqs->pru_control)(so, command, buffer, 0);
-}
-
-static int
-rtems_bsdnet_ioctl (rtems_libio_t *iop, unsigned32 command, void *buffer)
-{
- struct socket *so;
- int error;
-
- rtems_bsdnet_semaphore_obtain ();
- if ((so = iop->data1) == NULL) {
- errno = EBADF;
- rtems_bsdnet_semaphore_release ();
- return -1;
- }
- error = so_ioctl (iop, so, command, buffer);
- rtems_bsdnet_semaphore_release ();
- if (error) {
- errno = error;
- return -1;
- }
- return 0;
-}
-
-static int
-rtems_bsdnet_fcntl (int cmd, rtems_libio_t *iop)
-{
- struct socket *so;
-
- if (cmd == F_SETFL) {
- rtems_bsdnet_semaphore_obtain ();
- if ((so = iop->data1) == NULL) {
- rtems_bsdnet_semaphore_release ();
- return EBADF;
- }
- if (iop->flags & LIBIO_FLAGS_NO_DELAY)
- so->so_state |= SS_NBIO;
- else
- so->so_state &= ~SS_NBIO;
- rtems_bsdnet_semaphore_release ();
- }
- return 0;
-}
-
-static int
-rtems_bsdnet_fstat (rtems_filesystem_location_info_t *loc, struct stat *sp)
-{
- sp->st_mode = S_IFSOCK;
- return 0;
-}
-
-static const rtems_filesystem_file_handlers_r socket_handlers = {
- NULL, /* open */
- rtems_bsdnet_close, /* close */
- rtems_bsdnet_read, /* read */
- rtems_bsdnet_write, /* write */
- rtems_bsdnet_ioctl, /* ioctl */
- NULL, /* lseek */
- rtems_bsdnet_fstat, /* fstat */
- NULL, /* fchmod */
- NULL, /* ftruncate */
- NULL, /* fpathconf */
- NULL, /* fsync */
- NULL, /* fdatasync */
- rtems_bsdnet_fcntl, /* fcntl */
-};
diff --git a/c/src/libnetworking/rtems/sghostname.c b/c/src/libnetworking/rtems/sghostname.c
deleted file mode 100644
index 307f045fbd..0000000000
--- a/c/src/libnetworking/rtems/sghostname.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * RTEMS versions of hostname functions
- * FIXME: Not thread-safe
- *
- * $Id$
- */
-
-#include <string.h>
-#include <errno.h>
-#include <rtems/rtems_bsdnet.h>
-#include <sys/param.h>
-#include <sys/malloc.h>
-#include <sys/kernel.h>
-
-static char *rtems_hostname;
-
-int
-gethostname (char *name, size_t namelen)
-{
- char *cp = rtems_hostname;
-
- if (cp == NULL)
- cp = "";
- strncpy (name, cp, namelen);
- return 0;
-}
-
-int
-sethostname (char *name, size_t namelen)
-{
- char *old, *new;
-
- if (namelen >= MAXHOSTNAMELEN) {
- errno = EINVAL;
- return -1;
- }
- new = malloc (namelen + 1, M_HTABLE, M_NOWAIT);
- if (new == NULL) {
- errno = ENOMEM;
- return -1;
- }
- strncpy (new, name, namelen);
- new[namelen] = '\0';
- old = rtems_hostname;
- rtems_hostname = new;
- if (old)
- free (old, M_HTABLE);
- return 0;
-}
diff --git a/c/src/libnetworking/rtems/tftp.h b/c/src/libnetworking/rtems/tftp.h
deleted file mode 100644
index 11882bed1c..0000000000
--- a/c/src/libnetworking/rtems/tftp.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * $Id$
- */
-
-/*
- * Trivial File Transfer Protocol (TFTP)
- *
- * Transfer file to/from remote host
- *
- * W. Eric Norum
- * Saskatchewan Accelerator Laboratory
- * University of Saskatchewan
- * Saskatoon, Saskatchewan, CANADA
- * eric@skatter.usask.ca
- */
-
-/*
- * Usage:
- *
- * To open `/bootfiles/image' on `hostname' for reading:
- * fd = open ("/TFTP/hostname/bootfiles/image", O_RDONLY);
- *
- * The `hostname' must be four dot-separated decimal values.
- */
-
-#ifndef _TFTP_FILESYSTEM_h
-#define _TFTP_FILESYSTEM_h
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Filesystem initialization routine
- */
-
-int rtems_bsdnet_initialize_tftp_filesystem( void );
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif