summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2012-04-03 16:15:34 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2012-04-03 16:21:23 +0200
commit58f665583e8023f1245910e953eafff05121e782 (patch)
treee8dca109f1fe737f098bb1558229c34d678eaee3 /cpukit
parentFilesystem: Change type of ioctl_return (diff)
downloadrtems-58f665583e8023f1245910e953eafff05121e782.tar.bz2
networking: socket to/from file descriptor
o Move rtems_bsdnet_fdToSocket() and rtems_bsdnet_makeFdForSocket() to "cpukit/libnetworking/rtems/rtems_syscall.c". o The rtems_bsdnet_makeFdForSocket() function is now static. o Check in rtems_bsdnet_fdToSocket() function that the file descriptor uses the socket handlers, otherwise an error status will be returned and errno set to ENOTSOCK. o New test libtests/syscall01.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/libcsupport/Makefile.am4
-rw-r--r--cpukit/libcsupport/src/libio_sockets.c76
-rw-r--r--cpukit/libnetworking/rtems/rtems_bsdnet_internal.h2
-rw-r--r--cpukit/libnetworking/rtems/rtems_syscall.c61
4 files changed, 58 insertions, 85 deletions
diff --git a/cpukit/libcsupport/Makefile.am b/cpukit/libcsupport/Makefile.am
index 321eb29597..ce2a745ec9 100644
--- a/cpukit/libcsupport/Makefile.am
+++ b/cpukit/libcsupport/Makefile.am
@@ -60,10 +60,6 @@ BASE_FS_C_FILES = src/base_fs.c src/mount.c src/unmount.c src/libio.c \
src/privateenv.c \
src/open_dev_console.c src/__usrenv.c src/rtems_mkdir.c
-if LIBNETWORKING
-BASE_FS_C_FILES += src/libio_sockets.c
-endif
-
TERMIOS_C_FILES = src/cfgetispeed.c src/cfgetospeed.c src/cfsetispeed.c \
src/cfsetospeed.c src/tcgetattr.c src/tcsetattr.c src/tcdrain.c \
src/tcflow.c src/tcflush.c src/tcgetpgrp.c src/tcsendbreak.c \
diff --git a/cpukit/libcsupport/src/libio_sockets.c b/cpukit/libcsupport/src/libio_sockets.c
deleted file mode 100644
index ff02e0f4ea..0000000000
--- a/cpukit/libcsupport/src/libio_sockets.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * This file contains the support infrastructure used to manage the
- * table of integer style file descriptors used by the socket calls.
- *
- * COPYRIGHT (c) 1989-1999.
- * 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.rtems.com/license/LICENSE.
- *
- * $Id$
- */
-
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <rtems/libio_.h>
-#include <rtems/seterr.h>
-#include <rtems/rtems_bsdnet_internal.h>
-
-/*
- * Convert an RTEMS file descriptor to a BSD socket pointer.
- */
-
-struct socket *rtems_bsdnet_fdToSocket(
- int fd
-)
-{
- rtems_libio_t *iop;
-
- /* same as rtems_libio_check_fd(_fd) but different return */
- if ((uint32_t)fd >= rtems_libio_number_iops) {
- errno = EBADF;
- return NULL;
- }
- iop = &rtems_libio_iops[fd];
-
- /* same as rtems_libio_check_is_open(iop) but different return */
- if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) {
- errno = EBADF;
- return NULL;
- }
-
- if (iop->data1 == NULL)
- errno = EBADF;
- return iop->data1;
-}
-
-/*
- * Create an RTEMS file descriptor for a socket
- */
-
-int rtems_bsdnet_makeFdForSocket(
- void *so,
- const rtems_filesystem_file_handlers_r *h
-)
-{
- rtems_libio_t *iop;
- int fd;
-
- iop = rtems_libio_allocate();
- if (iop == 0)
- rtems_set_errno_and_return_minus_one( ENFILE );
-
- fd = iop - rtems_libio_iops;
- iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
- iop->data0 = fd;
- iop->data1 = so;
- iop->pathinfo.handlers = h;
- iop->pathinfo.ops = &rtems_filesystem_operations_default;
- iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
- rtems_filesystem_location_add_to_mt_entry(&iop->pathinfo);
- return fd;
-}
diff --git a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
index 3e1ce72455..8c43701523 100644
--- a/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
+++ b/cpukit/libnetworking/rtems/rtems_bsdnet_internal.h
@@ -199,8 +199,6 @@ int ioctl (int, ioctl_command_t, ...);
# error "Network event conflict"
#endif
-int rtems_bsdnet_makeFdForSocket(
- void *so, const rtems_filesystem_file_handlers_r *h);
struct socket *rtems_bsdnet_fdToSocket(int fd);
#ifdef __cplusplus
diff --git a/cpukit/libnetworking/rtems/rtems_syscall.c b/cpukit/libnetworking/rtems/rtems_syscall.c
index 9935a69e67..0a4ae91371 100644
--- a/cpukit/libnetworking/rtems/rtems_syscall.c
+++ b/cpukit/libnetworking/rtems/rtems_syscall.c
@@ -13,7 +13,7 @@
#include <errno.h>
#include <rtems.h>
-#include <rtems/libio.h>
+#include <rtems/libio_.h>
#include <rtems/error.h>
#include <rtems/rtems_bsdnet.h>
@@ -44,6 +44,61 @@ ssize_t recv(int, void *, size_t, int);
static const rtems_filesystem_file_handlers_r socket_handlers;
/*
+ * Convert an RTEMS file descriptor to a BSD socket pointer.
+ */
+struct socket *
+rtems_bsdnet_fdToSocket (int fd)
+{
+ rtems_libio_t *iop;
+
+ /* same as rtems_libio_check_fd(_fd) but different return */
+ if ((uint32_t)fd >= rtems_libio_number_iops) {
+ errno = EBADF;
+ return NULL;
+ }
+ iop = &rtems_libio_iops[fd];
+
+ /* same as rtems_libio_check_is_open(iop) but different return */
+ if ((iop->flags & LIBIO_FLAGS_OPEN) == 0) {
+ errno = EBADF;
+ return NULL;
+ }
+
+ if (iop->pathinfo.handlers != &socket_handlers) {
+ errno = ENOTSOCK;
+ return NULL;
+ }
+
+ if (iop->data1 == NULL)
+ errno = EBADF;
+ return iop->data1;
+}
+
+/*
+ * Create an RTEMS file descriptor for a socket
+ */
+static int
+rtems_bsdnet_makeFdForSocket (void *so)
+{
+ rtems_libio_t *iop;
+ int fd;
+
+ iop = rtems_libio_allocate();
+ if (iop == 0)
+ rtems_set_errno_and_return_minus_one( ENFILE );
+
+ fd = iop - rtems_libio_iops;
+ iop->flags |= LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
+ iop->data0 = fd;
+ iop->data1 = so;
+ iop->pathinfo.handlers = &socket_handlers;
+ iop->pathinfo.ops = &rtems_filesystem_operations_default;
+ iop->pathinfo.mt_entry = &rtems_filesystem_null_mt_entry;
+ rtems_filesystem_location_add_to_mt_entry(&iop->pathinfo);
+ return fd;
+}
+
+/*
* Package system call argument into mbuf.
*/
static int
@@ -82,7 +137,7 @@ socket (int domain, int type, int protocol)
rtems_bsdnet_semaphore_obtain ();
error = socreate(domain, &so, type, protocol, NULL);
if (error == 0) {
- fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
+ fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0)
soclose (so);
}
@@ -233,7 +288,7 @@ accept (int s, struct sockaddr *name, int *namelen)
TAILQ_REMOVE(&head->so_comp, so, so_list);
head->so_qlen--;
- fd = rtems_bsdnet_makeFdForSocket (so, &socket_handlers);
+ fd = rtems_bsdnet_makeFdForSocket (so);
if (fd < 0) {
TAILQ_INSERT_HEAD(&head->so_comp, so, so_list);
head->so_qlen++;