Index: client/clinet.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/clinet.c,v retrieving revision 1.31 diff -u -r1.31 clinet.c --- clinet.c 2000/08/14 12:42:00 1.31 +++ clinet.c 2000/09/03 00:40:41 @@ -120,33 +120,27 @@ int connect_to_server(char *name, char *hostname, int port, char *errbuf, int n_errbuf) { - /* use name to find TCPIP address of server */ + /* use name to find TCP/IP address of server */ struct sockaddr_in src; struct hostent *ph; - long address; struct packet_req_join_game req; - if(port==0) - port=DEFAULT_SOCK_PORT; - - if(!hostname) + if (port == 0) { + port = DEFAULT_SOCK_PORT; + } + + if (!hostname) { hostname="localhost"; - - if(isdigit((size_t)*hostname)) { - if((address = inet_addr(hostname)) == INADDR_NONE) { - mystrlcpy(errbuf, _("Invalid hostname"), n_errbuf); - return -1; - } - src.sin_addr.s_addr = address; - src.sin_family = AF_INET; } - else if ((ph = gethostbyname(hostname)) == NULL) { - mystrlcpy(errbuf, _("Failed looking up host"), n_errbuf); + + ph = gethostbyname(hostname); + if (ph == NULL || ph->h_addrtype != AF_INET + || ph->h_length != sizeof(struct in_addr)) { + my_snprintf(errbuf, n_errbuf, _("Failed to look up host '%s'"), hostname); return -1; - } - else { - src.sin_family = ph->h_addrtype; - memcpy((char *) &src.sin_addr, ph->h_addr, ph->h_length); + } else { + src.sin_family = AF_INET; + src.sin_addr = *(struct in_addr *)(ph->h_addr); } src.sin_port = htons(port); @@ -156,12 +150,12 @@ signal (SIGPIPE, SIG_IGN); #endif - if((aconnection.sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) { + if ((aconnection.sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) { mystrlcpy(errbuf, mystrerror(errno), n_errbuf); return -1; } - if(connect(aconnection.sock, (struct sockaddr *) &src, sizeof (src)) < 0) { + if (connect(aconnection.sock, (struct sockaddr *) &src, sizeof (src)) < 0) { mystrlcpy(errbuf, mystrerror(errno), n_errbuf); close(aconnection.sock); return -1; @@ -299,22 +293,24 @@ urlpath = s; } - if ((ph = gethostbyname(server)) == NULL) { - mystrlcpy(errbuf, _("Failed looking up host"), n_errbuf); + ph = gethostbyname(server); + if (ph == NULL || ph->h_addrtype != AF_INET + || ph->h_length != sizeof (struct in_addr)) { + my_snprintf(errbuf, n_errbuf, _("Failed to look up host '%s'."), server); return NULL; } else { - addr.sin_family = ph->h_addrtype; - memcpy((char *) &addr.sin_addr, ph->h_addr, ph->h_length); + addr.sin_family = AF_INET; + addr.sin_addr = *(struct in_addr *)(ph->h_addr); } addr.sin_port = htons(port); - if((s = socket (AF_INET, SOCK_STREAM, 0)) < 0) { + if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { mystrlcpy(errbuf, mystrerror(errno), n_errbuf); return NULL; } - if(connect(s, (struct sockaddr *) &addr, sizeof (addr)) < 0) { + if (connect(s, (struct sockaddr *) &addr, sizeof (addr)) < 0) { mystrlcpy(errbuf, mystrerror(errno), n_errbuf); close(s); return NULL; Index: server/meta.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/server/meta.c,v retrieving revision 1.36 diff -u -r1.36 meta.c --- meta.c 2000/08/22 08:55:02 1.36 +++ meta.c 2000/09/03 00:40:51 @@ -74,10 +74,6 @@ #include "meta.h" -#ifndef INADDR_NONE -#define INADDR_NONE 0xffffffff -#endif - int server_is_open=0; #ifdef GENERATING_MAC /* mac network globals */ @@ -229,15 +225,34 @@ } #else memset(&serv_addr, 0, sizeof(serv_addr)); + + bad = 0; + hp = gethostbyname(servername); + if (hp == NULL || hp->h_addrtype != AF_INET + || hp->h_length != sizeof (struct in_addr)) { + bad = 1; + } else { + serv_addr.sin_addr = *(struct in_addr *)(hp->h_addr); + } + +#if 0 /* Old way to get the server's address. */ + +#ifndef INADDR_NONE +#define INADDR_NONE 0xffffffff +#endif + serv_addr.sin_addr.s_addr = inet_addr(servername); if ((bad = (serv_addr.sin_addr.s_addr == INADDR_NONE))) { if (!(bad = ((hp = gethostbyname(servername)) == NULL))) { memcpy(&serv_addr.sin_addr.s_addr, hp->h_addr, hp->h_length); } } +#endif + serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(srvarg.metaserver_port); #endif + if (bad) { freelog(LOG_ERROR, _("Metaserver: bad address: [%s]."), servername); metaserver_failed();