MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / lwip_getaddrname

Function lwip_getaddrname

components/net/lwip/lwip-2.1.2/src/api/sockets.c:2721–2766  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2719}
2720
2721static int
2722lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local)
2723{
2724 struct lwip_sock *sock;
2725 union sockaddr_aligned saddr;
2726 ip_addr_t naddr;
2727 u16_t port;
2728 err_t err;
2729
2730 sock = get_socket(s);
2731 if (!sock) {
2732 return -1;
2733 }
2734
2735 /* get the IP address and port */
2736 err = netconn_getaddr(sock->conn, &naddr, &port, local);
2737 if (err != ERR_OK) {
2738 sock_set_errno(sock, err_to_errno(err));
2739 done_socket(sock);
2740 return -1;
2741 }
2742
2743#if LWIP_IPV4 && LWIP_IPV6
2744 /* Dual-stack: Map IPv4 addresses to IPv4 mapped IPv6 */
2745 if (NETCONNTYPE_ISIPV6(netconn_type(sock->conn)) &&
2746 IP_IS_V4_VAL(naddr)) {
2747 ip4_2_ipv4_mapped_ipv6(ip_2_ip6(&naddr), ip_2_ip4(&naddr));
2748 IP_SET_TYPE_VAL(naddr, IPADDR_TYPE_V6);
2749 }
2750#endif /* LWIP_IPV4 && LWIP_IPV6 */
2751
2752 IPADDR_PORT_TO_SOCKADDR(&saddr, &naddr, port);
2753
2754 LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getaddrname(%d, addr=", s));
2755 ip_addr_debug_print_val(SOCKETS_DEBUG, naddr);
2756 LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", port));
2757
2758 if (*namelen > saddr.sa.sa_len) {
2759 *namelen = saddr.sa.sa_len;
2760 }
2761 MEMCPY(name, &saddr, *namelen);
2762
2763 sock_set_errno(sock, 0);
2764 done_socket(sock);
2765 return 0;
2766}
2767
2768int
2769lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen)

Callers 2

lwip_getpeernameFunction · 0.70
lwip_getsocknameFunction · 0.70

Calls 5

done_socketFunction · 0.85
get_socketFunction · 0.70
netconn_getaddrFunction · 0.70
err_to_errnoFunction · 0.70
netconn_typeEnum · 0.70

Tested by

no test coverage detected