Since my ISP now has a news server accessible over IPv6, I added support for it in trn. I stayed away from configuration issues so far, I just manually added a -DINET6 to the Makefile. And I think some of the old stuff can be cleaned out, really... this new socket api makes things a lot simpler. Index: nntpinit.c =================================================================== RCS file: /cvsroot/trn/trn4/nntpinit.c,v retrieving revision 1.1 diff -u -r1.1 nntpinit.c --- nntpinit.c 25 May 2000 05:11:42 -0000 1.1 +++ nntpinit.c 2 Oct 2002 23:51:00 -0000 @@ -135,6 +135,56 @@ char* machine; { int s; +#if INET6 + struct addrinfo hints, *res, *res0; + char portstr[8] = "nntp"; + char *cause = NULL; + int error; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = 0; + if (nntplink.port_number) + sprintf(portstr, "%d", nntplink.port_number); + error = getaddrinfo(machine, portstr, &hints, &res0); + if (error) { + fprintf(stderr, "%s", gai_strerror(error)); + return -1; + } + for (res = res0; res; res = res->ai_next) { + char buf[64] = ""; + s = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (s < 0) { + cause = "socket"; + continue; + } + + inet_ntop(res->ai_family, res->ai_addr, buf, sizeof(buf)); + if (res != res0) + fprintf(stderr, "trying %s...", buf); + + if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { + fprintf(stderr, "connection to %s: ", buf); + perror(""); + cause = "connect"; + close(s); + s = -1; + continue; + } + + break; /* okay we got one */ + + } + if (s < 0) { + fprintf(stderr, "giving up... "); + perror(cause); + } + freeaddrinfo(res0); + + return s; +#else /* INET6 */ struct sockaddr_in sin; #ifdef __hpux int socksize = 0; @@ -268,6 +318,7 @@ #endif /* !EXCELAN */ #endif /* !h_addr */ +#endif /* INET6 */ #ifdef __hpux /* recommended by raj@cup.hp.com */ #define HPSOCKSIZE 0x8000 getsockopt(s, SOL_SOCKET, SO_SNDBUF, (caddr_t)&socksize, (caddr_t)&socksizelen); Index: url.c =================================================================== RCS file: /cvsroot/trn/trn4/url.c,v retrieving revision 1.1 diff -u -r1.1 url.c --- url.c 25 May 2000 05:11:42 -0000 1.1 +++ url.c 2 Oct 2002 23:51:00 -0000 @@ -43,12 +43,57 @@ static int url_port; static char url_path[1024]; +/* + * Why does this not use get_tcp_socket() from nntpinit.c, or vice versa? + */ static int get_url_socket(machine,port) char* machine; int port; { int s; +#if INET6 + struct addrinfo hints, *res, *res0; + char portstr[8] = "nntp"; + char *cause = NULL; + int error; + + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = 0; + sprintf(portstr, "%d", port); + error = getaddrinfo(hostnam, portstr, &hints, &res0); + if (error) { + fprintf(stderr, "%s", gai_strerror(error)); + return -1; + } + nsock = 0; + for (res = res0; res; res = res->ai_next) { + s = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (s < 0) { + cause = "socket"; + continue; + } + + if (connect(s, res->ai_addr, res->ai_addrlen) < 0) { + cause = "connect"; + close(s); + s = -1; + continue; + } + + break; /* okay we got one */ + + } + if (s < 0) { + perror(cause); + } + freeaddrinfo(res0); + + return s; +#else /* INET6 */ struct sockaddr_in sin; #ifdef __hpux int socksize = 0; @@ -153,6 +198,7 @@ return -1; } #endif /* !h_addr */ +#endif /* INET6 */ #ifdef __hpux /* recommended by raj@cup.hp.com */ #define HPSOCKSIZE 0x8000 getsockopt(s, SOL_SOCKET, SO_SNDBUF, (caddr_t)&socksize, (caddr_t)&socksizelen); @@ -316,7 +362,18 @@ /* normal URL type, will have host (optional portnum) */ s += 2; p = url_host; - while (*s && *s != '/' && *s != ':') *p++ = *s++; + /* check for address literal: news://[ip:v6:address]:port/ */ + if (*s == '[') { + while (*s && *s != ']') + *p++ = *s++; + if (!*s) { + printf("Bad address literal: %s\n",url) FLUSH; + return FALSE; + } + s++; /* skip ] */ + } else { + while (*s && *s != '/' && *s != ':') *p++ = *s++; + } *p = '\0'; if (!*s) { printf("Incomplete URL: %s\n",url) FLUSH; ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf