From 66d1f52f7016d0677d6070f9c9b5dc59c0ce2061 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 23 Nov 2023 18:20:20 -0500 Subject: [PATCH] opsfclient: Convert to use getaddrinfo gethostbyname, rumor has it, is obsolete and should be removed. Let's convert over to the successor. Signed-off-by: Donald Sharp --- ospfclient/ospf_apiclient.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ospfclient/ospf_apiclient.c b/ospfclient/ospf_apiclient.c index a1193001faea..abcdf591e5c3 100644 --- a/ospfclient/ospf_apiclient.c +++ b/ospfclient/ospf_apiclient.c @@ -81,7 +81,7 @@ struct ospf_apiclient *ospf_apiclient_connect(char *host, int syncport) struct sockaddr_in myaddr_sync; struct sockaddr_in myaddr_async; struct sockaddr_in peeraddr; - struct hostent *hp; + struct addrinfo hints, *res; struct ospf_apiclient *new; int size = 0; unsigned int peeraddrlen; @@ -155,8 +155,10 @@ struct ospf_apiclient *ospf_apiclient_connect(char *host, int syncport) /* Make connection for synchronous requests and connect to server */ /* Resolve address of server */ - hp = gethostbyname(host); - if (!hp) { + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + if (getaddrinfo(host, NULL, &hints, &res) != 0) { fprintf(stderr, "ospf_apiclient_connect: no such host %s\n", host); close(async_server_sock); @@ -217,7 +219,7 @@ struct ospf_apiclient *ospf_apiclient_connect(char *host, int syncport) } /* Prepare address structure for connect */ - memcpy(&myaddr_sync.sin_addr, hp->h_addr, hp->h_length); + myaddr_sync = *(struct sockaddr_in *)res->ai_addr; myaddr_sync.sin_family = AF_INET; myaddr_sync.sin_port = htons(ospf_apiclient_getport()); #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN