@@ -60,48 +60,30 @@ static mp_obj_t format_address(const struct sockaddr *addr, int family) {
6060 return mp_obj_new_str (ip_str , strlen (ip_str ));
6161}
6262
63- mp_obj_t common_hal_socketpool_socketpool_gethostbyname (socketpool_socketpool_obj_t * self ,
64- const char * host ) {
65-
66- const struct addrinfo hints = {
67- .ai_family = AF_INET ,
68- .ai_socktype = SOCK_STREAM ,
69- };
70- struct addrinfo * res = NULL ;
71- int err = socketpool_getaddrinfo_common (host , 0 , & hints , & res );
72- if (err != 0 || res == NULL ) {
73- return mp_const_none ;
74- }
75-
76- nlr_buf_t nlr ;
77- if (nlr_push (& nlr ) == 0 ) {
78- mp_obj_t result = format_address (res -> ai_addr , res -> ai_family );
79- nlr_pop ();
80- lwip_freeaddrinfo (res );
81- return result ;
82- } else {
83- lwip_freeaddrinfo (res );
84- nlr_raise (MP_OBJ_FROM_PTR (nlr .ret_val ));
85- };
86- }
87-
88- #if CIRCUITPY_SOCKETPOOL_IPV6
8963static mp_obj_t convert_sockaddr (const struct addrinfo * ai , int port ) {
64+ #if CIRCUITPY_SOCKETPOOL_IPV6
9065 mp_int_t n_tuple = ai -> ai_family == AF_INET6 ? 4 : 2 ;
66+ #else
67+ mp_int_t n_tuple = 2 ;
68+ #endif
9169 mp_obj_tuple_t * result = MP_OBJ_TO_PTR (mp_obj_new_tuple (n_tuple , NULL ));
9270 result -> items [0 ] = format_address (ai -> ai_addr , ai -> ai_family );
9371 result -> items [1 ] = MP_OBJ_NEW_SMALL_INT (port );
72+ #if CIRCUITPY_SOCKETPOOL_IPV6
9473 if (ai -> ai_family == AF_INET6 ) {
9574 const struct sockaddr_in6 * ai6 = (void * )ai -> ai_addr ;
9675 result -> items [2 ] = MP_OBJ_NEW_SMALL_INT (ai6 -> sin6_flowinfo );
9776 result -> items [3 ] = MP_OBJ_NEW_SMALL_INT (ai6 -> sin6_scope_id );
9877 }
78+ #endif
9979 return result ;
10080}
10181
10282static mp_obj_t convert_addrinfo (const struct addrinfo * ai , int port ) {
10383 MP_STATIC_ASSERT (AF_INET == SOCKETPOOL_AF_INET );
84+ #if CIRCUITPY_SOCKETPOOL_IPV6
10485 MP_STATIC_ASSERT (AF_INET6 == SOCKETPOOL_AF_INET6 );
86+ #endif
10587 // MP_STATIC_ASSERT(AF_UNSPEC == SOCKETPOOL_AF_UNSPEC);
10688 mp_obj_tuple_t * result = MP_OBJ_TO_PTR (mp_obj_new_tuple (5 , NULL ));
10789 result -> items [0 ] = MP_OBJ_NEW_SMALL_INT (ai -> ai_family );
@@ -113,7 +95,6 @@ static mp_obj_t convert_addrinfo(const struct addrinfo *ai, int port) {
11395}
11496
11597mp_obj_t common_hal_socketpool_getaddrinfo_raise (socketpool_socketpool_obj_t * self , const char * host , int port , int family , int type , int proto , int flags ) {
116- MP_STATIC_ASSERT (LWIP_IPV6 );
11798 const struct addrinfo hints = {
11899 .ai_flags = flags ,
119100 .ai_family = family ,
@@ -141,4 +122,3 @@ mp_obj_t common_hal_socketpool_getaddrinfo_raise(socketpool_socketpool_obj_t *se
141122 nlr_raise (MP_OBJ_FROM_PTR (nlr .ret_val ));
142123 }
143124}
144- #endif
0 commit comments