- if (str) {
- struct sockaddr_in *sin;
- unsigned long addr;
-
- sockcheck_conf.local_addr_len = sizeof(*sin);
- if (getipbyname(str, &addr)) {
- sin = malloc(sockcheck_conf.local_addr_len);
- sin->sin_family = AF_INET;
- sin->sin_port = 0;
- sin->sin_addr.s_addr = addr;
-#ifdef HAVE_SIN_LEN
- sin->sin_len = 0;
-#endif
- memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
- sockcheck_conf.local_addr = sin;
- } else {
- log_module(PC_LOG, LOG_ERROR, "Error: Unable to get host named `%s', not checking a specific address.", str);
- sockcheck_conf.local_addr = NULL;
- }
+ str = database_get_data(my_node, "bind_address", RECDB_QSTRING);
+ if (!str) str = database_get_data(my_node, "address", RECDB_QSTRING);
+ if (!getaddrinfo(str, NULL, NULL, &ai)) {
+ sockcheck_conf.local_addr_len = ai->ai_addrlen;
+ sockcheck_conf.local_addr = calloc(1, ai->ai_addrlen);
+ memcpy(sockcheck_conf.local_addr, ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
+ } else {
+ sockcheck_conf.local_addr_len = 0;
+ sockcheck_conf.local_addr = NULL;
+ if (str)
+ log_module(PC_LOG, LOG_ERROR, "Error: Unable to get host named `%s', not checking from a specific address.", str);