static void test_is_address_ipv4(void) { int ret = 0; diag("Utils IPv4 test"); ret = utils_is_address_ipv4("127.0.0.1"); ok(ret == 1, "Valid IPv4 address"); ret = utils_is_address_ipv4("127.0.0.256"); ok(ret == -1, "Invalid IPv4 address"); ret = utils_is_address_ipv4("::1"); ok(ret == -1, "Invalid IPv4 address when IPv6"); }
/* * Set the given string address in a configuration object. * * Return 0 on success or else a negative value. On error, the address was not * recognized. */ static int set_tor_address(const char *addr, struct configuration *config) { int ret; assert(addr); assert(config); ret = utils_is_address_ipv4(addr); if (ret == 1 ) { config->conf_file.tor_domain = CONNECTION_DOMAIN_INET; } else { ret = utils_is_address_ipv6(addr); if (ret != 1) { /* At this point, the addr is either v4 nor v6 so error. */ ERR("Config file unknown tor address: %s", addr); goto error; } config->conf_file.tor_domain = CONNECTION_DOMAIN_INET6; } config->conf_file.tor_address = strdup(addr); if (!config->conf_file.tor_address) { ret = -ENOMEM; goto error; } DBG("Config file setting tor address to %s", addr); ret = 0; error: return ret; }