+static int
+network_config_set_bind_address(const oconfig_item_t *ci,
+ struct sockaddr_storage **bind_address) {
+ char addr_text[256];
+
+ if (cf_util_get_string_buffer(ci, addr_text, sizeof(addr_text)) != 0)
+ return -1;
+
+ int ret;
+ struct addrinfo hint, *res = NULL;
+
+ memset(&hint, '\0', sizeof hint);
+ hint.ai_family = PF_UNSPEC;
+ hint.ai_flags = AI_NUMERICHOST;
+
+ ret = getaddrinfo(addr_text, NULL, &hint, &res);
+ if (ret) {
+ ERROR("Invalid address");
+ return 1;
+ }
+
+ *bind_address = malloc(sizeof(**bind_address));
+ (*bind_address)->ss_family = res->ai_family;
+ if (res->ai_family == AF_INET) {
+ struct sockaddr_in *addr = (struct sockaddr_in *)(*bind_address);
+ inet_pton(AF_INET, addr_text, &(addr->sin_addr));
+ } else if (res->ai_family == AF_INET6) {
+ struct sockaddr_in6 *addr = (struct sockaddr_in6 *)(*bind_address);
+ inet_pton(AF_INET6, addr_text, &(addr->sin6_addr));
+ } else {
+ ERROR("%s is an unknown address format %d\n", addr_text, res->ai_family);
+ }
+
+ return 0;
+} /* int network_config_set_bind_address */
+