X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=uip%2Fmhlsbr.c;h=9f1ebddeb763e0b5df04d991d533d7bc8a1945ff;hb=cd665517f488ca62e71b7fd1db6df0813dee052a;hp=acf21de9ee7d40aefe60c5d11746832c4ce71b0a;hpb=13f84dd50ca5754391dbd3296a5c7425f9363600;p=mmh diff --git a/uip/mhlsbr.c b/uip/mhlsbr.c index acf21de..9f1ebdd 100644 --- a/uip/mhlsbr.c +++ b/uip/mhlsbr.c @@ -291,7 +291,6 @@ int SOprintf (char *, ...); /* from termsbr.c */ int sc_width (void); /* from termsbr.c */ int sc_length (void); /* from termsbr.c */ int sc_hardcopy (void); /* from termsbr.c */ -struct hostent *gethostbystring (); int @@ -1526,17 +1525,16 @@ static int doface (struct mcomp *c1) { int result, sd; - struct sockaddr_in in_socket; - struct sockaddr_in *isock = &in_socket; static int inited = OK; - static int addrlen; - static struct in_addr addr; - static unsigned short portno; + static struct sockaddr_storage ss; + static socklen_t socklen; + static int socktype; + static int protocol; if (inited == OK) { char *cp; char **ap = brkstring (cp = getcpy (faceproc), " ", "\n"); - struct hostent *hp; + struct addrinfo hints, *res; if (ap[0] == NULL || ap[1] == NULL) { bad_faceproc: ; @@ -1544,27 +1542,30 @@ bad_faceproc: ; return (inited = NOTOK); } - if (!(hp = gethostbystring (ap[0]))) + memset(&hints, 0, sizeof(hints)); + hints.ai_flags = AI_ADDRCONFIG; + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + + if (getaddrinfo(ap[0], ap[1], &hints, &res) != 0) goto bad_faceproc; - memcpy((char *) &addr, hp->h_addr, addrlen = hp->h_length); - portno = htons ((unsigned short) atoi (ap[1])); - free (cp); + memcpy(&ss, res->ai_addr, res->ai_addrlen); + socklen = res->ai_addrlen; + socktype = res->ai_socktype; + protocol = res->ai_protocol; + freeaddrinfo(res); inited = DONE; } if (inited == NOTOK) return NOTOK; - isock->sin_family = AF_INET; - isock->sin_port = portno; - memcpy((char *) &isock->sin_addr, (char *) &addr, addrlen); - - if ((sd = socket (AF_INET, SOCK_DGRAM, 0)) == NOTOK) + if ((sd = socket (ss.ss_family, socktype, protocol)) == NOTOK) return NOTOK; result = sendto (sd, c1->c_text, strlen (c1->c_text), 0, - (struct sockaddr *) isock, sizeof(*isock)); + (struct sockaddr *) &ss, socklen); close (sd);