2002-10-19 12:59:30 +00:00
|
|
|
/*
|
2004-02-07 00:30:03 +00:00
|
|
|
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
2003-06-11 22:11:42 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
2002-10-19 12:59:30 +00:00
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
2003-06-11 22:11:42 +00:00
|
|
|
* derived from this software without specific prior written permission.
|
2002-10-19 12:59:30 +00:00
|
|
|
*
|
2003-06-11 22:11:42 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
|
|
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
|
|
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
2002-10-19 12:59:30 +00:00
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* This file is part of the lwIP TCP/IP stack.
|
2003-06-11 22:11:42 +00:00
|
|
|
*
|
2002-10-19 12:59:30 +00:00
|
|
|
* Author: Adam Dunkels <adam@sics.se>
|
|
|
|
*
|
2003-02-06 22:18:56 +00:00
|
|
|
* Improved by Marc Boucher <marc@mbsi.ca> and David Haas <dhaas@alum.rpi.edu>
|
|
|
|
*
|
2002-10-19 12:59:30 +00:00
|
|
|
*/
|
|
|
|
|
2004-07-04 23:43:02 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-02-21 16:43:46 +00:00
|
|
|
#include "lwip/opt.h"
|
2002-10-19 12:59:30 +00:00
|
|
|
#include "lwip/api.h"
|
2003-02-06 22:18:56 +00:00
|
|
|
#include "lwip/arch.h"
|
|
|
|
#include "lwip/sys.h"
|
2007-03-11 19:16:38 +00:00
|
|
|
#include "lwip/igmp.h"
|
2002-10-19 12:59:30 +00:00
|
|
|
#include "lwip/sockets.h"
|
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
#define NUM_SOCKETS MEMP_NUM_NETCONN
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
struct lwip_socket {
|
|
|
|
struct netconn *conn;
|
|
|
|
struct netbuf *lastdata;
|
|
|
|
u16_t lastoffset;
|
2003-02-06 22:18:56 +00:00
|
|
|
u16_t rcvevent;
|
|
|
|
u16_t sendevent;
|
2003-06-09 21:14:47 +00:00
|
|
|
u16_t flags;
|
2003-02-06 22:18:56 +00:00
|
|
|
int err;
|
|
|
|
};
|
|
|
|
|
2007-03-28 18:21:24 +00:00
|
|
|
struct lwip_select_cb {
|
|
|
|
struct lwip_select_cb *next;
|
|
|
|
fd_set *readset;
|
|
|
|
fd_set *writeset;
|
|
|
|
fd_set *exceptset;
|
|
|
|
int sem_signalled;
|
|
|
|
sys_sem_t sem;
|
2002-10-19 12:59:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct lwip_socket sockets[NUM_SOCKETS];
|
2003-02-06 22:18:56 +00:00
|
|
|
static struct lwip_select_cb *select_cb_list = 0;
|
|
|
|
|
|
|
|
static sys_sem_t socksem = 0;
|
|
|
|
static sys_sem_t selectsem = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len);
|
|
|
|
|
2007-03-06 16:41:02 +00:00
|
|
|
static int err_to_errno_table[] = {
|
|
|
|
0, /* ERR_OK 0 No error, everything OK. */
|
|
|
|
ENOMEM, /* ERR_MEM -1 Out of memory error. */
|
|
|
|
ENOBUFS, /* ERR_BUF -2 Buffer error. */
|
|
|
|
ECONNABORTED, /* ERR_ABRT -3 Connection aborted. */
|
|
|
|
ECONNRESET, /* ERR_RST -4 Connection reset. */
|
|
|
|
ESHUTDOWN, /* ERR_CLSD -5 Connection closed. */
|
|
|
|
ENOTCONN, /* ERR_CONN -6 Not connected. */
|
|
|
|
EINVAL, /* ERR_VAL -7 Illegal value. */
|
|
|
|
EIO, /* ERR_ARG -8 Illegal argument. */
|
|
|
|
EHOSTUNREACH, /* ERR_RTE -9 Routing problem. */
|
|
|
|
EADDRINUSE, /* ERR_USE -10 Address in use. */
|
|
|
|
-1, /* ERR_IF -11 Low-level netif error */
|
|
|
|
-1, /* ERR_ISCONN -12 Already connected. */
|
|
|
|
ETIMEDOUT /* ERR_TIMEOUT -13 Timeout */
|
2003-02-06 22:18:56 +00:00
|
|
|
};
|
|
|
|
|
2006-02-13 08:14:11 +00:00
|
|
|
#define ERR_TO_ERRNO_TABLE_SIZE \
|
|
|
|
(sizeof(err_to_errno_table)/sizeof(err_to_errno_table[0]))
|
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
#define err_to_errno(err) \
|
2007-03-21 21:14:06 +00:00
|
|
|
((unsigned)(-(err)) < ERR_TO_ERRNO_TABLE_SIZE ? \
|
2006-02-13 08:14:11 +00:00
|
|
|
err_to_errno_table[-(err)] : EIO)
|
2003-02-06 22:18:56 +00:00
|
|
|
|
|
|
|
#ifdef ERRNO
|
|
|
|
#define set_errno(err) errno = (err)
|
|
|
|
#else
|
|
|
|
#define set_errno(err)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define sock_set_errno(sk, e) do { \
|
2003-06-09 21:14:47 +00:00
|
|
|
sk->err = (e); \
|
|
|
|
set_errno(sk->err); \
|
2003-05-01 13:24:01 +00:00
|
|
|
} while (0)
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2007-02-26 20:01:04 +00:00
|
|
|
void
|
|
|
|
lwip_socket_init(void)
|
|
|
|
{
|
|
|
|
socksem = sys_sem_new(1);
|
|
|
|
selectsem = sys_sem_new(1);
|
|
|
|
}
|
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
static struct lwip_socket *
|
|
|
|
get_socket(int s)
|
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2007-02-26 20:16:38 +00:00
|
|
|
if ((s < 0) || (s >= NUM_SOCKETS)) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", s));
|
|
|
|
set_errno(EBADF);
|
2002-10-19 12:59:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
sock = &sockets[s];
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (!sock->conn) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): not active\n", s));
|
|
|
|
set_errno(EBADF);
|
2002-10-19 12:59:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
return sock;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
static int
|
|
|
|
alloc_socket(struct netconn *newconn)
|
|
|
|
{
|
|
|
|
int i;
|
2003-02-06 22:18:56 +00:00
|
|
|
|
|
|
|
/* Protect socket array */
|
|
|
|
sys_sem_wait(socksem);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* allocate a new socket identifier */
|
|
|
|
for(i = 0; i < NUM_SOCKETS; ++i) {
|
2003-05-01 13:24:01 +00:00
|
|
|
if (!sockets[i].conn) {
|
2007-03-06 16:41:02 +00:00
|
|
|
sockets[i].conn = newconn;
|
|
|
|
sockets[i].lastdata = NULL;
|
2002-10-19 12:59:30 +00:00
|
|
|
sockets[i].lastoffset = 0;
|
2007-03-06 16:41:02 +00:00
|
|
|
sockets[i].rcvevent = 0;
|
|
|
|
sockets[i].sendevent = 1; /* TCP send buf is empty */
|
|
|
|
sockets[i].flags = 0;
|
|
|
|
sockets[i].err = 0;
|
2003-02-06 22:18:56 +00:00
|
|
|
sys_sem_signal(socksem);
|
2002-10-19 12:59:30 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
sys_sem_signal(socksem);
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
2003-03-03 10:29:21 +00:00
|
|
|
lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
struct netconn *newconn;
|
2003-01-24 09:24:44 +00:00
|
|
|
struct ip_addr naddr;
|
2002-10-19 12:59:30 +00:00
|
|
|
u16_t port;
|
|
|
|
int newsock;
|
2003-02-06 22:18:56 +00:00
|
|
|
struct sockaddr_in sin;
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s));
|
2002-10-19 12:59:30 +00:00
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
newconn = netconn_accept(sock->conn);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* get the IP address and port of the remote host */
|
|
|
|
netconn_peer(newconn, &naddr, &port);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_len = sizeof(sin);
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_port = htons(port);
|
|
|
|
sin.sin_addr.s_addr = naddr.addr;
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (*addrlen > sizeof(sin))
|
2003-02-06 22:18:56 +00:00
|
|
|
*addrlen = sizeof(sin);
|
|
|
|
|
|
|
|
memcpy(addr, &sin, *addrlen);
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
newsock = alloc_socket(newconn);
|
2003-06-11 22:11:42 +00:00
|
|
|
if (newsock == -1) {
|
2002-10-19 12:59:30 +00:00
|
|
|
netconn_delete(newconn);
|
2007-04-05 16:49:33 +00:00
|
|
|
sock_set_errno(sock, ENFILE);
|
2007-03-28 18:21:24 +00:00
|
|
|
return -1;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
newconn->callback = event_callback;
|
|
|
|
sock = get_socket(newsock);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sys_sem_wait(socksem);
|
|
|
|
sock->rcvevent += -1 - newconn->socket;
|
|
|
|
newconn->socket = newsock;
|
|
|
|
sys_sem_signal(socksem);
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d addr=", s, newsock));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", port));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2002-10-19 12:59:30 +00:00
|
|
|
return newsock;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
2003-03-03 10:29:21 +00:00
|
|
|
lwip_bind(int s, struct sockaddr *name, socklen_t namelen)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
2003-02-06 22:18:56 +00:00
|
|
|
struct ip_addr local_addr;
|
|
|
|
u16_t local_port;
|
2002-10-19 12:59:30 +00:00
|
|
|
err_t err;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
2007-03-11 16:53:37 +00:00
|
|
|
|
|
|
|
LWIP_ASSERT("lwip_bind: invalid address", (namelen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)name)->sin_family) == AF_INET));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
local_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
|
|
|
|
local_port = ((struct sockaddr_in *)name)->sin_port;
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &local_addr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(local_port)));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
err = netconn_bind(sock->conn, &local_addr, ntohs(local_port));
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (err != ERR_OK) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err));
|
|
|
|
sock_set_errno(sock, err_to_errno(err));
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) succeeded\n", s));
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2002-10-19 12:59:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
|
|
|
lwip_close(int s)
|
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s));
|
2003-02-06 22:18:56 +00:00
|
|
|
|
|
|
|
/* We cannot allow multiple closes of the same socket. */
|
|
|
|
sys_sem_wait(socksem);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
sock = get_socket(s);
|
2003-05-01 13:24:01 +00:00
|
|
|
if (!sock) {
|
2003-02-06 22:18:56 +00:00
|
|
|
sys_sem_signal(socksem);
|
|
|
|
return -1;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
netconn_delete(sock->conn);
|
2003-05-01 13:24:01 +00:00
|
|
|
if (sock->lastdata) {
|
2002-10-19 12:59:30 +00:00
|
|
|
netbuf_delete(sock->lastdata);
|
|
|
|
}
|
2007-03-11 16:53:37 +00:00
|
|
|
sock->lastdata = NULL;
|
2002-10-19 12:59:30 +00:00
|
|
|
sock->lastoffset = 0;
|
2007-03-11 16:53:37 +00:00
|
|
|
sock->conn = NULL;
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2007-03-11 16:53:37 +00:00
|
|
|
sys_sem_signal(socksem);
|
2002-10-19 12:59:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
2007-03-11 17:57:13 +00:00
|
|
|
lwip_connect(int s, const struct sockaddr *name, socklen_t namelen)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
err_t err;
|
|
|
|
|
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
2007-03-11 16:53:37 +00:00
|
|
|
|
|
|
|
LWIP_ASSERT("lwip_connect: invalid address", (namelen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)name)->sin_family) == AF_INET));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-01-22 16:18:05 +00:00
|
|
|
if (((struct sockaddr_in *)name)->sin_family == AF_UNSPEC) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s));
|
|
|
|
err = netconn_disconnect(sock->conn);
|
2003-02-06 22:18:56 +00:00
|
|
|
} else {
|
2003-06-09 21:14:47 +00:00
|
|
|
struct ip_addr remote_addr;
|
|
|
|
u16_t remote_port;
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-06-09 21:14:47 +00:00
|
|
|
remote_addr.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
|
|
|
|
remote_port = ((struct sockaddr_in *)name)->sin_port;
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u)\n", ntohs(remote_port)));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-06-09 21:14:47 +00:00
|
|
|
err = netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
|
2007-03-28 18:21:24 +00:00
|
|
|
}
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (err != ERR_OK) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err));
|
|
|
|
sock_set_errno(sock, err_to_errno(err));
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) succeeded\n", s));
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2002-10-19 12:59:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
|
|
|
lwip_listen(int s, int backlog)
|
|
|
|
{
|
2003-06-11 22:11:42 +00:00
|
|
|
struct lwip_socket *sock;
|
2002-10-19 12:59:30 +00:00
|
|
|
err_t err;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2007-04-04 19:54:22 +00:00
|
|
|
/* This does no harm. If debugging is off, backlog is unused. */
|
|
|
|
LWIP_UNUSED_ARG(backlog);
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog));
|
2002-10-19 12:59:30 +00:00
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
err = netconn_listen(sock->conn);
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (err != ERR_OK) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err));
|
|
|
|
sock_set_errno(sock, err_to_errno(err));
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2002-10-19 12:59:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
|
|
|
lwip_recvfrom(int s, void *mem, int len, unsigned int flags,
|
2003-06-09 21:14:47 +00:00
|
|
|
struct sockaddr *from, socklen_t *fromlen)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
2007-03-06 16:41:02 +00:00
|
|
|
struct netbuf *buf;
|
|
|
|
u16_t buflen, copylen;
|
|
|
|
struct ip_addr *addr;
|
|
|
|
u16_t port;
|
2002-10-19 12:59:30 +00:00
|
|
|
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %d, 0x%x, ..)\n", s, mem, len, flags));
|
2002-10-19 12:59:30 +00:00
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Check if there is data left from the last recv operation. */
|
2003-06-11 22:11:42 +00:00
|
|
|
if (sock->lastdata) {
|
2007-03-28 18:21:24 +00:00
|
|
|
buf = sock->lastdata;
|
|
|
|
} else {
|
|
|
|
/* If this is non-blocking call, then check first */
|
|
|
|
if (((flags & MSG_DONTWAIT) || (sock->flags & O_NONBLOCK)) && !sock->rcvevent) {
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): returning EWOULDBLOCK\n", s));
|
|
|
|
sock_set_errno(sock, EWOULDBLOCK);
|
|
|
|
return -1;
|
|
|
|
}
|
2007-03-06 16:41:02 +00:00
|
|
|
|
2007-03-28 18:21:24 +00:00
|
|
|
/* No data was left from the previous operation, so we try to get
|
|
|
|
some from the network. */
|
|
|
|
buf = netconn_recv(sock->conn);
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
/* We should really do some error checking here. */
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): buf == NULL!\n", s));
|
|
|
|
sock_set_errno(sock, (sock->conn->type==NETCONN_UDP)?ETIMEDOUT:0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
buflen = netbuf_len(buf);
|
|
|
|
|
|
|
|
buflen -= sock->lastoffset;
|
2007-03-06 16:41:02 +00:00
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (len > buflen) {
|
2007-03-28 18:21:24 +00:00
|
|
|
copylen = buflen;
|
|
|
|
} else {
|
|
|
|
copylen = len;
|
|
|
|
}
|
2007-03-06 16:41:02 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* copy the contents of the received buffer into
|
2007-03-06 16:41:02 +00:00
|
|
|
the supplied memory pointer mem */
|
2002-10-19 12:59:30 +00:00
|
|
|
netbuf_copy_partial(buf, mem, copylen, sock->lastoffset);
|
|
|
|
|
2007-03-06 16:41:02 +00:00
|
|
|
/* Check to see from where the data was.*/
|
2003-05-01 13:24:01 +00:00
|
|
|
if (from && fromlen) {
|
2003-02-06 22:18:56 +00:00
|
|
|
struct sockaddr_in sin;
|
|
|
|
|
|
|
|
addr = netbuf_fromaddr(buf);
|
|
|
|
port = netbuf_fromport(buf);
|
|
|
|
|
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_len = sizeof(sin);
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
sin.sin_port = htons(port);
|
|
|
|
sin.sin_addr.s_addr = addr->addr;
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (*fromlen > sizeof(sin))
|
2003-02-06 22:18:56 +00:00
|
|
|
*fromlen = sizeof(sin);
|
|
|
|
|
|
|
|
memcpy(from, &sin, *fromlen);
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, addr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, copylen));
|
2003-02-06 22:18:56 +00:00
|
|
|
} else {
|
2004-11-09 11:44:06 +00:00
|
|
|
#if SOCKETS_DEBUG
|
2003-01-31 12:51:56 +00:00
|
|
|
addr = netbuf_fromaddr(buf);
|
2003-06-11 22:11:42 +00:00
|
|
|
port = netbuf_fromport(buf);
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d): addr=", s));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, addr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u len=%u\n", port, copylen));
|
2003-02-06 22:18:56 +00:00
|
|
|
#endif
|
|
|
|
|
2003-01-31 12:51:56 +00:00
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* If this is a TCP socket, check if there is data left in the
|
|
|
|
buffer. If so, it should be saved in the sock structure for next
|
|
|
|
time around. */
|
2003-05-01 13:24:01 +00:00
|
|
|
if (netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) {
|
2002-10-19 12:59:30 +00:00
|
|
|
sock->lastdata = buf;
|
|
|
|
sock->lastoffset += copylen;
|
|
|
|
} else {
|
|
|
|
sock->lastdata = NULL;
|
|
|
|
sock->lastoffset = 0;
|
|
|
|
netbuf_delete(buf);
|
|
|
|
}
|
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2002-11-15 15:05:06 +00:00
|
|
|
return copylen;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
|
|
|
lwip_read(int s, void *mem, int len)
|
|
|
|
{
|
2003-02-06 22:18:56 +00:00
|
|
|
return lwip_recvfrom(s, mem, len, 0, NULL, NULL);
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
|
|
|
lwip_recv(int s, void *mem, int len, unsigned int flags)
|
|
|
|
{
|
|
|
|
return lwip_recvfrom(s, mem, len, flags, NULL, NULL);
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
2007-03-11 17:57:13 +00:00
|
|
|
lwip_send(int s, const void *data, int size, unsigned int flags)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
struct netbuf *buf;
|
|
|
|
err_t err;
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%d, flags=0x%x)\n", s, data, size, flags));
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
switch (netconn_type(sock->conn)) {
|
2003-11-14 13:17:23 +00:00
|
|
|
case NETCONN_RAW:
|
2002-10-19 12:59:30 +00:00
|
|
|
case NETCONN_UDP:
|
2003-11-14 13:17:23 +00:00
|
|
|
case NETCONN_UDPLITE:
|
|
|
|
case NETCONN_UDPNOCHKSUM:
|
2002-10-19 12:59:30 +00:00
|
|
|
/* create a buffer */
|
|
|
|
buf = netbuf_new();
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (!buf) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) ENOBUFS\n", s));
|
|
|
|
sock_set_errno(sock, ENOBUFS);
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2007-03-28 17:26:06 +00:00
|
|
|
/* make the buffer point to the data that should be sent */
|
|
|
|
if ((err = netbuf_ref(buf, data, size))==ERR_OK) {
|
|
|
|
/* send the data */
|
|
|
|
err = netconn_send(sock->conn, buf);
|
|
|
|
}
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
/* deallocated the buffer */
|
|
|
|
netbuf_delete(buf);
|
|
|
|
break;
|
|
|
|
case NETCONN_TCP:
|
|
|
|
err = netconn_write(sock->conn, data, size, NETCONN_COPY);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = ERR_ARG;
|
|
|
|
break;
|
|
|
|
}
|
2003-05-01 13:24:01 +00:00
|
|
|
if (err != ERR_OK) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d\n", s, err));
|
|
|
|
sock_set_errno(sock, err_to_errno(err));
|
2003-06-11 22:11:42 +00:00
|
|
|
return -1;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) ok size=%d\n", s, size));
|
2003-02-06 22:18:56 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2002-10-19 12:59:30 +00:00
|
|
|
return size;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
2007-03-11 17:57:13 +00:00
|
|
|
lwip_sendto(int s, const void *data, int size, unsigned int flags,
|
2003-03-03 10:29:21 +00:00
|
|
|
struct sockaddr *to, socklen_t tolen)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
2003-01-24 09:24:44 +00:00
|
|
|
struct ip_addr remote_addr, addr;
|
2002-10-19 12:59:30 +00:00
|
|
|
u16_t remote_port, port;
|
2007-03-06 16:41:02 +00:00
|
|
|
int err,connected;
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
2007-03-11 16:53:37 +00:00
|
|
|
|
|
|
|
LWIP_ASSERT("lwip_sendto: invalid address", (tolen == sizeof(struct sockaddr_in)) && ((((struct sockaddr_in *)to)->sin_family) == AF_INET));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
/* get the peer if currently connected */
|
2003-01-22 16:18:05 +00:00
|
|
|
connected = (netconn_peer(sock->conn, &addr, &port) == ERR_OK);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
remote_addr.addr = ((struct sockaddr_in *)to)->sin_addr.s_addr;
|
|
|
|
remote_port = ((struct sockaddr_in *)to)->sin_port;
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, size=%d, flags=0x%x to=", s, data, size, flags));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &remote_addr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%u\n", ntohs(remote_port)));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-01-23 16:46:01 +00:00
|
|
|
netconn_connect(sock->conn, &remote_addr, ntohs(remote_port));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2007-03-06 16:41:02 +00:00
|
|
|
err = lwip_send(s, data, size, flags);
|
2002-10-19 12:59:30 +00:00
|
|
|
|
|
|
|
/* reset the remote address and port number
|
|
|
|
of the connection */
|
2003-05-01 13:24:01 +00:00
|
|
|
if (connected)
|
2003-06-09 21:14:47 +00:00
|
|
|
netconn_connect(sock->conn, &addr, port);
|
2003-01-22 16:18:05 +00:00
|
|
|
else
|
2007-03-28 18:21:24 +00:00
|
|
|
netconn_disconnect(sock->conn);
|
2007-03-06 16:41:02 +00:00
|
|
|
return err;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
|
|
|
lwip_socket(int domain, int type, int protocol)
|
|
|
|
{
|
|
|
|
struct netconn *conn;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* create a netconn */
|
2003-05-01 13:24:01 +00:00
|
|
|
switch (type) {
|
2003-11-14 13:17:23 +00:00
|
|
|
case SOCK_RAW:
|
|
|
|
conn = netconn_new_with_proto_and_callback(NETCONN_RAW, protocol, event_callback);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
|
|
|
break;
|
2002-10-19 12:59:30 +00:00
|
|
|
case SOCK_DGRAM:
|
2003-02-06 22:18:56 +00:00
|
|
|
conn = netconn_new_with_callback(NETCONN_UDP, event_callback);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
2002-10-19 12:59:30 +00:00
|
|
|
break;
|
|
|
|
case SOCK_STREAM:
|
2003-02-06 22:18:56 +00:00
|
|
|
conn = netconn_new_with_callback(NETCONN_TCP, event_callback);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol));
|
2002-10-19 12:59:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", domain, type, protocol));
|
|
|
|
set_errno(EINVAL);
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (!conn) {
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("-1 / ENOBUFS (could not create netconn)\n"));
|
|
|
|
set_errno(ENOBUFS);
|
2002-10-19 12:59:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = alloc_socket(conn);
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (i == -1) {
|
2002-10-19 12:59:30 +00:00
|
|
|
netconn_delete(conn);
|
2007-04-05 16:49:33 +00:00
|
|
|
set_errno(ENFILE);
|
2007-03-28 18:21:24 +00:00
|
|
|
return -1;
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
conn->socket = i;
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i));
|
2003-02-06 22:18:56 +00:00
|
|
|
set_errno(0);
|
2002-10-19 12:59:30 +00:00
|
|
|
return i;
|
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2002-10-19 12:59:30 +00:00
|
|
|
int
|
2007-03-11 17:57:13 +00:00
|
|
|
lwip_write(int s, const void *data, int size)
|
2002-10-19 12:59:30 +00:00
|
|
|
{
|
2002-11-15 15:05:06 +00:00
|
|
|
return lwip_send(s, data, size, 0);
|
2002-10-19 12:59:30 +00:00
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
static int
|
|
|
|
lwip_selscan(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset)
|
|
|
|
{
|
|
|
|
int i, nready = 0;
|
|
|
|
fd_set lreadset, lwriteset, lexceptset;
|
|
|
|
struct lwip_socket *p_sock;
|
|
|
|
|
|
|
|
FD_ZERO(&lreadset);
|
|
|
|
FD_ZERO(&lwriteset);
|
|
|
|
FD_ZERO(&lexceptset);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* Go through each socket in each list to count number of sockets which
|
|
|
|
currently match */
|
|
|
|
for(i = 0; i < maxfdp1; i++)
|
|
|
|
{
|
2003-05-01 13:24:01 +00:00
|
|
|
if (FD_ISSET(i, readset))
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
|
|
|
/* See if netconn of this socket is ready for read */
|
|
|
|
p_sock = get_socket(i);
|
|
|
|
if (p_sock && (p_sock->lastdata || p_sock->rcvevent))
|
|
|
|
{
|
|
|
|
FD_SET(i, &lreadset);
|
2007-03-06 16:41:02 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i));
|
2003-02-06 22:18:56 +00:00
|
|
|
nready++;
|
|
|
|
}
|
|
|
|
}
|
2003-05-01 13:24:01 +00:00
|
|
|
if (FD_ISSET(i, writeset))
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
|
|
|
/* See if netconn of this socket is ready for write */
|
|
|
|
p_sock = get_socket(i);
|
|
|
|
if (p_sock && p_sock->sendevent)
|
|
|
|
{
|
|
|
|
FD_SET(i, &lwriteset);
|
2007-03-06 16:41:02 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i));
|
2003-02-06 22:18:56 +00:00
|
|
|
nready++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*readset = lreadset;
|
|
|
|
*writeset = lwriteset;
|
|
|
|
FD_ZERO(exceptset);
|
|
|
|
|
|
|
|
return nready;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
int
|
|
|
|
lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
|
2003-02-17 11:34:48 +00:00
|
|
|
struct timeval *timeout)
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int nready;
|
|
|
|
fd_set lreadset, lwriteset, lexceptset;
|
|
|
|
u32_t msectimeout;
|
|
|
|
struct lwip_select_cb select_cb;
|
|
|
|
struct lwip_select_cb *p_selcb;
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select(%d, %p, %p, %p, tvsec=%ld tvusec=%ld)\n", maxfdp1, (void *)readset, (void *) writeset, (void *) exceptset, timeout ? timeout->tv_sec : -1L, timeout ? timeout->tv_usec : -1L));
|
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
select_cb.next = 0;
|
|
|
|
select_cb.readset = readset;
|
|
|
|
select_cb.writeset = writeset;
|
|
|
|
select_cb.exceptset = exceptset;
|
|
|
|
select_cb.sem_signalled = 0;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* Protect ourselves searching through the list */
|
|
|
|
sys_sem_wait(selectsem);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
if (readset)
|
|
|
|
lreadset = *readset;
|
|
|
|
else
|
|
|
|
FD_ZERO(&lreadset);
|
|
|
|
if (writeset)
|
|
|
|
lwriteset = *writeset;
|
|
|
|
else
|
|
|
|
FD_ZERO(&lwriteset);
|
|
|
|
if (exceptset)
|
|
|
|
lexceptset = *exceptset;
|
|
|
|
else
|
|
|
|
FD_ZERO(&lexceptset);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* Go through each socket in each list to count number of sockets which
|
|
|
|
currently match */
|
|
|
|
nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* If we don't have any current events, then suspend if we are supposed to */
|
|
|
|
if (!nready)
|
|
|
|
{
|
|
|
|
if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0)
|
|
|
|
{
|
2003-03-24 15:53:38 +00:00
|
|
|
sys_sem_signal(selectsem);
|
2003-02-06 22:18:56 +00:00
|
|
|
if (readset)
|
|
|
|
FD_ZERO(readset);
|
|
|
|
if (writeset)
|
|
|
|
FD_ZERO(writeset);
|
|
|
|
if (exceptset)
|
|
|
|
FD_ZERO(exceptset);
|
|
|
|
|
2007-03-06 16:41:02 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: no timeout, returning 0\n"));
|
|
|
|
set_errno(0);
|
2003-06-10 10:45:29 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* add our semaphore to list */
|
|
|
|
/* We don't actually need any dynamic memory. Our entry on the
|
|
|
|
* list is only valid while we are in this function, so it's ok
|
|
|
|
* to use local variables */
|
|
|
|
|
|
|
|
select_cb.sem = sys_sem_new(0);
|
|
|
|
/* Note that we are still protected */
|
|
|
|
/* Put this select_cb on top of list */
|
|
|
|
select_cb.next = select_cb_list;
|
|
|
|
select_cb_list = &select_cb;
|
|
|
|
|
|
|
|
/* Now we can safely unprotect */
|
|
|
|
sys_sem_signal(selectsem);
|
|
|
|
|
|
|
|
/* Now just wait to be woken */
|
|
|
|
if (timeout == 0)
|
|
|
|
/* Wait forever */
|
|
|
|
msectimeout = 0;
|
2007-02-28 12:52:44 +00:00
|
|
|
else {
|
2003-11-14 13:17:23 +00:00
|
|
|
msectimeout = ((timeout->tv_sec * 1000) + ((timeout->tv_usec + 500)/1000));
|
2007-02-28 12:52:44 +00:00
|
|
|
if(msectimeout == 0)
|
|
|
|
msectimeout = 1;
|
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
|
|
|
|
i = sys_sem_wait_timeout(select_cb.sem, msectimeout);
|
|
|
|
|
|
|
|
/* Take us off the list */
|
|
|
|
sys_sem_wait(selectsem);
|
|
|
|
if (select_cb_list == &select_cb)
|
|
|
|
select_cb_list = select_cb.next;
|
|
|
|
else
|
|
|
|
for (p_selcb = select_cb_list; p_selcb; p_selcb = p_selcb->next)
|
|
|
|
if (p_selcb->next == &select_cb)
|
|
|
|
{
|
|
|
|
p_selcb->next = select_cb.next;
|
|
|
|
break;
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sys_sem_signal(selectsem);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sys_sem_free(select_cb.sem);
|
|
|
|
if (i == 0) /* Timeout */
|
|
|
|
{
|
|
|
|
if (readset)
|
|
|
|
FD_ZERO(readset);
|
|
|
|
if (writeset)
|
|
|
|
FD_ZERO(writeset);
|
|
|
|
if (exceptset)
|
|
|
|
FD_ZERO(exceptset);
|
2003-06-10 10:45:29 +00:00
|
|
|
|
2007-03-06 16:41:02 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: timeout expired\n"));
|
|
|
|
set_errno(0);
|
2003-06-10 10:45:29 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (readset)
|
|
|
|
lreadset = *readset;
|
|
|
|
else
|
|
|
|
FD_ZERO(&lreadset);
|
|
|
|
if (writeset)
|
|
|
|
lwriteset = *writeset;
|
|
|
|
else
|
|
|
|
FD_ZERO(&lwriteset);
|
|
|
|
if (exceptset)
|
|
|
|
lexceptset = *exceptset;
|
|
|
|
else
|
|
|
|
FD_ZERO(&lexceptset);
|
|
|
|
|
|
|
|
/* See what's set */
|
|
|
|
nready = lwip_selscan(maxfdp1, &lreadset, &lwriteset, &lexceptset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sys_sem_signal(selectsem);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
if (readset)
|
|
|
|
*readset = lreadset;
|
|
|
|
if (writeset)
|
|
|
|
*writeset = lwriteset;
|
|
|
|
if (exceptset)
|
|
|
|
*exceptset = lexceptset;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready));
|
2003-06-09 21:14:47 +00:00
|
|
|
set_errno(0);
|
2003-06-10 10:45:29 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
return nready;
|
|
|
|
}
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
static void
|
|
|
|
event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len)
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
struct lwip_select_cb *scb;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* Get socket */
|
|
|
|
if (conn)
|
|
|
|
{
|
|
|
|
s = conn->socket;
|
|
|
|
if (s < 0)
|
|
|
|
{
|
|
|
|
/* Data comes in right away after an accept, even though
|
|
|
|
* the server task might not have created a new socket yet.
|
|
|
|
* Just count down (or up) if that's the case and we
|
|
|
|
* will use the data later. Note that only receive events
|
|
|
|
* can happen before the new socket is set up. */
|
|
|
|
if (evt == NETCONN_EVT_RCVPLUS)
|
|
|
|
conn->socket--;
|
|
|
|
return;
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sock = get_socket(s);
|
|
|
|
if (!sock)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return;
|
|
|
|
|
|
|
|
sys_sem_wait(selectsem);
|
|
|
|
/* Set event as required */
|
|
|
|
switch (evt)
|
|
|
|
{
|
|
|
|
case NETCONN_EVT_RCVPLUS:
|
|
|
|
sock->rcvevent++;
|
|
|
|
break;
|
|
|
|
case NETCONN_EVT_RCVMINUS:
|
|
|
|
sock->rcvevent--;
|
|
|
|
break;
|
|
|
|
case NETCONN_EVT_SENDPLUS:
|
|
|
|
sock->sendevent = 1;
|
|
|
|
break;
|
|
|
|
case NETCONN_EVT_SENDMINUS:
|
|
|
|
sock->sendevent = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sys_sem_signal(selectsem);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
/* Now decide if anyone is waiting for this socket */
|
|
|
|
/* NOTE: This code is written this way to protect the select link list
|
|
|
|
but to avoid a deadlock situation by releasing socksem before
|
|
|
|
signalling for the select. This means we need to go through the list
|
|
|
|
multiple times ONLY IF a select was actually waiting. We go through
|
|
|
|
the list the number of waiting select calls + 1. This list is
|
|
|
|
expected to be small. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
sys_sem_wait(selectsem);
|
|
|
|
for (scb = select_cb_list; scb; scb = scb->next)
|
|
|
|
{
|
|
|
|
if (scb->sem_signalled == 0)
|
|
|
|
{
|
|
|
|
/* Test this select call for our socket */
|
|
|
|
if (scb->readset && FD_ISSET(s, scb->readset))
|
|
|
|
if (sock->rcvevent)
|
|
|
|
break;
|
|
|
|
if (scb->writeset && FD_ISSET(s, scb->writeset))
|
|
|
|
if (sock->sendevent)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (scb)
|
|
|
|
{
|
|
|
|
scb->sem_signalled = 1;
|
|
|
|
sys_sem_signal(selectsem);
|
|
|
|
sys_sem_signal(scb->sem);
|
|
|
|
} else {
|
|
|
|
sys_sem_signal(selectsem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
int lwip_shutdown(int s, int how)
|
|
|
|
{
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_shutdown(%d, how=%d)\n", s, how));
|
|
|
|
return lwip_close(s); /* XXX temporary hack until proper implementation */
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
|
2003-03-03 10:29:21 +00:00
|
|
|
int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen)
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct ip_addr naddr;
|
|
|
|
|
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2003-02-06 22:18:56 +00:00
|
|
|
return -1;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_len = sizeof(sin);
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
|
|
|
|
/* get the IP address and port of the remote host */
|
|
|
|
netconn_peer(sock->conn, &naddr, &sin.sin_port);
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getpeername(%d, addr=", s));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, &naddr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%d)\n", sin.sin_port));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sin.sin_port = htons(sin.sin_port);
|
|
|
|
sin.sin_addr.s_addr = naddr.addr;
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (*namelen > sizeof(sin))
|
2003-02-06 22:18:56 +00:00
|
|
|
*namelen = sizeof(sin);
|
|
|
|
|
|
|
|
memcpy(name, &sin, *namelen);
|
|
|
|
sock_set_errno(sock, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-03 10:29:21 +00:00
|
|
|
int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
|
|
|
struct lwip_socket *sock;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct ip_addr *naddr;
|
|
|
|
|
|
|
|
sock = get_socket(s);
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2003-02-06 22:18:56 +00:00
|
|
|
return -1;
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
memset(&sin, 0, sizeof(sin));
|
|
|
|
sin.sin_len = sizeof(sin);
|
|
|
|
sin.sin_family = AF_INET;
|
|
|
|
|
|
|
|
/* get the IP address and port of the remote host */
|
|
|
|
netconn_addr(sock->conn, &naddr, &sin.sin_port);
|
|
|
|
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockname(%d, addr=", s));
|
2003-06-11 22:11:42 +00:00
|
|
|
ip_addr_debug_print(SOCKETS_DEBUG, naddr);
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%d)\n", sin.sin_port));
|
2003-06-11 22:11:42 +00:00
|
|
|
|
2003-02-06 22:18:56 +00:00
|
|
|
sin.sin_port = htons(sin.sin_port);
|
|
|
|
sin.sin_addr.s_addr = naddr->addr;
|
|
|
|
|
2003-05-01 13:24:01 +00:00
|
|
|
if (*namelen > sizeof(sin))
|
2003-02-06 22:18:56 +00:00
|
|
|
*namelen = sizeof(sin);
|
|
|
|
|
|
|
|
memcpy(name, &sin, *namelen);
|
|
|
|
sock_set_errno(sock, 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-03-03 10:29:21 +00:00
|
|
|
int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen)
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
2003-11-14 13:17:23 +00:00
|
|
|
int err = 0;
|
2003-06-09 21:14:47 +00:00
|
|
|
struct lwip_socket *sock = get_socket(s);
|
|
|
|
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2003-11-14 13:17:23 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if( NULL == optval || NULL == optlen ) {
|
|
|
|
sock_set_errno( sock, EFAULT );
|
2003-06-09 21:14:47 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
/* Do length and type checks for the various options first, to keep it readable. */
|
|
|
|
switch( level ) {
|
|
|
|
|
|
|
|
/* Level: SOL_SOCKET */
|
|
|
|
case SOL_SOCKET:
|
|
|
|
switch(optname) {
|
|
|
|
|
|
|
|
case SO_ACCEPTCONN:
|
|
|
|
case SO_BROADCAST:
|
|
|
|
/* UNIMPL case SO_DEBUG: */
|
|
|
|
/* UNIMPL case SO_DONTROUTE: */
|
2003-06-09 21:14:47 +00:00
|
|
|
case SO_ERROR:
|
2003-11-14 13:17:23 +00:00
|
|
|
case SO_KEEPALIVE:
|
2007-03-08 20:58:46 +00:00
|
|
|
/* UNIMPL case SO_CONTIMEO: */
|
2007-03-06 16:41:02 +00:00
|
|
|
/* UNIMPL case SO_SNDTIMEO: */
|
2007-03-08 20:58:46 +00:00
|
|
|
#if LWIP_SO_RCVTIMEO
|
2007-03-06 16:41:02 +00:00
|
|
|
case SO_RCVTIMEO:
|
2007-03-08 20:58:46 +00:00
|
|
|
#endif /* LWIP_SO_RCVTIMEO */
|
2003-11-14 13:17:23 +00:00
|
|
|
/* UNIMPL case SO_OOBINLINE: */
|
|
|
|
/* UNIMPL case SO_RCVBUF: */
|
|
|
|
/* UNIMPL case SO_SNDBUF: */
|
|
|
|
/* UNIMPL case SO_RCVLOWAT: */
|
|
|
|
/* UNIMPL case SO_SNDLOWAT: */
|
2004-03-23 00:19:38 +00:00
|
|
|
#if SO_REUSE
|
2003-11-14 13:17:23 +00:00
|
|
|
case SO_REUSEADDR:
|
|
|
|
case SO_REUSEPORT:
|
|
|
|
#endif /* SO_REUSE */
|
|
|
|
case SO_TYPE:
|
|
|
|
/* UNIMPL case SO_USELOOPBACK: */
|
|
|
|
if( *optlen < sizeof(int) ) {
|
2003-06-09 21:14:47 +00:00
|
|
|
err = EINVAL;
|
2003-11-14 13:17:23 +00:00
|
|
|
}
|
2007-03-28 18:21:24 +00:00
|
|
|
break;
|
2003-11-14 13:17:23 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_IP */
|
|
|
|
case IPPROTO_IP:
|
|
|
|
switch(optname) {
|
|
|
|
/* UNIMPL case IP_HDRINCL: */
|
|
|
|
/* UNIMPL case IP_RCVDSTADDR: */
|
|
|
|
/* UNIMPL case IP_RCVIF: */
|
|
|
|
case IP_TTL:
|
|
|
|
case IP_TOS:
|
|
|
|
if( *optlen < sizeof(int) ) {
|
|
|
|
err = EINVAL;
|
2003-06-09 21:14:47 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-11-14 13:17:23 +00:00
|
|
|
|
2003-06-09 21:14:47 +00:00
|
|
|
default:
|
2003-11-14 13:17:23 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_TCP */
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
if( *optlen < sizeof(int) ) {
|
|
|
|
err = EINVAL;
|
2003-06-09 21:14:47 +00:00
|
|
|
break;
|
2007-03-28 18:21:24 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
|
|
|
/* If this is no TCP socket, ignore any options. */
|
|
|
|
if ( sock->conn->type != NETCONN_TCP ) return 0;
|
|
|
|
|
|
|
|
switch( optname ) {
|
|
|
|
case TCP_NODELAY:
|
|
|
|
case TCP_KEEPALIVE:
|
2007-03-11 15:53:43 +00:00
|
|
|
#if LWIP_TCP_KEEPALIVE
|
|
|
|
case TCP_KEEPIDLE:
|
|
|
|
case TCP_KEEPINTVL:
|
|
|
|
case TCP_KEEPCNT:
|
|
|
|
#endif /* LWIP_TCP_KEEPALIVE */
|
2003-11-14 13:17:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* UNDEFINED LEVEL */
|
|
|
|
default:
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
|
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
|
|
|
|
|
|
|
|
if( 0 != err ) {
|
|
|
|
sock_set_errno(sock, err);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Now do the actual option processing */
|
|
|
|
|
|
|
|
switch(level) {
|
|
|
|
|
|
|
|
/* Level: SOL_SOCKET */
|
|
|
|
case SOL_SOCKET:
|
|
|
|
switch( optname ) {
|
|
|
|
|
|
|
|
/* The option flags */
|
|
|
|
case SO_ACCEPTCONN:
|
|
|
|
case SO_BROADCAST:
|
|
|
|
/* UNIMPL case SO_DEBUG: */
|
|
|
|
/* UNIMPL case SO_DONTROUTE: */
|
|
|
|
case SO_KEEPALIVE:
|
|
|
|
/* UNIMPL case SO_OOBINCLUDE: */
|
2004-03-23 19:33:53 +00:00
|
|
|
#if SO_REUSE
|
2003-11-14 13:17:23 +00:00
|
|
|
case SO_REUSEADDR:
|
|
|
|
case SO_REUSEPORT:
|
|
|
|
#endif /* SO_REUSE */
|
|
|
|
/*case SO_USELOOPBACK: UNIMPL */
|
|
|
|
*(int*)optval = sock->conn->pcb.tcp->so_options & optname;
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, optname=0x%x, ..) = %s\n", s, optname, (*(int*)optval?"on":"off")));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_TYPE:
|
|
|
|
switch (sock->conn->type) {
|
|
|
|
case NETCONN_RAW:
|
|
|
|
*(int*)optval = SOCK_RAW;
|
|
|
|
break;
|
|
|
|
case NETCONN_TCP:
|
|
|
|
*(int*)optval = SOCK_STREAM;
|
|
|
|
break;
|
|
|
|
case NETCONN_UDP:
|
|
|
|
case NETCONN_UDPLITE:
|
|
|
|
case NETCONN_UDPNOCHKSUM:
|
|
|
|
*(int*)optval = SOCK_DGRAM;
|
|
|
|
break;
|
|
|
|
default: /* unrecognized socket type */
|
|
|
|
*(int*)optval = sock->conn->type;
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n", s, *(int *)optval));
|
|
|
|
} /* switch */
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SO_ERROR:
|
|
|
|
*(int *)optval = sock->err;
|
|
|
|
sock->err = 0;
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
2007-03-06 16:41:02 +00:00
|
|
|
|
2007-03-08 20:58:46 +00:00
|
|
|
#if LWIP_SO_RCVTIMEO
|
2007-03-06 16:41:02 +00:00
|
|
|
case SO_RCVTIMEO:
|
|
|
|
*(int *)optval = sock->conn->recv_timeout;
|
|
|
|
break;
|
2007-03-08 20:58:46 +00:00
|
|
|
#endif /* LWIP_SO_RCVTIMEO */
|
2003-11-14 13:17:23 +00:00
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_IP */
|
|
|
|
case IPPROTO_IP:
|
|
|
|
switch( optname ) {
|
|
|
|
case IP_TTL:
|
|
|
|
*(int*)optval = sock->conn->pcb.tcp->ttl;
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TTL) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
|
|
|
case IP_TOS:
|
|
|
|
*(int*)optval = sock->conn->pcb.tcp->tos;
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TOS) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_TCP */
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
switch( optname ) {
|
|
|
|
case TCP_NODELAY:
|
|
|
|
*(int*)optval = (sock->conn->pcb.tcp->flags & TF_NODELAY);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n", s, (*(int*)optval)?"on":"off") );
|
|
|
|
break;
|
|
|
|
case TCP_KEEPALIVE:
|
2007-03-11 15:53:43 +00:00
|
|
|
*(int*)optval = (int)sock->conn->pcb.tcp->keep_idle;
|
2003-11-14 13:17:23 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPALIVE) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
2007-03-11 15:53:43 +00:00
|
|
|
|
|
|
|
#if LWIP_TCP_KEEPALIVE
|
|
|
|
case TCP_KEEPIDLE:
|
|
|
|
*(int*)optval = (int)(sock->conn->pcb.tcp->keep_idle/1000);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPIDLE) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
|
|
|
case TCP_KEEPINTVL:
|
|
|
|
*(int*)optval = (int)(sock->conn->pcb.tcp->keep_intvl/1000);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPINTVL) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
|
|
|
case TCP_KEEPCNT:
|
|
|
|
*(int*)optval = (int)sock->conn->pcb.tcp->keep_cnt;
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, TCP_KEEPCNT) = %d\n", s, *(int *)optval));
|
|
|
|
break;
|
|
|
|
#endif /* LWIP_TCP_KEEPALIVE */
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
} /* switch */
|
|
|
|
break;
|
2003-06-09 21:14:47 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
|
|
|
|
2003-06-09 21:14:47 +00:00
|
|
|
sock_set_errno(sock, err);
|
|
|
|
return err ? -1 : 0;
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
|
2003-03-03 10:29:21 +00:00
|
|
|
int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen)
|
2003-02-06 22:18:56 +00:00
|
|
|
{
|
2003-06-09 21:14:47 +00:00
|
|
|
struct lwip_socket *sock = get_socket(s);
|
2003-11-14 13:17:23 +00:00
|
|
|
int err = 0;
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2003-06-09 21:14:47 +00:00
|
|
|
return -1;
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
if( NULL == optval ) {
|
|
|
|
sock_set_errno( sock, EFAULT );
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Do length and type checks for the various options first, to keep it readable. */
|
|
|
|
switch( level ) {
|
|
|
|
|
|
|
|
/* Level: SOL_SOCKET */
|
|
|
|
case SOL_SOCKET:
|
|
|
|
switch(optname) {
|
|
|
|
|
|
|
|
case SO_BROADCAST:
|
|
|
|
/* UNIMPL case SO_DEBUG: */
|
|
|
|
/* UNIMPL case SO_DONTROUTE: */
|
|
|
|
case SO_KEEPALIVE:
|
2007-03-08 20:58:46 +00:00
|
|
|
/* UNIMPL case case SO_CONTIMEO: */
|
2007-03-06 16:41:02 +00:00
|
|
|
/* UNIMPL case case SO_SNDTIMEO: */
|
2007-03-08 20:58:46 +00:00
|
|
|
#if LWIP_SO_RCVTIMEO
|
2007-03-06 16:41:02 +00:00
|
|
|
case SO_RCVTIMEO:
|
2007-03-08 20:58:46 +00:00
|
|
|
#endif /* LWIP_SO_RCVTIMEO */
|
2003-11-14 13:17:23 +00:00
|
|
|
/* UNIMPL case SO_OOBINLINE: */
|
|
|
|
/* UNIMPL case SO_RCVBUF: */
|
|
|
|
/* UNIMPL case SO_SNDBUF: */
|
|
|
|
/* UNIMPL case SO_RCVLOWAT: */
|
|
|
|
/* UNIMPL case SO_SNDLOWAT: */
|
2004-03-23 19:33:53 +00:00
|
|
|
#if SO_REUSE
|
2003-11-14 13:17:23 +00:00
|
|
|
case SO_REUSEADDR:
|
|
|
|
case SO_REUSEPORT:
|
|
|
|
#endif /* SO_REUSE */
|
|
|
|
/* UNIMPL case SO_USELOOPBACK: */
|
|
|
|
if( optlen < sizeof(int) ) {
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_IP */
|
|
|
|
case IPPROTO_IP:
|
|
|
|
switch(optname) {
|
|
|
|
/* UNIMPL case IP_HDRINCL: */
|
|
|
|
/* UNIMPL case IP_RCVDSTADDR: */
|
|
|
|
/* UNIMPL case IP_RCVIF: */
|
|
|
|
case IP_TTL:
|
|
|
|
case IP_TOS:
|
|
|
|
if( optlen < sizeof(int) ) {
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
2007-03-28 18:21:24 +00:00
|
|
|
break;
|
2007-03-11 19:16:38 +00:00
|
|
|
#if LWIP_IGMP
|
|
|
|
case IP_MULTICAST_TTL:
|
2007-03-21 12:50:04 +00:00
|
|
|
{
|
|
|
|
/* NOTE, some BSD implementation use "int", some others "char" */
|
|
|
|
if(( optlen != sizeof(char) ) && ( optlen != sizeof(int) ))
|
|
|
|
err = EINVAL;
|
2007-03-11 19:16:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IP_ADD_MEMBERSHIP:
|
|
|
|
case IP_DROP_MEMBERSHIP:
|
2007-03-28 18:21:24 +00:00
|
|
|
{ if( optlen < sizeof(struct ip_mreq) ) {
|
|
|
|
err = EINVAL;
|
|
|
|
}
|
2007-03-11 19:16:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* LWIP_IGMP */
|
2003-06-09 21:14:47 +00:00
|
|
|
default:
|
2007-03-28 18:21:24 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
|
|
|
err = ENOPROTOOPT;
|
2003-11-14 13:17:23 +00:00
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_TCP */
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
if( optlen < sizeof(int) ) {
|
|
|
|
err = EINVAL;
|
2007-03-28 18:21:24 +00:00
|
|
|
break;
|
2003-06-09 21:14:47 +00:00
|
|
|
}
|
2003-11-14 13:17:23 +00:00
|
|
|
|
|
|
|
/* If this is no TCP socket, ignore any options. */
|
|
|
|
if ( sock->conn->type != NETCONN_TCP ) return 0;
|
|
|
|
|
|
|
|
switch( optname ) {
|
|
|
|
case TCP_NODELAY:
|
|
|
|
case TCP_KEEPALIVE:
|
2007-03-11 15:53:43 +00:00
|
|
|
#if LWIP_TCP_KEEPALIVE
|
|
|
|
case TCP_KEEPIDLE:
|
|
|
|
case TCP_KEEPINTVL:
|
|
|
|
case TCP_KEEPCNT:
|
|
|
|
#endif /* LWIP_TCP_KEEPALIVE */
|
2003-11-14 13:17:23 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", s, optname));
|
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
2007-03-28 18:21:24 +00:00
|
|
|
/* UNDEFINED LEVEL */
|
2003-11-14 13:17:23 +00:00
|
|
|
default:
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", s, level, optname));
|
2003-11-14 13:17:23 +00:00
|
|
|
err = ENOPROTOOPT;
|
|
|
|
} /* switch */
|
|
|
|
|
|
|
|
|
|
|
|
if( 0 != err ) {
|
|
|
|
sock_set_errno(sock, err);
|
|
|
|
return -1;
|
2003-06-09 21:14:47 +00:00
|
|
|
}
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
|
|
|
|
/* Now do the actual option processing */
|
|
|
|
|
|
|
|
switch(level) {
|
|
|
|
|
|
|
|
/* Level: SOL_SOCKET */
|
|
|
|
case SOL_SOCKET:
|
|
|
|
switch(optname) {
|
|
|
|
|
|
|
|
/* The option flags */
|
|
|
|
case SO_BROADCAST:
|
|
|
|
/* UNIMPL case SO_DEBUG: */
|
|
|
|
/* UNIMPL case SO_DONTROUTE: */
|
|
|
|
case SO_KEEPALIVE:
|
|
|
|
/* UNIMPL case SO_OOBINCLUDE: */
|
2004-03-23 19:33:53 +00:00
|
|
|
#if SO_REUSE
|
2003-11-14 13:17:23 +00:00
|
|
|
case SO_REUSEADDR:
|
|
|
|
case SO_REUSEPORT:
|
|
|
|
#endif /* SO_REUSE */
|
|
|
|
/* UNIMPL case SO_USELOOPBACK: */
|
|
|
|
if ( *(int*)optval ) {
|
|
|
|
sock->conn->pcb.tcp->so_options |= optname;
|
|
|
|
} else {
|
|
|
|
sock->conn->pcb.tcp->so_options &= ~optname;
|
|
|
|
}
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n", s, optname, (*(int*)optval?"on":"off")));
|
|
|
|
break;
|
2007-03-08 20:58:46 +00:00
|
|
|
#if LWIP_SO_RCVTIMEO
|
2007-03-06 16:41:02 +00:00
|
|
|
case SO_RCVTIMEO:
|
|
|
|
sock->conn->recv_timeout = ( *(int*)optval );
|
|
|
|
break;
|
2007-03-08 20:58:46 +00:00
|
|
|
#endif /* LWIP_SO_RCVTIMEO */
|
2003-11-14 13:17:23 +00:00
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_IP */
|
|
|
|
case IPPROTO_IP:
|
|
|
|
switch( optname ) {
|
|
|
|
case IP_TTL:
|
|
|
|
sock->conn->pcb.tcp->ttl = (u8_t)(*(int*)optval);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %u\n", s, sock->conn->pcb.tcp->ttl));
|
|
|
|
break;
|
|
|
|
case IP_TOS:
|
|
|
|
sock->conn->pcb.tcp->tos = (u8_t)(*(int*)optval);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %u\n", s, sock->conn->pcb.tcp->tos));
|
|
|
|
break;
|
2007-03-11 19:16:38 +00:00
|
|
|
#if LWIP_IGMP
|
|
|
|
case IP_MULTICAST_TTL:
|
|
|
|
{ if (optlen==sizeof(int)) sock->conn->pcb.tcp->ttl = (u8_t)(*(int*) optval);
|
|
|
|
if (optlen==sizeof(u8_t)) sock->conn->pcb.tcp->ttl = (u8_t)(*(u8_t*)optval);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IP_ADD_MEMBERSHIP:
|
|
|
|
case IP_DROP_MEMBERSHIP:
|
|
|
|
{ /* If this is a TCP or a RAW socket, ignore these options. */
|
|
|
|
if ((sock->conn->type == NETCONN_TCP) || (sock->conn->type == NETCONN_RAW))
|
|
|
|
{ err = EAFNOSUPPORT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ struct ip_mreq *imr = (struct ip_mreq *)optval;
|
|
|
|
if (netconn_join_leave_group( sock->conn, (struct ip_addr *)&(imr->imr_multiaddr.s_addr), (struct ip_addr *)&(imr->imr_interface.s_addr), ((optname==IP_ADD_MEMBERSHIP)?NETCONN_JOIN:NETCONN_LEAVE)) < 0)
|
|
|
|
{ err = EADDRNOTAVAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* LWIP_IGMP */
|
2003-11-14 13:17:23 +00:00
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Level: IPPROTO_TCP */
|
|
|
|
case IPPROTO_TCP:
|
|
|
|
switch( optname ) {
|
|
|
|
case TCP_NODELAY:
|
|
|
|
if ( *(int*)optval ) {
|
|
|
|
sock->conn->pcb.tcp->flags |= TF_NODELAY;
|
|
|
|
} else {
|
|
|
|
sock->conn->pcb.tcp->flags &= ~TF_NODELAY;
|
|
|
|
}
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_NODELAY) -> %s\n", s, (*(int *)optval)?"on":"off") );
|
|
|
|
break;
|
|
|
|
case TCP_KEEPALIVE:
|
2007-03-11 15:53:43 +00:00
|
|
|
sock->conn->pcb.tcp->keep_idle = (u32_t)(*(int*)optval);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %lu\n", s, sock->conn->pcb.tcp->keep_idle));
|
2003-11-14 13:17:23 +00:00
|
|
|
break;
|
2007-03-11 15:53:43 +00:00
|
|
|
|
|
|
|
#if LWIP_TCP_KEEPALIVE
|
|
|
|
case TCP_KEEPIDLE:
|
|
|
|
sock->conn->pcb.tcp->keep_idle = 1000*(u32_t)(*(int*)optval);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %lu\n", s, sock->conn->pcb.tcp->keep_idle));
|
|
|
|
break;
|
|
|
|
case TCP_KEEPINTVL:
|
|
|
|
sock->conn->pcb.tcp->keep_intvl = 1000*(u32_t)(*(int*)optval);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %lu\n", s, sock->conn->pcb.tcp->keep_intvl));
|
|
|
|
break;
|
|
|
|
case TCP_KEEPCNT:
|
|
|
|
sock->conn->pcb.tcp->keep_cnt = (u32_t)(*(int*)optval);
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %lu\n", s, sock->conn->pcb.tcp->keep_cnt));
|
|
|
|
break;
|
|
|
|
#endif /* LWIP_TCP_KEEPALIVE */
|
|
|
|
|
2003-11-14 13:17:23 +00:00
|
|
|
} /* switch */
|
|
|
|
break;
|
|
|
|
} /* switch */
|
|
|
|
|
2003-06-09 21:14:47 +00:00
|
|
|
sock_set_errno(sock, err);
|
|
|
|
return err ? -1 : 0;
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int lwip_ioctl(int s, long cmd, void *argp)
|
|
|
|
{
|
2003-06-09 21:14:47 +00:00
|
|
|
struct lwip_socket *sock = get_socket(s);
|
2007-05-03 19:13:27 +00:00
|
|
|
u16_t buflen = 0;
|
2003-06-09 21:14:47 +00:00
|
|
|
|
2007-03-11 16:53:37 +00:00
|
|
|
if (!sock)
|
2003-06-09 21:14:47 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONREAD:
|
|
|
|
if (!argp) {
|
|
|
|
sock_set_errno(sock, EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*((u16_t*)argp) = sock->conn->recv_avail;
|
|
|
|
|
2007-05-03 19:13:27 +00:00
|
|
|
/* Check if there is data left from the last recv operation. /maq 041215 */
|
|
|
|
if (sock->lastdata) {
|
|
|
|
buflen = netbuf_len(sock->lastdata);
|
|
|
|
buflen -= sock->lastoffset;
|
|
|
|
|
|
|
|
*((u16_t*)argp) += buflen;
|
|
|
|
}
|
|
|
|
|
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONREAD, %p) = %u\n", s, argp, *((u16_t*)argp)));
|
2003-11-14 13:17:23 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2003-06-09 21:14:47 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FIONBIO:
|
|
|
|
if (argp && *(u32_t*)argp)
|
|
|
|
sock->flags |= O_NONBLOCK;
|
|
|
|
else
|
|
|
|
sock->flags &= ~O_NONBLOCK;
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONBIO, %d)\n", s, !!(sock->flags & O_NONBLOCK)));
|
2003-11-14 13:17:23 +00:00
|
|
|
sock_set_errno(sock, 0);
|
2003-06-09 21:14:47 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
2003-06-10 10:45:29 +00:00
|
|
|
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp));
|
2003-06-09 21:14:47 +00:00
|
|
|
sock_set_errno(sock, ENOSYS); /* not yet implemented */
|
|
|
|
return -1;
|
|
|
|
}
|
2003-02-06 22:18:56 +00:00
|
|
|
}
|
|
|
|
|