fixed bug #38404 getpeeraddr returns success on unconnected/listening TCP sockets

This commit is contained in:
Simon Goldschmidt 2014-02-27 21:28:15 +01:00
parent 2666d6df90
commit c60635855d
3 changed files with 17 additions and 2 deletions

View File

@ -96,6 +96,10 @@ HISTORY
++ Bugfixes:
2014-02-27: Simon Goldschmidt
* api_msg.c, sockets.c: fixed bug #38404 getpeeraddr returns success on
unconnected/listening TCP sockets
2014-02-27: Simon Goldschmidt
* sockets.c: fixed bug #41729 Some socket functions return Exyz instead of -1

View File

@ -1455,7 +1455,13 @@ lwip_netconn_do_getaddr(struct api_msg_msg *msg)
#endif /* LWIP_UDP */
#if LWIP_TCP
case NETCONN_TCP:
API_EXPR_DEREF(msg->msg.ad.port) = (msg->msg.ad.local?msg->conn->pcb.tcp->local_port:msg->conn->pcb.tcp->remote_port);
if ((msg->msg.ad.local == 0) &&
((msg->conn->pcb.tcp->state == CLOSED) || (msg->conn->pcb.tcp->state == LISTEN))) {
/* pcb is not connected and remote name is requested */
msg->err = ERR_CONN;
} else {
API_EXPR_DEREF(msg->msg.ad.port) = (msg->msg.ad.local ? msg->conn->pcb.tcp->local_port : msg->conn->pcb.tcp->remote_port);
}
break;
#endif /* LWIP_TCP */
default:

View File

@ -1478,6 +1478,7 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
union sockaddr_aligned saddr;
ipX_addr_t naddr;
u16_t port;
err_t err;
sock = get_socket(s);
if (!sock) {
@ -1486,7 +1487,11 @@ lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
/* get the IP address and port */
/* @todo: this does not work for IPv6, yet */
netconn_getaddr(sock->conn, ipX_2_ip(&naddr), &port, local);
err = netconn_getaddr(sock->conn, ipX_2_ip(&naddr), &port, local);
if (err != ERR_OK) {
sock_set_errno(sock, err_to_errno(err));
return -1;
}
IPXADDR_PORT_TO_SOCKADDR(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)),
&saddr, &naddr, port);