From: Zdeněk Salvet Date: Fri, 22 Jan 2010 08:22:03 +0000 (+0000) Subject: Merge IPv6 changes. X-Git-Tag: glite-lb-harvester_R_1_0_3_1~7 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=c993327186ab4a5b53d0be3276ab61d6576458c2;p=jra1mw.git Merge IPv6 changes. --- diff --git a/org.glite.security.gsoap-plugin/Makefile b/org.glite.security.gsoap-plugin/Makefile index a0ea15d..9d656e5 100644 --- a/org.glite.security.gsoap-plugin/Makefile +++ b/org.glite.security.gsoap-plugin/Makefile @@ -67,7 +67,7 @@ CFLAGS:= ${DEBUG} \ -DWITH_NONAMESPACES \ -I. -I${top_srcdir}/interface \ -I${stagedir}/include \ - ${COVERAGE_FLAGS} -D_GNU_SOURCE -DDATAGRID_EXTENSION + ${COVERAGE_FLAGS} -D_GNU_SOURCE -DDATAGRID_EXTENSION -DWITH_IPV6 LDFLAGS:=${COVERAGE_FLAGS} diff --git a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c index d65e625..f8c9eee 100644 --- a/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c +++ b/org.glite.security.gsoap-plugin/examples/wscalc_srv_ex2.c @@ -33,15 +33,18 @@ main(int argc, char **argv) edg_wll_GssStatus gss_code; edg_wll_GssCred cred = NULL; edg_wll_GssConnection connection; - glite_gsplugin_Context ctx; - struct sockaddr_in a; - int alen; - char *name, *msg; - int opt, - port = 19999; + glite_gsplugin_Context ctx; + struct sockaddr_storage a; + int alen; + char *name, *msg; + int opt, + port = 19999; char *cert_filename = NULL, *key_filename = NULL; - int sock; - + int sock; + struct addrinfo hints; + struct addrinfo *res; + char *portname; + int error; name = strrchr(argv[0],'/'); if ( name ) name++; else name = argv[0]; @@ -78,12 +81,21 @@ main(int argc, char **argv) exit(1); } - alen = sizeof(a); - if ( (sock = socket(PF_INET,SOCK_STREAM,0)) < 0 ) { perror("socket()"); exit(1); } - a.sin_family = AF_INET; - a.sin_port = htons(port); - a.sin_addr.s_addr = INADDR_ANY; - if ( bind(sock, (struct sockaddr *)&a, sizeof(a)) ) { perror("bind()"); exit(1); } + asprintf(&portname, "%d", port); + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_flags = AI_PASSIVE; + hints.ai_socktype = SOCK_STREAM; + error = getaddrinfo(NULL, portname , &hints, &res); + if (error) { + perror(gai_strerror(error)); + exit(1); + } + alen = res->ai_addrlen; + if ( (sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0 ) + { perror("socket()"); exit(1); } + if ( bind(sock, res->ai_addr, res->ai_addrlen) ) { perror("bind()"); exit(1); } + freeaddrinfo(res); if ( listen(sock, 100) ) { perror("listen()"); exit(1); } bzero((char *) &a, alen); diff --git a/org.glite.security.gss/src/glite_gss.c b/org.glite.security.gss/src/glite_gss.c index 0cb7d9c..45ce359 100644 --- a/org.glite.security.gss/src/glite_gss.c +++ b/org.glite.security.gss/src/glite_gss.c @@ -73,15 +73,16 @@ static void callback_handler(void *arg, int status, struct hostent *h) break; } arp->ent->h_addr_list[0] = - malloc(sizeof(struct in_addr)); + malloc(h->h_length); if (arp->ent->h_addr_list[0] == NULL) { free(arp->ent->h_addr_list); arp->err = NETDB_INTERNAL; break; } memcpy(arp->ent->h_addr_list[0], h->h_addr_list[0], - sizeof(struct in_addr)); + h->h_length); arp->ent->h_addr_list[1] = NULL; + arp->ent->h_addrtype = h->h_addrtype; arp->err = NETDB_SUCCESS; } else { arp->err = NO_DATA; @@ -119,7 +120,7 @@ static void free_hostent(struct hostent *h){ } } -static int asyn_gethostbyname(char **addrOut, char const *name, struct timeval *timeout) { +static int asyn_getservbyname(struct sockaddr_storage *addrOut, socklen_t *a_len,char const *name, int port, struct timeval *timeout) { struct asyn_result ar; ares_channel channel; int nfds; @@ -135,7 +136,7 @@ static int asyn_gethostbyname(char **addrOut, char const *name, struct timeval * ar.ent = (struct hostent *) calloc (sizeof(*ar.ent),1); /* query DNS server asynchronously */ - ares_gethostbyname(channel, name, AF_INET, callback_handler, + ares_gethostbyname(channel, name, AF_INET6, callback_handler, (void *) &ar); /* wait for result */ @@ -147,7 +148,7 @@ static int asyn_gethostbyname(char **addrOut, char const *name, struct timeval * break; gettimeofday(&check_time,0); - if (decrement_timeout(timeout, start_time, check_time)) { + if (timeout && decrement_timeout(timeout, start_time, check_time)) { ares_destroy(channel); free_hostent(ar.ent); return(TRY_AGAIN); @@ -174,9 +175,28 @@ static int asyn_gethostbyname(char **addrOut, char const *name, struct timeval * ares_destroy(channel); if (ar.err == NETDB_SUCCESS) { - *addrOut = malloc(sizeof(struct in_addr)); - memcpy(*addrOut,ar.ent->h_addr_list[0], sizeof(struct in_addr)); + struct sockaddr_in *p4 = (struct sockaddr_in *)addrOut; + struct sockaddr_in6 *p6 = (struct sockaddr_in6 *)addrOut; + + memset(addrOut, 0, sizeof *addrOut); + addrOut->ss_family = ar.ent->h_addrtype; + switch (ar.ent->h_addrtype) { + case AF_INET: + memcpy(&p4->sin_addr,ar.ent->h_addr_list[0], sizeof(struct in_addr)); + p4->sin_port = htons(port); + *a_len = sizeof (struct sockaddr_in); + break; + case AF_INET6: + memcpy(&p6->sin6_addr,ar.ent->h_addr_list[0], sizeof(struct in6_addr)); + p6->sin6_port = htons(port); + *a_len = sizeof (struct sockaddr_in6); + break; + default: + return NETDB_INTERNAL; + break; + } } + free_hostent(ar.ent); return(ar.err); } @@ -186,34 +206,16 @@ do_connect(int *s, char const *hostname, int port, struct timeval *timeout) { int sock; struct timeval before,after,to; - struct sockaddr_in a; + struct sockaddr_storage a; + socklen_t a_len; int sock_err; socklen_t err_len; - char *addr; int h_errno; int opt; - sock = socket(AF_INET, SOCK_STREAM, 0); - if (sock < 0) return EDG_WLL_GSS_ERROR_ERRNO; - - opt = 1; - setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,&opt,sizeof opt); - - if (timeout) { - int flags = fcntl(sock, F_GETFL, 0); - if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) - return EDG_WLL_GSS_ERROR_ERRNO; - gettimeofday(&before,NULL); - } - - if (timeout) { - switch (h_errno = asyn_gethostbyname(&addr, hostname, timeout)) { + /* XXX todo: try multiple addresses */ + switch (h_errno = asyn_getservbyname(&a, &a_len, hostname, port, timeout)) { case NETDB_SUCCESS: - memset(&a,0,sizeof a); - a.sin_family = AF_INET; - memcpy(&a.sin_addr.s_addr,addr,sizeof a.sin_addr.s_addr); - a.sin_port = htons(port); - free(addr); break; case TRY_AGAIN: close(sock); @@ -228,23 +230,21 @@ do_connect(int *s, char const *hostname, int port, struct timeval *timeout) errno = h_errno; return EDG_WLL_GSS_ERROR_HERRNO; } - } else { - struct hostent *hp; - hp = gethostbyname(hostname); - if (hp == NULL) { - close(sock); - errno = h_errno; - return EDG_WLL_GSS_ERROR_HERRNO; - } + sock = socket(a.ss_family, SOCK_STREAM, 0); + if (sock < 0) return EDG_WLL_GSS_ERROR_ERRNO; - memset(&a,0,sizeof a); - a.sin_family = AF_INET; - memcpy(&a.sin_addr.s_addr, hp->h_addr_list[0], sizeof(a.sin_addr.s_addr)); - a.sin_port = htons(port); - } + opt = 1; + setsockopt(sock,IPPROTO_TCP,TCP_NODELAY,&opt,sizeof opt); - if (connect(sock,(struct sockaddr *) &a,sizeof a) < 0) { + if (timeout) { + int flags = fcntl(sock, F_GETFL, 0); + if (fcntl(sock, F_SETFL, flags | O_NONBLOCK) < 0) + return EDG_WLL_GSS_ERROR_ERRNO; + gettimeofday(&before,NULL); + } + + if (connect(sock,(struct sockaddr *) &a, a_len) < 0) { if (timeout && errno == EINPROGRESS) { fd_set fds; FD_ZERO(&fds);