1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
19658: sys/posix/sockets: fix code style & set sin6_scope_id in _ep_to_sockaddr()  r=benpicco a=maribu

### Contribution description

- Fix double indent of switch cases to single indent, as per coding convention. (Whitespace only change.)
- Set sin6_scope_id to netif in `_ep_to_sockaddr()`


Co-authored-by: Marian Buschsieweke <marian.buschsieweke@ovgu.de>
This commit is contained in:
bors[bot] 2023-05-24 02:20:38 +00:00 committed by GitHub
commit e93d597510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -172,32 +172,32 @@ static inline int _choose_ipproto(int type, int protocol)
{ {
switch (type) { switch (type) {
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
if ((protocol == 0) || (protocol == IPPROTO_TCP)) { if ((protocol == 0) || (protocol == IPPROTO_TCP)) {
return protocol; return protocol;
} }
else { else {
errno = EPROTOTYPE; errno = EPROTOTYPE;
} }
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
if ((protocol == 0) || (protocol == IPPROTO_UDP)) { if ((protocol == 0) || (protocol == IPPROTO_UDP)) {
return protocol; return protocol;
} }
else { else {
errno = EPROTOTYPE; errno = EPROTOTYPE;
} }
break; break;
#endif #endif
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
return protocol; return protocol;
#endif #endif
default: default:
(void)protocol; (void)protocol;
break; break;
} }
errno = EPROTONOSUPPORT; errno = EPROTONOSUPPORT;
return -1; return -1;
@ -214,9 +214,9 @@ static inline socklen_t _addr_truncate(struct sockaddr *out, socklen_t out_len,
static int _ep_to_sockaddr(const struct _sock_tl_ep *ep, static int _ep_to_sockaddr(const struct _sock_tl_ep *ep,
struct sockaddr_storage *out) struct sockaddr_storage *out)
{ {
assert((ep->family == AF_INET) || (ep->family == AF_INET6));
switch (ep->family) { switch (ep->family) {
case AF_INET: { case AF_INET:
{
struct sockaddr_in *in_addr = (struct sockaddr_in *)out; struct sockaddr_in *in_addr = (struct sockaddr_in *)out;
in_addr->sin_family = AF_INET; in_addr->sin_family = AF_INET;
@ -225,18 +225,21 @@ static int _ep_to_sockaddr(const struct _sock_tl_ep *ep,
return sizeof(struct sockaddr_in); return sizeof(struct sockaddr_in);
} }
#ifdef SOCK_HAS_IPV6 #ifdef SOCK_HAS_IPV6
case AF_INET6: { case AF_INET6:
{
struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)out; struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)out;
in6_addr->sin6_family = AF_INET6; in6_addr->sin6_family = AF_INET6;
memcpy(&in6_addr->sin6_addr, &ep->addr.ipv6, sizeof(ep->addr.ipv6)); memcpy(&in6_addr->sin6_addr, &ep->addr.ipv6, sizeof(ep->addr.ipv6));
in6_addr->sin6_port = htons(ep->port); in6_addr->sin6_port = htons(ep->port);
in6_addr->sin6_scope_id = ep->netif;
return sizeof(struct sockaddr_in6); return sizeof(struct sockaddr_in6);
} }
#endif #endif
default: default:
/* should not happen */ /* should not happen */
return 0; assert(0);
return 0;
} }
} }
@ -246,36 +249,36 @@ static int _sockaddr_to_ep(const struct sockaddr *address, socklen_t address_len
assert(address != NULL); assert(address != NULL);
switch (address->sa_family) { switch (address->sa_family) {
case AF_INET: case AF_INET:
if (address_len < sizeof(struct sockaddr_in)) { if (address_len < sizeof(struct sockaddr_in)) {
errno = EINVAL; errno = EINVAL;
return -1;
}
struct sockaddr_in *in_addr = (struct sockaddr_in *)address;
memset(out, 0, sizeof(*out));
out->family = AF_INET;
out->addr.ipv4_u32 = in_addr->sin_addr.s_addr;
out->port = ntohs(in_addr->sin_port);
break;
#ifdef SOCK_HAS_IPV6
case AF_INET6:
if (address_len < sizeof(struct sockaddr_in6)) {
errno = EINVAL;
return -1;
}
struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)address;
memset(out, 0, sizeof(*out));
out->family = AF_INET6;
memcpy(&out->addr.ipv6, &in6_addr->sin6_addr, sizeof(out->addr.ipv6));
out->port = ntohs(in6_addr->sin6_port);
if (in6_addr->sin6_scope_id != 0) {
out->netif = (uint16_t) in6_addr->sin6_scope_id;
}
break;
#endif
default:
errno = EAFNOSUPPORT;
return -1; return -1;
}
struct sockaddr_in *in_addr = (struct sockaddr_in *)address;
memset(out, 0, sizeof(*out));
out->family = AF_INET;
out->addr.ipv4_u32 = in_addr->sin_addr.s_addr;
out->port = ntohs(in_addr->sin_port);
break;
#ifdef SOCK_HAS_IPV6
case AF_INET6:
if (address_len < sizeof(struct sockaddr_in6)) {
errno = EINVAL;
return -1;
}
struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)address;
memset(out, 0, sizeof(*out));
out->family = AF_INET6;
memcpy(&out->addr.ipv6, &in6_addr->sin6_addr, sizeof(out->addr.ipv6));
out->port = ntohs(in6_addr->sin6_port);
if (in6_addr->sin6_scope_id != 0) {
out->netif = (uint16_t) in6_addr->sin6_scope_id;
}
break;
#endif
default:
errno = EAFNOSUPPORT;
return -1;
} }
return 0; return 0;
} }
@ -291,29 +294,29 @@ static int socket_close(vfs_file_t *filp)
int idx = _get_sock_idx(s->sock); int idx = _get_sock_idx(s->sock);
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
sock_udp_close(&s->sock->udp); sock_udp_close(&s->sock->udp);
break; break;
#endif #endif
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
sock_ip_close(&s->sock->raw); sock_ip_close(&s->sock->raw);
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
if (s->queue_array == NULL) { if (s->queue_array == NULL) {
sock_tcp_disconnect(&s->sock->tcp.sock); sock_tcp_disconnect(&s->sock->tcp.sock);
} }
else { else {
sock_tcp_stop_listen(&s->sock->tcp.queue); sock_tcp_stop_listen(&s->sock->tcp.queue);
} }
break; break;
#endif #endif
default: default:
errno = EOPNOTSUPP; errno = EOPNOTSUPP;
res = -1; res = -1;
break; break;
} }
if (idx >= 0) { if (idx >= 0) {
bf_unset(_sock_pool_used, idx); bf_unset(_sock_pool_used, idx);
@ -396,30 +399,30 @@ static void _sock_set_cb(socket_t *socket)
switch (socket->type) { switch (socket->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
sock_ip_set_cb(&socket->sock->raw, callback.ip, socket); sock_ip_set_cb(&socket->sock->raw, callback.ip, socket);
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
/* is a TCP client socket */ /* is a TCP client socket */
if (socket->queue_array == NULL) { if (socket->queue_array == NULL) {
sock_tcp_set_cb(&socket->sock->tcp.sock, callback.tcp, socket); sock_tcp_set_cb(&socket->sock->tcp.sock, callback.tcp, socket);
} }
/* is a TCP listening socket */ /* is a TCP listening socket */
else { else {
sock_tcp_queue_set_cb(&socket->sock->tcp.queue, sock_tcp_queue_set_cb(&socket->sock->tcp.queue,
callback.tcp_queue, socket); callback.tcp_queue, socket);
} }
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
sock_udp_set_cb(&socket->sock->udp, callback.udp, socket); sock_udp_set_cb(&socket->sock->udp, callback.udp, socket);
break; break;
#endif #endif
default: default:
break; break;
} }
} }
#endif #endif
@ -437,46 +440,46 @@ int socket(int domain, int type, int protocol)
return -1; return -1;
} }
switch (domain) { switch (domain) {
case AF_INET: case AF_INET:
#ifdef SOCK_HAS_IPV6 #ifdef SOCK_HAS_IPV6
case AF_INET6: case AF_INET6:
#endif #endif
{ {
int fd = vfs_bind(VFS_ANY_FD, O_RDWR, &socket_ops, s); int fd = vfs_bind(VFS_ANY_FD, O_RDWR, &socket_ops, s);
if (fd < 0) { if (fd < 0) {
errno = ENFILE; errno = ENFILE;
res = -1; res = -1;
break;
}
else {
s->fd = res = fd;
}
s->domain = domain;
s->type = type;
if ((s->protocol = _choose_ipproto(type, protocol)) < 0) {
res = -1;
break;
}
s->bound = false;
s->sock = NULL;
#ifdef POSIX_SETSOCKOPT
s->recv_timeout = SOCK_NO_TIMEOUT;
#endif
#ifdef MODULE_SOCK_TCP
if (type == SOCK_STREAM) {
s->queue_array = NULL;
s->queue_array_len = 0;
memset(&s->local, 0, sizeof(sock_tcp_ep_t));
}
#endif
break; break;
} }
default: else {
(void)type; s->fd = res = fd;
(void)protocol; }
errno = EAFNOSUPPORT; s->domain = domain;
s->type = type;
if ((s->protocol = _choose_ipproto(type, protocol)) < 0) {
res = -1; res = -1;
break;
}
s->bound = false;
s->sock = NULL;
#ifdef POSIX_SETSOCKOPT
s->recv_timeout = SOCK_NO_TIMEOUT;
#endif
#ifdef MODULE_SOCK_TCP
if (type == SOCK_STREAM) {
s->queue_array = NULL;
s->queue_array_len = 0;
memset(&s->local, 0, sizeof(sock_tcp_ep_t));
}
#endif
break;
}
default:
(void)type;
(void)protocol;
errno = EAFNOSUPPORT;
res = -1;
} }
mutex_unlock(&_socket_pool_mutex); mutex_unlock(&_socket_pool_mutex);
return res; return res;
@ -510,63 +513,63 @@ int accept(int socket, struct sockaddr *restrict address,
#endif #endif
switch (s->type) { switch (s->type) {
case SOCK_STREAM: case SOCK_STREAM:
new_s = _get_free_socket(); new_s = _get_free_socket();
if (new_s == NULL) { if (new_s == NULL) {
errno = ENFILE;
res = -1;
break;
}
sock = (sock_tcp_t *)new_s->sock;
if ((res = sock_tcp_accept(&s->sock->tcp.queue, &sock,
recv_timeout)) < 0) {
errno = -res;
res = -1;
break;
}
else {
if ((address != NULL) && (address_len != NULL)) {
sock_tcp_ep_t ep;
struct sockaddr_storage sa;
socklen_t sa_len;
if ((res = sock_tcp_get_remote(sock, &ep)) < 0) {
errno = -res;
res = -1;
break;
}
sa.ss_family = s->domain;
sa_len = _ep_to_sockaddr(&ep, &sa);
*address_len = _addr_truncate(address, *address_len, &sa,
sa_len);
}
int fd = vfs_bind(VFS_ANY_FD, O_RDWR, &socket_ops, new_s);
if (fd < 0) {
errno = ENFILE; errno = ENFILE;
res = -1; res = -1;
break; break;
} }
sock = (sock_tcp_t *)new_s->sock;
if ((res = sock_tcp_accept(&s->sock->tcp.queue, &sock,
recv_timeout)) < 0) {
errno = -res;
res = -1;
break;
}
else { else {
if ((address != NULL) && (address_len != NULL)) { new_s->fd = res = fd;
sock_tcp_ep_t ep;
struct sockaddr_storage sa;
socklen_t sa_len;
if ((res = sock_tcp_get_remote(sock, &ep)) < 0) {
errno = -res;
res = -1;
break;
}
sa.ss_family = s->domain;
sa_len = _ep_to_sockaddr(&ep, &sa);
*address_len = _addr_truncate(address, *address_len, &sa,
sa_len);
}
int fd = vfs_bind(VFS_ANY_FD, O_RDWR, &socket_ops, new_s);
if (fd < 0) {
errno = ENFILE;
res = -1;
break;
}
else {
new_s->fd = res = fd;
}
new_s->domain = s->domain;
new_s->type = s->type;
new_s->protocol = s->protocol;
new_s->bound = true;
new_s->queue_array = NULL;
new_s->queue_array_len = 0;
new_s->sock = (socket_sock_t *)sock;
#if IS_USED(MODULE_SOCK_ASYNC)
_sock_set_cb(new_s);
#endif
memset(&s->local, 0, sizeof(sock_tcp_ep_t));
} }
break; new_s->domain = s->domain;
default: new_s->type = s->type;
errno = EOPNOTSUPP; new_s->protocol = s->protocol;
res = -1; new_s->bound = true;
break; new_s->queue_array = NULL;
new_s->queue_array_len = 0;
new_s->sock = (socket_sock_t *)sock;
#if IS_USED(MODULE_SOCK_ASYNC)
_sock_set_cb(new_s);
#endif
memset(&s->local, 0, sizeof(sock_tcp_ep_t));
}
break;
default:
errno = EOPNOTSUPP;
res = -1;
break;
} }
if ((res < 0) && (sock != NULL)) { if ((res < 0) && (sock != NULL)) {
sock_tcp_disconnect(sock); sock_tcp_disconnect(sock);
@ -605,21 +608,21 @@ int bind(int socket, const struct sockaddr *address, socklen_t address_len)
} }
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
break; break;
#endif #endif
default: default:
(void)res; (void)res;
errno = EOPNOTSUPP; errno = EOPNOTSUPP;
return -1; return -1;
} }
if (_sockaddr_to_ep(address, address_len, &s->local) < 0) { if (_sockaddr_to_ep(address, address_len, &s->local) < 0) {
return -1; return -1;
@ -658,31 +661,31 @@ static int _bind_connect(socket_t *s, const struct sockaddr *address,
} }
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
/* TODO apply flags if possible */ /* TODO apply flags if possible */
res = sock_ip_create(&sock->raw, (sock_ip_ep_t *)local, res = sock_ip_create(&sock->raw, (sock_ip_ep_t *)local,
(sock_ip_ep_t *)remote, s->protocol, 0); (sock_ip_ep_t *)remote, s->protocol, 0);
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
/* TODO apply flags if possible */ /* TODO apply flags if possible */
assert(remote != NULL); assert(remote != NULL);
res = sock_tcp_connect(&sock->tcp.sock, remote, res = sock_tcp_connect(&sock->tcp.sock, remote,
(local == NULL) ? 0 : local->port, 0); (local == NULL) ? 0 : local->port, 0);
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
/* TODO apply flags if possible */ /* TODO apply flags if possible */
res = sock_udp_create(&sock->udp, local, remote, 0); res = sock_udp_create(&sock->udp, local, remote, 0);
break; break;
#endif #endif
default: default:
(void)local; (void)local;
(void)remote; (void)remote;
res = -EOPNOTSUPP; res = -EOPNOTSUPP;
break; break;
} }
if (res < 0) { if (res < 0) {
errno = -res; errno = -res;
@ -737,28 +740,28 @@ static int _getpeername(socket_t *s, struct sockaddr *__restrict address,
} }
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
res = sock_ip_get_remote(&s->sock->raw, (sock_ip_ep_t *)&ep); res = sock_ip_get_remote(&s->sock->raw, (sock_ip_ep_t *)&ep);
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
if (s->queue_array == NULL) { if (s->queue_array == NULL) {
res = sock_tcp_get_remote(&s->sock->tcp.sock, &ep); res = sock_tcp_get_remote(&s->sock->tcp.sock, &ep);
} }
else { else {
res = -ENOTCONN; res = -ENOTCONN;
} }
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
res = sock_udp_get_remote(&s->sock->udp, &ep); res = sock_udp_get_remote(&s->sock->udp, &ep);
break; break;
#endif #endif
default: default:
res = -EOPNOTSUPP; res = -EOPNOTSUPP;
break; break;
} }
if (res >= 0) { if (res >= 0) {
struct sockaddr_storage sa; struct sockaddr_storage sa;
@ -811,28 +814,28 @@ int getsockname(int socket, struct sockaddr *__restrict address,
struct _sock_tl_ep ep; struct _sock_tl_ep ep;
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
res = sock_ip_get_local(&s->sock->raw, (sock_ip_ep_t *)&ep); res = sock_ip_get_local(&s->sock->raw, (sock_ip_ep_t *)&ep);
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
if (s->queue_array == NULL) { if (s->queue_array == NULL) {
res = sock_tcp_get_local(&s->sock->tcp.sock, &ep); res = sock_tcp_get_local(&s->sock->tcp.sock, &ep);
} }
else { else {
res = sock_tcp_queue_get_local(&s->sock->tcp.queue, &ep); res = sock_tcp_queue_get_local(&s->sock->tcp.queue, &ep);
} }
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
res = sock_udp_get_local(&s->sock->udp, &ep); res = sock_udp_get_local(&s->sock->udp, &ep);
break; break;
#endif #endif
default: default:
res = -EOPNOTSUPP; res = -EOPNOTSUPP;
break; break;
} }
sa_len = _ep_to_sockaddr(&ep, &sa); sa_len = _ep_to_sockaddr(&ep, &sa);
} }
@ -948,29 +951,29 @@ static ssize_t socket_recvfrom(socket_t *s, void *restrict buffer,
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
res = sock_ip_recv(&s->sock->raw, buffer, length, recv_timeout, res = sock_ip_recv(&s->sock->raw, buffer, length, recv_timeout,
(sock_ip_ep_t *)&ep); (sock_ip_ep_t *)&ep);
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
res = sock_tcp_read(&s->sock->tcp.sock, buffer, length, res = sock_tcp_read(&s->sock->tcp.sock, buffer, length,
recv_timeout); recv_timeout);
break; break;
#endif #endif
#ifdef MODULE_SOCK_UDP #ifdef MODULE_SOCK_UDP
case SOCK_DGRAM: case SOCK_DGRAM:
res = sock_udp_recv(&s->sock->udp, buffer, length, recv_timeout, res = sock_udp_recv(&s->sock->udp, buffer, length, recv_timeout,
&ep); &ep);
break; break;
#endif #endif
default: default:
#if !defined(MODULE_SOCK_IP) && !defined(MODULE_SOCK_TCP) && !defined(MODULE_SOCK_UDP) #if !defined(MODULE_SOCK_IP) && !defined(MODULE_SOCK_TCP) && !defined(MODULE_SOCK_UDP)
(void) recv_timeout; (void) recv_timeout;
#endif #endif
res = -EOPNOTSUPP; res = -EOPNOTSUPP;
break; break;
} }
if ((res >= 0) && (address != NULL) && (address_len != NULL)) { if ((res >= 0) && (address != NULL) && (address_len != NULL)) {
#ifdef MODULE_SOCK_ASYNC #ifdef MODULE_SOCK_ASYNC
@ -978,11 +981,12 @@ static ssize_t socket_recvfrom(socket_t *s, void *restrict buffer,
#endif #endif
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
res = _getpeername(s, address, address_len); res = _getpeername(s, address, address_len);
break; break;
#endif #endif
default: { default:
{
struct sockaddr_storage sa; struct sockaddr_storage sa;
socklen_t sa_len; socklen_t sa_len;
@ -1045,47 +1049,47 @@ static ssize_t socket_sendto(socket_t *s, const void *buffer, size_t length,
#endif #endif
switch (s->type) { switch (s->type) {
#ifdef MODULE_SOCK_IP #ifdef MODULE_SOCK_IP
case SOCK_RAW: case SOCK_RAW:
if ((res = sock_ip_send(&s->sock->raw, buffer, length, if ((res = sock_ip_send(&s->sock->raw, buffer, length,
s->protocol, (sock_ip_ep_t *)&ep)) < 0) { s->protocol, (sock_ip_ep_t *)&ep)) < 0) {
errno = -res; errno = -res;
res = -1; res = -1;
} }
break; break;
#endif #endif
#ifdef MODULE_SOCK_TCP #ifdef MODULE_SOCK_TCP
case SOCK_STREAM: case SOCK_STREAM:
if (address == NULL) { if (address == NULL) {
(void)address_len; (void)address_len;
if ((res = sock_tcp_write(&s->sock->tcp.sock, buffer, length)) < 0) { if ((res = sock_tcp_write(&s->sock->tcp.sock, buffer, length)) < 0) {
errno = -res;
res = -1;
}
}
else {
res = -1;
errno = EISCONN;
}
break;
#endif
#ifdef MODULE_SOCK_UDP
case SOCK_DGRAM:
if (address == NULL) {
res = sock_udp_get_remote(&s->sock->udp, &ep);
} else {
res = _sockaddr_to_ep(address, address_len, &ep);
}
if ((res < 0) ||
(res = sock_udp_send(&s->sock->udp, buffer, length, &ep)) < 0) {
errno = -res; errno = -res;
res = -1; res = -1;
} }
break; }
#endif else {
default:
res = -1; res = -1;
errno = EOPNOTSUPP; errno = EISCONN;
break; }
break;
#endif
#ifdef MODULE_SOCK_UDP
case SOCK_DGRAM:
if (address == NULL) {
res = sock_udp_get_remote(&s->sock->udp, &ep);
} else {
res = _sockaddr_to_ep(address, address_len, &ep);
}
if ((res < 0) ||
(res = sock_udp_send(&s->sock->udp, buffer, length, &ep)) < 0) {
errno = -res;
res = -1;
}
break;
#endif
default:
res = -1;
errno = EOPNOTSUPP;
break;
} }
return res; return res;
} }