- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- perror("socket");
- break;
- }
-#ifdef HAVE_GETHOSTBYNAME_R
- if (gethostbyname_r(info.apcupsd.host, &he_mem, hostbuff, sizeof(hostbuff), &he, &he_errno)) {
- NORM_ERR("APCUPSD gethostbyname_r: %s", hstrerror(h_errno));
+ memset(&hints, 0, sizeof(struct addrinfo));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = 0;
+ hints.ai_protocol = 0;
+ snprintf(portbuf, 8, "%d", info.apcupsd.port);
+ res = getaddrinfo(info.apcupsd.host, portbuf, &hints, &ai);
+ if (res != 0) {
+ NORM_ERR("APCUPSD getaddrinfo: %s", gai_strerror(res));