static PyObject * Channel_func_set_local_ip(Channel *self, PyObject *args) { char *ip; struct in_addr addr4; struct in6_addr addr6; CHECK_CHANNEL(self); if (!PyArg_ParseTuple(args, "s:set_local_ip", &ip)) { return NULL; } if (ares_inet_pton(AF_INET, ip, &addr4) == 1) { ares_set_local_ip4(self->channel, ntohl(addr4.s_addr)); } else if (ares_inet_pton(AF_INET6, ip, &addr6) == 1) { ares_set_local_ip6(self->channel, addr6.s6_addr); } else { PyErr_SetString(PyExc_ValueError, "invalid IP address"); return NULL; } Py_RETURN_NONE; }
CURLcode Curl_set_dns_local_ip4(struct Curl_easy *data, const char *local_ip4) { #if (ARES_VERSION >= 0x010704) struct in_addr a4; if((!local_ip4) || (local_ip4[0] == 0)) { a4.s_addr = 0; /* disabled: do not bind to a specific address */ } else { if(Curl_inet_pton(AF_INET, local_ip4, &a4) != 1) { return CURLE_BAD_FUNCTION_ARGUMENT; } } ares_set_local_ip4((ares_channel)data->state.resolver, ntohl(a4.s_addr)); return CURLE_OK; #else /* c-ares version too old! */ (void)data; (void)local_ip4; return CURLE_NOT_BUILT_IN; #endif }