Skip to content

Commit 8eb802a

Browse files
committed
unix: socket.getaddrinfo: Accept family & socktype arguments.
This usually allows to get just a single address entry.
1 parent af33ebb commit 8eb802a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

unix/modsocket.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_socket_gethostbyname_obj, mod_socket_gethos
357357

358358
STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
359359
// TODO: Implement all args
360-
assert(n_args == 2);
360+
assert(n_args >= 2 && n_args <= 4);
361361
assert(MP_OBJ_IS_STR(args[0]));
362362

363363
const char *host = mp_obj_str_get_str(args[0]);
@@ -390,6 +390,13 @@ STATIC mp_obj_t mod_socket_getaddrinfo(mp_uint_t n_args, const mp_obj_t *args) {
390390
serv = mp_obj_str_get_str(args[1]);
391391
}
392392

393+
if (n_args > 2) {
394+
hints.ai_family = MP_OBJ_SMALL_INT_VALUE(args[2]);
395+
if (n_args > 3) {
396+
hints.ai_socktype = MP_OBJ_SMALL_INT_VALUE(args[3]);
397+
}
398+
}
399+
393400
struct addrinfo *addr_list;
394401
int res = getaddrinfo(host, serv, &hints, &addr_list);
395402

0 commit comments

Comments
 (0)