summaryrefslogtreecommitdiffstats
path: root/c/src/exec/libcsupport
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1999-01-26 01:49:31 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1999-01-26 01:49:31 +0000
commitd78b7a9ed741ce1a8fa5ccae4e015b60741a4dad (patch)
tree2c6b00c74fddc1b46b4d73dedc76a92a74710414 /c/src/exec/libcsupport
parentAdded prototype information about the SONIC driver. (diff)
downloadrtems-d78b7a9ed741ce1a8fa5ccae4e015b60741a4dad.tar.bz2
Added libio_sockets.c to hold support routines for networking code.
Diffstat (limited to 'c/src/exec/libcsupport')
-rw-r--r--c/src/exec/libcsupport/src/libio_sockets.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/c/src/exec/libcsupport/src/libio_sockets.c b/c/src/exec/libcsupport/src/libio_sockets.c
new file mode 100644
index 0000000000..d0a9fbef13
--- /dev/null
+++ b/c/src/exec/libcsupport/src/libio_sockets.c
@@ -0,0 +1,58 @@
+/*
+ * This file contains the support infrastructure used to manage the
+ * table of integer style file descriptors used by the socket calls.
+ *
+ * COPYRIGHT (c) 1989-1998.
+ * On-Line Applications Research Corporation (OAR).
+ * Copyright assigned to U.S. Government, 1994.
+ *
+ * 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.
+ *
+ * $Id$
+ */
+
+#include "libio_.h" /* libio_.h pulls in rtems */
+#include <rtems.h>
+
+#include <errno.h>
+
+
+/*
+ * Convert an RTEMS file descriptor to a BSD socket pointer.
+ */
+
+struct socket *rtems_bsdnet_fdToSocket(
+ int fd
+)
+{
+ rtems_libio_t *iop;
+
+ if ((unsigned32)fd >= rtems_libio_number_iops)
+ return NULL;
+ iop = &rtems_libio_iops[fd];
+ if ((iop->flags & LIBIO_FLAGS_HANDLER_MASK) != LIBIO_FLAGS_HANDLER_SOCK)
+ return NULL;
+ return iop->data1;
+}
+
+/*
+ * Create an RTEMS file descriptor for a socket
+ */
+
+int rtems_bsdnet_makeFdForSocket(
+ void *so
+)
+{
+ rtems_libio_t *iop;
+
+ iop = rtems_libio_allocate();
+ if (iop == 0) {
+ errno = ENFILE;
+ return -1;
+ }
+ iop->flags |= LIBIO_FLAGS_HANDLER_SOCK;
+ iop->data1 = so;
+ return iop - rtems_libio_iops;
+}