blob: cb1d5a7bdda42bdfa1b633a079dda16d3afa3f0c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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 | LIBIO_FLAGS_WRITE | LIBIO_FLAGS_READ;
iop->data1 = so;
return iop - rtems_libio_iops;
}
|