Convert a netbuf's address data to struct sockaddr */
| 1042 | |
| 1043 | /* Convert a netbuf's address data to struct sockaddr */ |
| 1044 | static int |
| 1045 | lwip_sock_make_addr(struct netconn *conn, ip_addr_t *fromaddr, u16_t port, |
| 1046 | struct sockaddr *from, socklen_t *fromlen) |
| 1047 | { |
| 1048 | int truncated = 0; |
| 1049 | union sockaddr_aligned saddr; |
| 1050 | |
| 1051 | LWIP_UNUSED_ARG(conn); |
| 1052 | |
| 1053 | LWIP_ASSERT("fromaddr != NULL", fromaddr != NULL); |
| 1054 | LWIP_ASSERT("from != NULL", from != NULL); |
| 1055 | LWIP_ASSERT("fromlen != NULL", fromlen != NULL); |
| 1056 | |
| 1057 | #if LWIP_IPV4 && LWIP_IPV6 |
| 1058 | /* Dual-stack: Map IPv4 addresses to IPv4 mapped IPv6 */ |
| 1059 | if (NETCONNTYPE_ISIPV6(netconn_type(conn)) && IP_IS_V4(fromaddr)) { |
| 1060 | ip4_2_ipv4_mapped_ipv6(ip_2_ip6(fromaddr), ip_2_ip4(fromaddr)); |
| 1061 | IP_SET_TYPE(fromaddr, IPADDR_TYPE_V6); |
| 1062 | } |
| 1063 | #endif /* LWIP_IPV4 && LWIP_IPV6 */ |
| 1064 | |
| 1065 | IPADDR_PORT_TO_SOCKADDR(&saddr, fromaddr, port); |
| 1066 | if (*fromlen < saddr.sa.sa_len) { |
| 1067 | truncated = 1; |
| 1068 | } else if (*fromlen > saddr.sa.sa_len) { |
| 1069 | *fromlen = saddr.sa.sa_len; |
| 1070 | } |
| 1071 | MEMCPY(from, &saddr, *fromlen); |
| 1072 | return truncated; |
| 1073 | } |
| 1074 | |
| 1075 | #if LWIP_TCP |
| 1076 | /* Helper function to get a tcp socket's remote address info */ |
no test coverage detected