mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-07 15:04:39 +08:00
Start working task #14494: Implement SO_BINDTODEVICE
Implement setsockopt. TODO: getsockopt
This commit is contained in:
parent
eab2ae5d78
commit
c7e3519f46
@ -2920,6 +2920,38 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_
|
||||
}
|
||||
break;
|
||||
#endif /* LWIP_UDP */
|
||||
case SO_BINDTODEVICE:
|
||||
{
|
||||
struct ifreq *iface;
|
||||
struct netif* n = NULL;
|
||||
|
||||
LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, struct ifreq);
|
||||
|
||||
iface = (struct ifreq*)optval;
|
||||
if (iface->ifr_name[0] != 0) {
|
||||
n = netif_find(iface->ifr_name);
|
||||
if (n == NULL) {
|
||||
done_socket(sock);
|
||||
return ENODEV;
|
||||
}
|
||||
}
|
||||
|
||||
switch (NETCONNTYPE_GROUP(netconn_type(sock->conn)))
|
||||
{
|
||||
case NETCONN_TCP:
|
||||
tcp_bind_netif(sock->conn->pcb.tcp, n);
|
||||
break;
|
||||
case NETCONN_UDP:
|
||||
udp_bind_netif(sock->conn->pcb.udp, n);
|
||||
break;
|
||||
case NETCONN_RAW:
|
||||
raw_bind_netif(sock->conn->pcb.raw, n);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n",
|
||||
s, optname));
|
||||
|
@ -58,7 +58,7 @@ extern "C" {
|
||||
|
||||
#if !LWIP_TCPIP_CORE_LOCKING
|
||||
/** Maximum optlen used by setsockopt/getsockopt */
|
||||
#define LWIP_SETGETSOCKOPT_MAXOPTLEN 16
|
||||
#define LWIP_SETGETSOCKOPT_MAXOPTLEN LWIP_MAX(16, sizeof(struct ifreq))
|
||||
|
||||
/** This struct is used to pass data to the set/getsockopt_internal
|
||||
* functions running in tcpip_thread context (only a void* is allowed) */
|
||||
|
@ -44,6 +44,7 @@
|
||||
#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
|
||||
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "lwip/netif.h"
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/errno.h"
|
||||
@ -175,6 +176,12 @@ will need to increase long long */
|
||||
#define CMSG_LEN(length) (ALIGN_D(sizeof(struct cmsghdr)) + \
|
||||
length)
|
||||
|
||||
/* Set socket options argument */
|
||||
#define IFNAMSIZ NETIF_NAMESIZE
|
||||
struct ifreq {
|
||||
char ifr_name[IFNAMSIZ]; /* Interface name */
|
||||
};
|
||||
|
||||
/* Socket protocol types (TCP/UDP/RAW) */
|
||||
#define SOCK_STREAM 1
|
||||
#define SOCK_DGRAM 2
|
||||
@ -209,7 +216,7 @@ will need to increase long long */
|
||||
#define SO_TYPE 0x1008 /* get socket type */
|
||||
#define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
|
||||
#define SO_NO_CHECK 0x100a /* don't create UDP checksum */
|
||||
|
||||
#define SO_BINDTODEVICE 0x100b /* bind to device */
|
||||
|
||||
/*
|
||||
* Structure used for manipulating linger option.
|
||||
|
Loading…
x
Reference in New Issue
Block a user