@@ -37,6 +37,7 @@ int socketpool_getaddrinfo_common(const char *host, int service, const struct zs
3737
3838 char service_buf [6 ];
3939 snprintf (service_buf , sizeof (service_buf ), "%d" , service );
40+ printk ("socketpool_getaddrinfo_common host %s service %s\n" , host , service_buf );
4041
4142 return zsock_getaddrinfo (host , service_buf , hints , res );
4243}
@@ -85,13 +86,14 @@ static mp_obj_t convert_sockaddr(const struct zsock_addrinfo *ai, int port) {
8586}
8687
8788static mp_obj_t convert_addrinfo (const struct addrinfo * ai , int port ) {
88- MP_STATIC_ASSERT (AF_INET == SOCKETPOOL_AF_INET );
89- #if CIRCUITPY_SOCKETPOOL_IPV6
90- MP_STATIC_ASSERT (AF_INET6 == SOCKETPOOL_AF_INET6 );
91- #endif
92- // MP_STATIC_ASSERT(AF_UNSPEC == SOCKETPOOL_AF_UNSPEC);
9389 mp_obj_tuple_t * result = MP_OBJ_TO_PTR (mp_obj_new_tuple (5 , NULL ));
94- result -> items [0 ] = MP_OBJ_NEW_SMALL_INT (ai -> ai_family );
90+ int family = ai -> ai_family ;
91+ if (ai -> ai_family == AF_INET ) {
92+ family = SOCKETPOOL_AF_INET ;
93+ } else if (ai -> ai_family == AF_INET6 ) {
94+ family = SOCKETPOOL_AF_INET6 ;
95+ }
96+ result -> items [0 ] = MP_OBJ_NEW_SMALL_INT (family );
9597 result -> items [1 ] = MP_OBJ_NEW_SMALL_INT (ai -> ai_socktype );
9698 result -> items [2 ] = MP_OBJ_NEW_SMALL_INT (ai -> ai_protocol );
9799 result -> items [3 ] = ai -> ai_canonname ? mp_obj_new_str (ai -> ai_canonname , strlen (ai -> ai_canonname )) : MP_OBJ_NEW_QSTR (MP_QSTR_ );
@@ -100,6 +102,12 @@ static mp_obj_t convert_addrinfo(const struct addrinfo *ai, int port) {
100102}
101103
102104mp_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 ) {
105+ if (family == SOCKETPOOL_AF_INET ) {
106+ family = AF_INET ;
107+ } else if (family == SOCKETPOOL_AF_INET6 ) {
108+ family = AF_INET6 ;
109+ }
110+ // Proto and type values match BSD.
103111 const struct zsock_addrinfo hints = {
104112 .ai_flags = flags ,
105113 .ai_family = family ,
@@ -110,7 +118,7 @@ mp_obj_t common_hal_socketpool_getaddrinfo_raise(socketpool_socketpool_obj_t *se
110118 struct addrinfo * res = NULL ;
111119 int err = socketpool_getaddrinfo_common (host , port , & hints , & res );
112120 if (err != 0 || res == NULL ) {
113- printk ("common_hal_socketpool_getaddrinfo_raise\n" );
121+ printk ("common_hal_socketpool_getaddrinfo_raise err %d res %p \n" , err , res );
114122 common_hal_socketpool_socketpool_raise_gaierror_noname ();
115123 }
116124
0 commit comments