diff -ru -Xdiff_ignore freeciv-1.13.0.orig/client/clinet.c freeciv-1.13.0/client/clinet.c --- freeciv-1.13.0.orig/client/clinet.c Thu Jun 27 15:41:08 2002 +++ freeciv-1.13.0/client/clinet.c Sat Sep 28 23:53:13 2002 @@ -78,7 +78,9 @@ #include "clinet.h" struct connection aconnection; -static struct sockaddr_in server_addr; +/* IPv4 only ... Modified By LucioSlayer : dual-stack compliant + static struct sockaddr_in server_addr; +*/ /************************************************************************** Close socket and cleanup. This one doesn't print a message, so should @@ -118,10 +120,18 @@ /************************************************************************** Connect to a civserver instance -- or at least try to. On success, return 0; on failure, put an error message in ERRBUF and return -1. + Modified By lucioSlayer ... dual-stack compliant ! **************************************************************************/ -int connect_to_server(char *name, char *hostname, int port, +/* + int connect_to_server(char *name, char *hostname, int port, char *errbuf, int errbufsize) +*/ + int connect_to_server(char *user_name, char *hostname, int port, + char *errbuf, int errbufsize) + { +/* IPv4 only */ +/* if (get_server_address(hostname, port, errbuf, errbufsize) != 0) { return -1; } @@ -131,7 +141,7 @@ } return 0; } - +*/ /************************************************************************** Get ready to [try to] connect to a server: - translate HOSTNAME and PORT (with defaults of "localhost" and @@ -140,14 +150,16 @@ - return 0 on success or put an error message in ERRBUF and return -1 on failure **************************************************************************/ +/* Ipv4 only */ +/* int get_server_address(char *hostname, int port, char *errbuf, int errbufsize) { if (port == 0) port = DEFAULT_SOCK_PORT; - - /* use name to find TCP/IP address of server */ - if (!hostname) +*/ +/* use name to find TCP/IP address of server */ +/* if (!hostname) hostname = "localhost"; if (!fc_lookup_host(hostname, &server_addr)) { @@ -158,7 +170,7 @@ server_addr.sin_port = htons(port); return 0; } - +*/ /************************************************************************** Try to connect to a server (get_server_address() must be called first!): - try to create a TCP socket and connect it to `server_addr' @@ -170,6 +182,8 @@ message in ERRBUF and return the Unix error code (ie., errno, which will be non-zero). **************************************************************************/ +/* IPv4 only */ +/* int try_to_connect(char *user_name, char *errbuf, int errbufsize) { struct packet_req_join_game req; @@ -185,8 +199,30 @@ my_closesocket(aconnection.sock); aconnection.sock = -1; return errno; - } + } +*/ +/* Dual-stack Compliant */ + /* use name to find TCP/IP address of server */ + /* temporary supressed + struct addrinfo hints, *src; + int n; + */ + struct packet_req_join_game req; + + if(port==0) + port=DEFAULT_SOCK_PORT; + + if(!hostname) + hostname="localhost"; + /******************** + Lucioslayer: Now fc_look_up_host performs hostname resolution + and also the connect() function + ***********************/ + if((aconnection.sock = fc_lookup_host(hostname, port)) < 0) { + (void) mystrlcpy(errbuf, mystrerror(errno), errbufsize); + fprintf (stderr,"pb lors de l'attribution aconnection.sock\n"); + } if (aconnection.buffer) { /* didn't close cleanly previously? */ freelog(LOG_ERROR, "Unexpected buffers in try_to_connect()"); @@ -455,7 +491,9 @@ struct server_list *create_server_list(char *errbuf, int n_errbuf) { struct server_list *server_list; - struct sockaddr_in addr; +/* IPv4-only suppressed by Lucioslayer + struct sockaddr_in addr; +*/ int s; FILE *f; char *proxy_url; @@ -514,6 +552,8 @@ urlpath = s; } +/* IPv4 only */ +/* if (!fc_lookup_host(server, &addr)) { (void) mystrlcpy(errbuf, _("Failed looking up host"), n_errbuf); return NULL; @@ -528,6 +568,11 @@ if(connect(s, (struct sockaddr *) &addr, sizeof (addr)) == -1) { (void) mystrlcpy(errbuf, mystrerror(errno), n_errbuf); +*/ + /* Lucioslayer: dual-stack compliant */ + if ((s=fc_lookup_host(server, port))< 0) { + mystrlcpy(errbuf, _("Failed looking up host"), n_errbuf); + /* End dual-stack */ my_closesocket(s); return NULL; } diff -ru -Xdiff_ignore freeciv-1.13.0.orig/client/gui-gtk/connectdlg.c freeciv-1.13.0/client/gui-gtk/connectdlg.c --- freeciv-1.13.0.orig/client/gui-gtk/connectdlg.c Mon Jun 24 12:05:06 2002 +++ freeciv-1.13.0/client/gui-gtk/connectdlg.c Sun Sep 29 00:55:50 2002 @@ -300,7 +300,11 @@ Make an attempt to autoconnect to the server. (server_autoconnect() gets GTK to call this function every so often.) **************************************************************************/ -static int try_to_autoconnect(gpointer data) +/* LucioSLayer : modified for dual-stack compliance + static int try_to_autoconnect(gpointer data) +*/ +static int try_to_autoconnect(gpointer data, char *hostname, int port) + { char errbuf[512]; static int count = 0; @@ -316,7 +320,10 @@ exit(EXIT_FAILURE); } - switch (try_to_connect(player_name, errbuf, sizeof(errbuf))) { +/* switch (try_to_connect(player_name, errbuf, sizeof(errbuf))) { +*/ +switch (connect_to_server(player_name, hostname, port, errbuf, sizeof errbuf)) { + case 0: /* Success! */ return FALSE; /* Tells GTK not to call this function again */ @@ -359,14 +366,19 @@ MAX_AUTOCONNECT_ATTEMPTS); append_output_window(buf); +/* IPv4-only suppressed by Lucioslayer if (get_server_address(server_host, server_port, buf, sizeof(buf)) < 0) { freelog(LOG_FATAL, _("Error contacting server \"%s\" at port %d " "as \"%s\":\n %s\n"), server_host, server_port, player_name, buf); gtk_exit(EXIT_FAILURE); - } - if (try_to_autoconnect(NULL)) { + if (try_to_autoconnect(NULL, char *hostname, int port)) { + */ + /* Lucioslayer: modified for Dual-stack compliant mode + */ +if (try_to_autoconnect(NULL, server_host, server_port)) { +/* End dual-stack */ gtk_timeout_add(AUTOCONNECT_INTERVAL, try_to_autoconnect, NULL); } } diff -ru -Xdiff_ignore freeciv-1.13.0.orig/client/gui-gtk-2.0/connectdlg.c freeciv-1.13.0/client/gui-gtk-2.0/connectdlg.c --- freeciv-1.13.0.orig/client/gui-gtk-2.0/connectdlg.c Thu Jun 27 15:41:10 2002 +++ freeciv-1.13.0/client/gui-gtk-2.0/connectdlg.c Sun Sep 29 00:58:03 2002 @@ -319,7 +319,10 @@ Make an attempt to autoconnect to the server. (server_autoconnect() gets GTK to call this function every so often.) **************************************************************************/ -static int try_to_autoconnect(gpointer data) +/* LucioSLayer : modified for dual-stack compliance + static int try_to_autoconnect(gpointer data) +*/ +static int try_to_autoconnect(gpointer data, char *hostname, int port) { char errbuf[512]; static int count = 0; @@ -335,7 +338,9 @@ exit(EXIT_FAILURE); } - switch (try_to_connect(player_name, errbuf, sizeof(errbuf))) { + /* switch (try_to_connect(player_name, errbuf, sizeof(errbuf))) { + */ +switch (connect_to_server(player_name, hostname, port, errbuf, sizeof errbuf)) { case 0: /* Success! */ return FALSE; /* Tells GTK not to call this function again */ @@ -378,14 +383,18 @@ MAX_AUTOCONNECT_ATTEMPTS); append_output_window(buf); +/* IPv4-only suppressed by Lucioslayer if (get_server_address(server_host, server_port, buf, sizeof(buf)) < 0) { freelog(LOG_FATAL, _("Error contacting server \"%s\" at port %d " "as \"%s\":\n %s\n"), server_host, server_port, player_name, buf); gtk_exit(EXIT_FAILURE); - } - if (try_to_autoconnect(NULL)) { + if (try_to_autoconnect(NULL, char *hostname, int port)) { + */ +/* Lucioslayer: modified for Dual-stack compliant mode */ +if (try_to_autoconnect(NULL, server_host, server_port)) { +/* End dual-stack */ gtk_timeout_add(AUTOCONNECT_INTERVAL, try_to_autoconnect, NULL); } } diff -ru -Xdiff_ignore freeciv-1.13.0.orig/common/netintf.c freeciv-1.13.0/common/netintf.c --- freeciv-1.13.0.orig/common/netintf.c Tue Mar 5 16:46:22 2002 +++ freeciv-1.13.0/common/netintf.c Sat Sep 28 20:05:14 2002 @@ -22,6 +22,8 @@ #include #include #include +/* add-on temporary */ +#include #ifdef HAVE_FCNTL_H #include @@ -162,7 +164,9 @@ /*************************************************************************** Look up the given host and fill in *sock. Note that the caller should fill in the port number (sock->sin_port). + Modified By Lucioslayer ... dual-stack compliant ! ***************************************************************************/ +/* IPv4 Only bool fc_lookup_host(const char *hostname, struct sockaddr_in *sock) { struct hostent *hp; @@ -185,4 +189,88 @@ memcpy(&sock->sin_addr, hp->h_addr, hp->h_length); return TRUE; + } +*/ +/* Dual-stack compliant */ +bool fc_lookup_host(const char *hostname, int port) +{ + int sockfd, n; + struct addrinfo hints, *res, *ressave; + char serv[30]; + + snprintf(serv,sizeof(serv)-1,"%d",(unsigned int) port ); + serv[sizeof(serv)-1]=0; + + bzero(&hints, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if ((n = getaddrinfo(hostname,serv,&hints,&res)) != 0) { + fprintf(stderr,"fc_lookup_host error for %s, %s: %s\n", hostname, serv, gai_strerror(n)); + return -1; + } + + ressave = res; + + do { + sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if( sockfd < 0) + continue; + if (connect(sockfd,res->ai_addr,res->ai_addrlen) == 0) + break; + close(sockfd); + + } while( (res = res->ai_next)!=NULL); + + if (res == NULL) { /* errno set from final connect() */ + fprintf(stderr,"fc_lookup_host: no suitable address found.\n"); + freeaddrinfo(ressave); + return -1; + } + + freeaddrinfo(ressave); + + return(sockfd); +} + +int net_connect_udp(const char *hostname, int port) +{ + int sockfd, n; + struct addrinfo hints, *res, *ressave; + char serv[30]; + + snprintf(serv,sizeof(serv)-1,"%d",(unsigned int) port ); + serv[sizeof(serv)-1]=0; + + bzero(&hints, sizeof(struct addrinfo)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_DGRAM; + + if ((n = getaddrinfo(hostname,serv,&hints,&res)) != 0) { + fprintf(stderr,"net_connect_udp error for %s, %s: %s\n", hostname, serv, gai_strerror(n)); + return -1; + } + + ressave = res; + + do { + sockfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if( sockfd < 0) + continue; + if (connect(sockfd,res->ai_addr,res->ai_addrlen) == 0) + break; + close(sockfd); + + } while( (res = res->ai_next)!=NULL); + + if (res == NULL) { /* errno set from final connect() */ + fprintf(stderr,"net_connect_udp: no suitable address found.\n"); + freeaddrinfo(ressave); + return -1; + } + + freeaddrinfo(ressave); + + return(sockfd); } +/* End dual-stack */ diff -ru -Xdiff_ignore freeciv-1.13.0.orig/common/netintf.h freeciv-1.13.0/common/netintf.h --- freeciv-1.13.0.orig/common/netintf.h Thu Feb 14 16:17:16 2002 +++ freeciv-1.13.0/common/netintf.h Sat Sep 28 18:13:48 2002 @@ -53,6 +53,11 @@ void my_shutdown_network(void); void my_nonblock(int sockfd); +/*IPv4 only bool fc_lookup_host(const char *hostname, struct sockaddr_in *sock); +*/ +/* Modified by Lucioslayer ... Dual-Stack compliant */ +bool fc_lookup_host(const char *hostname, int port); +/* End dual-stack*/ #endif /* FC__NETINTF_H */ diff -ru -Xdiff_ignore freeciv-1.13.0.orig/server/meta.c freeciv-1.13.0/server/meta.c --- freeciv-1.13.0.orig/server/meta.c Fri May 17 16:07:58 2002 +++ freeciv-1.13.0/server/meta.c Sat Sep 28 18:35:20 2002 @@ -189,13 +189,16 @@ { char *servername=srvarg.metaserver_addr; bool bad; + #ifdef GENERATING_MAC /* mac networking */ OSStatus err1; OSErr err2; InetSvcRef ref=OTOpenInternetServices(kDefaultInternetServicesPath, 0, &err1); InetHostInfo hinfo; #else - struct sockaddr_in serv_addr; + /* IPv4 only + struct sockaddr_in serv_addr; + */ #endif /* @@ -214,8 +217,15 @@ bad=true; } #else + /* IPv4 only bad = !fc_lookup_host(servername, &serv_addr); serv_addr.sin_port = htons(srvarg.metaserver_port); + */ + /* Dual-stack Compliant */ + sockfd = net_connect_udp(servername, srvarg.metaserver_port); + if (sockfd < 0) {bad = 1;} + else bad = 0; + /* End Dual-stack*/ #endif if (bad) { freelog(LOG_ERROR, _("Metaserver: bad address: [%s]."), servername); @@ -229,16 +239,19 @@ #ifdef GENERATING_MAC /* mac networking */ meta_ep=OTOpenEndpoint(OTCreateConfiguration(kUDPName), 0, &meta_info, &err1); bad = (err1 != 0); -#else +/* IPv4 only +#else bad = ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1); + #endif +*/ if (bad) { freelog(LOG_ERROR, "Metaserver: can't open datagram socket: %s", mystrerror(errno)); metaserver_failed(); return; } - +#endif /* * Bind any local address for us and * associate datagram socket with server. @@ -250,13 +263,16 @@ metaserver_failed(); return; } -#else +/* IPv4 only + #else */ /* no, this is not weird, see man connect(2) --vasc */ - if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))==-1) { +/* IPv4 only + if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))==-1) { freelog(LOG_ERROR, "Metaserver: connect failed: %s", mystrerror(errno)); metaserver_failed(); return; } + */ #endif server_is_open = TRUE; diff -ru -Xdiff_ignore freeciv-1.13.0.orig/server/sernet.c freeciv-1.13.0/server/sernet.c --- freeciv-1.13.0.orig/server/sernet.c Sun Jul 14 15:17:30 2002 +++ freeciv-1.13.0/server/sernet.c Sat Sep 28 23:31:14 2002 @@ -657,6 +657,7 @@ Low level socket stuff, and basic-initialize the connection struct. Returns 0 on success, -1 on failure (bad accept(), or too many connections). + Modified By lucioslayer ... dual-stack compliant ! ********************************************************************/ static int server_accept_connection(int sockfd) { @@ -668,8 +669,16 @@ # endif int new_sock; + /* IPv4 Only struct sockaddr_in fromend; struct hostent *from; + */ + /* Dual Stack compliant */ + struct sockaddr *fromend; + char from[14]; + struct hostent *hostres; + int err; + /* End dual-stack */ int i; fromlen = sizeof(fromend); @@ -681,8 +690,25 @@ my_nonblock(new_sock); - from=gethostbyaddr((char *)&fromend.sin_addr, sizeof(fromend.sin_addr), - AF_INET); + /* IPv4 only : suppressed +from=gethostbyaddr((char *)&fromend.sin_addr, sizeof(fromend.sin_addr),AF_INET); + */ + /* Dual-stack compliant but getipnodebyaddr() is till not available ;=(((*/ +/* struct hostent *ip=getipnodebyaddr(const void *addr, + size_t len, int af, + int flags, int *error_num); +*/ +/* if (!(*hostres=getipnodebyaddr(fromend->sa_data, fromlen, AF_INET6, AI_ALL, err))==NULL) + from=hostres->h_name; + else { if (!(*hostres=getipnodebyaddr(fromend->sa_data, fromlen, AF_INET, AI_ALL, err))==NULL) + from=hostres>h_name; + else { *from=fromend->sa_data; + } + } + freehostent(*hostres); + */ +*from=fromend->sa_data; + /* End dual-stack */ for(i=0; iname, makeup_connection_name(&pconn->id)); sz_strlcpy(pconn->addr, - (from ? from->h_name : inet_ntoa(fromend.sin_addr))); - + /* IPv4 only + (from ? from->h_name : inet_ntoa(fromend.sin_addr))); + */ + from); conn_list_insert_back(&game.all_connections, pconn); freelog(LOG_VERBOSE, "connection (%s) from %s", pconn->name, pconn->addr); @@ -724,11 +752,14 @@ /******************************************************************** open server socket to be used to accept client connections + Modified By Lucioslayer ... dual-stack compliant ! ********************************************************************/ int server_open_socket(void) { /* setup socket address */ - struct sockaddr_in src; +/* IPv4 Only */ +/* + struct sockaddr_in src; int opt; if((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) { @@ -756,6 +787,63 @@ freelog(LOG_FATAL, "listen failed: %s", mystrerror(errno)); exit(EXIT_FAILURE); } + */ + /* Dual-stack-compliant */ + /* setup socket address */ + int n; + const int on = 1; + struct addrinfo hints, *res, *ressave; + char serv[30]; + + snprintf(serv,sizeof(serv)-1,"%d",(unsigned int) srvarg.port ); + serv[sizeof(serv)-1]=0; + + bzero(&hints, sizeof(struct addrinfo)); + hints.ai_flags = AI_PASSIVE; + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + + if ( (n = getaddrinfo(NULL, serv, &hints, &res)) != 0) + return -1; + + ressave = res; + + do { + sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol); + if (sock < 0) + { + freelog(LOG_ERROR, "socket failed: %s", mystrerror(errno)); + continue; /* error, try next one */ + } + if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) + freelog(LOG_ERROR, "SO_REUSEADDR failed: %s", mystrerror(errno)); + + if (bind(sock, res->ai_addr, res->ai_addrlen) == 0) + { + freelog(LOG_VERBOSE, "bind is a succes"); + break; /* success */ + } + + close(sock); /* bind error, close and try next one */ + } while ( (res = res->ai_next) != NULL); + + if (res == NULL) { + fprintf(stderr,"server: Connection pb, no valid address"); + freeaddrinfo(ressave); + exit(1); + } + if (sock==-1) + { + freelog(LOG_FATAL, "socket failed: %s", mystrerror(errno)); + exit(1); + } + if(listen(sock, MAX_NUM_CONNECTIONS) == -1) + { + freelog(LOG_FATAL, "listen failed: %s", mystrerror(errno)); + exit(1); + } + + freeaddrinfo(ressave); close_socket_set_callback(close_socket_callback); return 0;