diff --git a/src/client/host.c b/src/client/host.c index a818a1b7..2efb2ea0 100644 --- a/src/client/host.c +++ b/src/client/host.c @@ -32,7 +32,7 @@ * Steve McClure, 1998 */ -#include +#include #include #include #include @@ -46,7 +46,6 @@ #include #include #endif -#include #include "misc.h" int @@ -60,15 +59,9 @@ hostaddr(char *name, struct sockaddr_in *addr) addr->sin_addr.s_addr = inet_addr(name); } else { hp = gethostbyname(name); - if (hp == NULL) { - fprintf(stderr, "%s: No such host\n", name); + if (hp == NULL) return 0; - } memcpy(&addr->sin_addr, hp->h_addr, sizeof(addr->sin_addr)); -#ifdef _WIN32 - printf("Trying to connect to '%s'\n", inet_ntoa(addr->sin_addr)); - fflush(stdout); -#endif } return 1; } @@ -81,12 +74,7 @@ hostport(char *name, struct sockaddr_in *addr) if (name == NULL || *name == 0) return 0; if (isdigit(*name)) { -#ifndef _WIN32 addr->sin_port = htons(atoi(name)); -#else - addr->sin_port = atoi(name); - addr->sin_port = htons(addr->sin_port); -#endif } else { sp = getservbyname(name, "tcp"); if (sp == NULL) @@ -106,17 +94,12 @@ hostconnect(struct sockaddr_in *addr) #ifdef _WIN32 errno = WSAGetLastError(); #endif - perror("socket"); return -1; } addr->sin_family = AF_INET; if (connect(s, (struct sockaddr *)addr, sizeof(*addr)) < 0) { #ifdef _WIN32 errno = WSAGetLastError(); -#endif - perror("connect"); -#ifdef _WIN32 - printf("Check that your EMPIREHOST and EMPIREPORT are correct.\n"); #endif (void)close(s); return -1; diff --git a/src/client/main.c b/src/client/main.c index a59f286b..a2da8b3c 100644 --- a/src/client/main.c +++ b/src/client/main.c @@ -105,6 +105,8 @@ main(int ac, char **av) char *cname; char *pname; char *uname; + char *host; + char *port; int send_kill = 0; int utf8 = 0; @@ -157,18 +159,24 @@ main(int ac, char **av) exit(1); } getsose(); - if (!hostport(getenv("EMPIREPORT"), &sin) && - !hostport("empire", &sin) && !hostport(empireport, &sin)) { - fprintf(stderr, "No empire port\n"); + port = getenv("EMPIREPORT"); + if (!port) + port = empireport; + if (!hostport(port, &sin)) { + fprintf(stderr, "Can't resolve Empire port %s\n", port); exit(1); } - if (!hostaddr(getenv("EMPIREHOST"), &sin) && - !hostaddr(empirehost, &sin)) { - fprintf(stderr, "No empire host\n"); + host = getenv("EMPIREHOST"); + if (!host) + host = empirehost; + if (!hostaddr(host, &sin)) { + fprintf(stderr, "Can't resolve Empire host %s\n", host); exit(1); } - if ((sock = hostconnect(&sin)) < 0) + if ((sock = hostconnect(&sin)) < 0) { + perror("Can't connect to Empire server"); exit(1); + } cname = getenv("COUNTRY"); if (ac > 1) cname = argv[1];