api_msg.h <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /* IP addresses and port numbers are expected to be in * the same byte order as in the corresponding pcb. */ struct api_msg_msg { struct netconn *conn; union { struct netbuf *b; /* do_send */ struct { u8_t proto; } n; /* do_newconn */ struct { struct ip_addr *ipaddr; u16_t port; } bc; /* do_bind, do_connect */ struct { struct ip_addr *ipaddr; u16_t* port; u8_t local; } ad; /* do_getaddr */ struct { const void *dataptr; int len; u8_t apiflags; } w; /* do_write */ struct { u16_t len; } r; /* do_recv */ #if LWIP_IGMP struct { struct ip_addr *multiaddr; struct ip_addr *interface; enum netconn_igmp join_or_leave; } jl; /* do_join_leave_group */ #endif /* LWIP_IGMP */ } msg; }; ... void do_getaddr ( struct api_msg_msg *msg); ... api.h <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< err_t netconn_getaddr(struct netconn *conn, struct ip_addr *addr, u16_t *port, u8_t local); #define netconn_peer(c,i,p,l) netconn_getaddr(c,i,p,0) #define netconn_addr(c,i,p,l) netconn_getaddr(c,i,p,1) api_lib.c <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< /** * @todo comment */ err_t netconn_getaddr(struct netconn *conn, struct ip_addr *addr, u16_t *port, u8_t local) { struct api_msg msg; LWIP_ERROR("netconn_getaddr: invalid conn", (conn != NULL), return ERR_ARG;); LWIP_ERROR("netconn_getaddr: invalid addr", (addr != NULL), return ERR_ARG;); LWIP_ERROR("netconn_getaddr: invalid port", (port != NULL), return ERR_ARG;); msg.function = do_getaddr; msg.msg.conn = conn; msg.msg.msg.ad.ipaddr = addr; msg.msg.msg.ad.port = port; msg.msg.msg.ad.local = local; TCPIP_APIMSG(&msg); return conn->err; } api_msg.c <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< void do_getaddr(struct api_msg_msg *msg) { if (msg->conn->pcb.ip != NULL) { *(msg->msg.ad.ipaddr) = (msg->msg.ad.local?msg->conn->pcb.ip->local_ip:msg->conn->pcb.ip->remote_ip); switch (NETCONNTYPE_GROUP(msg->conn->type)) { #if LWIP_RAW case NETCONN_RAW: if (msg->msg.ad.local) { *(msg->msg.ad.port) = msg->conn->pcb.raw->protocol; } else { /* return an error as connecting is only a helper for upper layers */ msg->conn->err = ERR_CONN; } break; #endif /* LWIP_RAW */ #if LWIP_UDP case NETCONN_UDP: if (msg->msg.ad.local) { *(msg->msg.ad.port) = msg->conn->pcb.udp->local_port; } else { if ((msg->conn->pcb.udp->flags & UDP_FLAGS_CONNECTED) == 0) { msg->conn->err = ERR_CONN; } else { *(msg->msg.ad.port) = msg->conn->pcb.udp->remote_port; } } break; #endif /* LWIP_UDP */ #if LWIP_TCP case NETCONN_TCP: *(msg->msg.ad.port) = (msg->msg.ad.local?msg->conn->pcb.tcp->local_port:msg->conn->pcb.tcp->remote_port); break; #endif /* LWIP_TCP */ } } else { msg->conn->err =ERR_CONN; } TCPIP_APIMSG_ACK(msg); } + little changes in sockets.c