aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cf.c60
1 files changed, 16 insertions, 44 deletions
diff --git a/src/cf.c b/src/cf.c
index d57e132..e923d82 100644
--- a/src/cf.c
+++ b/src/cf.c
@@ -545,9 +545,6 @@ make_socket(struct cfloc const *loc, int family,
struct sockaddr_in s_in;
} addr;
socklen_t socklen;
- short pnum;
- long num;
- char *p;
switch (family) {
case AF_UNIX:
@@ -567,48 +564,23 @@ make_socket(struct cfloc const *loc, int family,
strcpy(addr.s_un.sun_path, path);
break;
- case AF_INET:
- addr.sa.sa_family = PF_INET;
- socklen = sizeof(addr.s_in);
-
- num = pnum = strtol(port, &p, 0);
- if (*p == 0) {
- if (num != pnum) {
- cferror(loc, "%s", _("bad port number"));
- return -1;
- }
- pnum = htons(pnum);
- } else {
- struct servent *sp = getservbyname(port, "tcp");
- if (!sp) {
- cferror(loc, "%s", _("unknown service name"));
- return -1;
- }
- pnum = sp->s_port;
- }
-
- if (!path)
- addr.s_in.sin_addr.s_addr = INADDR_ANY;
- else {
- struct hostent *hp = gethostbyname(path);
- if (!hp) {
- cferror(loc, "%s", _("unknown host name %s"),
- path);
- return 1;
- }
- addr.sa.sa_family = hp->h_addrtype;
- switch (hp->h_addrtype) {
- case AF_INET:
- memmove(&addr.s_in.sin_addr, hp->h_addr, 4);
- addr.s_in.sin_port = pnum;
- break;
-
- default:
- cferror(loc, "%s",
- _("unsupported address family"));
- return 1;
- }
+ case AF_INET: {
+ struct addrinfo hints, *res;
+ int rc;
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_INET;
+ hints.ai_socktype = SOCK_STREAM;
+ rc = getaddrinfo(path, port ? port : "tcpmux", &hints, &res);
+ if (rc) {
+ cferror(loc, "%s", _("gettaddrinfo: %s"),
+ gai_strerror(rc));
+ return 1;
}
+ socklen = sizeof(addr.s_in);
+ memmove(&addr.s_in, res->ai_addr, socklen);
+ freeaddrinfo(res);
+ }
break;
default:

Return to:

Send suggestions and report system problems to the System administrator.