Article View: news.software.nntp
Article #79572Re: A pair of small patches I'd like to see in the mainstream.
From: D. Stussy
Date: Sun, 26 Oct 2008 06:00
Date: Sun, 26 Oct 2008 06:00
135 lines
6545 bytes
6545 bytes
"Julien ÉLIE" <iulius@nom-de-mon-site.com.invalid> wrote in message
news:gdvpnh$qvj$1@news.trigofacile.com...
> Hi D. Stussy,
>
> > + } else {
> > + char *p;
> > +
> > + p = sprint_sockaddr((struct sockaddr *)&cp->Address);
> > + if ((strstr(status->ip_addr, p) == NULL) &&
> > + (strlen(status->ip_addr) + strlen(p) + 1 <
sizeof(status->ip_addr))) {
> > + strcat(status->ip_addr, " ");
> > + strcat(status->ip_addr, p);
> > + }
>
> strlcat should be used instead of strcat.
> Be careful if cp->Address.ss_family is 0 (local connection)...
1) "strlcat"? If by this you mean a strcat with a maximum length to copy
specified, note that such is unnecessary as the routine has already checked
to make certain sufficient space exists. It cannot overrun the destination
string length.
2) Any issue with cp->Address fields should be handled by the called
subroutine. However, note that since this ADDS an address to a string that
ALREADY HAS and address, the data design may already exclude local
connections.
3) There should be a better way of checking of the address already appears
in the list than strstr, but how often in the real world does one address in
use be a non-identical substring of another in use at the same host? I
suppose that "10.x.y.24" and "10.x.y.247" could be in use, and if so, a
".24" found after the ".247" would be a substring and ignored. However, I
considered that so remote as to be negligible, and if it were to happen,
it's no worse than the original code that only prints the first address
found.
Although your suggested code for v2.5 below assumes one IPv4 and one IPv6,
please also note that my design will handle multiple addresses of either
family in any combination. I note that two of my real-world peers have
multiple IPv4 addresses that they use to send to me, and I have seen
instances where two or more of the same address family were simultaneously
in use. I believe that your code may execute the strlcats even if they
don't change the string while my code will skip them if there's insufficient
room. It's also possible that your code may add multiple spaces before
concatenating an address, while mine won't (e.g. enough room to add the
separating space but not the address, and later, a shorter address that fits
is found). By changing the conditional and using strlcat, you may have
introduced undesired side effects.
> Suggestion for INN 2.5 (where there is no buffer of 64 chars):
>
> Index: status.c
> ===================================================================
> --- status.c (révision 8141)
> +++ status.c (copie de travail)
> @@ -22,7 +22,9 @@
>
> typedef struct _STATUS {
> char name[SMBUF];
> - char ip_addr[INET6_ADDRSTRLEN];
> + /* ip_addr may contain the concatenation of an IPv4 address
> + * and an IPv6 address. */
> + char ip_addr[INET_ADDRSTRLEN + INET6_ADDRSTRLEN + 1];
> bool can_stream;
> unsigned short activeCxn;
> unsigned short sleepingCxns;
> @@ -117,6 +119,7 @@
> int peers = 0;
> char TempString[SMBUF];
> char *path;
> + char other_ip_addr[INET6_ADDRSTRLEN];
> STATUS *head, *status, *tmp;
> char str[9];
> time_t now;
> @@ -186,7 +189,16 @@
> else
> tmp->next = status;
> tmp = status;
> + } else if (cp->Address.ss_family != 0) {
> + network_sockaddr_sprint(other_ip_addr, sizeof(other_ip_addr),
> + (struct sockaddr *) &cp->Address);
> + /* Concatenate the addresses if it is a new one. */
> + if (strstr(status->ip_addr, other_ip_addr) == NULL) {
> + strlcat(status->ip_addr, " ", sizeof(status->ip_addr));
> + strlcat(status->ip_addr, other_ip_addr, sizeof(status->ip_addr));
> + }
> }
> +
> if (Now.tv_sec - cp->Started > status->seconds)
> status->seconds = Now.tv_sec - cp->Started;
> if (Now.tv_sec - cp->Started > seconds)
>
>
>
>
> > diff -ur innfeed/host.c innfeed/host.c
> > --- innfeed/host.c 2008-05-05 10:18:36.000000000 +0000
> > +++ innfeed/host.c 2008-05-14 21:50:38.000000000 +0000
> > @@ -3477,6 +3478,20 @@
> >
> > fputc ('\n',fp) ;
> >
> > + if (host->ipAddrs) {
> > + int i;
> > + char *family;
> > +
> > + for(i=0; host->ipAddrs[i] != NULL; ++i) {
> > + switch(host->ipAddrs[i]->sa_family) {
> > + case AF_INET: family="IPv4"; break;
> > + case AF_INET6: family="IPv6"; break;
> > + default: family="????"; break;
> > + }
> > + fprintf(fp,"Address %-2u: %-4.4s %s\n", i+1, family,
sprint_sockaddr(host->ipAddrs[i]));
> > + }
> > + }
> > +
> > fprintf (fp, " seconds: %-7ld art. timeout: %-5d ip name:
%s\n",
> > host->firstConnectTime > 0 ? (long)(now -
host->firstConnectTime) : 0,
> > host->params->articleTimeout, host->params->ipName) ;
> >
> >
> > Comments?
>
> It looks good to me. But #ifdef for IPv6 capability should be added;
otherwise,
> there are compilation issues on some platforms...
Point noted. Don't forget #ifdef's for IPv4 too (someone may compile an
IPv6-only version someday).
Technical Details
Message-ID:
<ge1138$79b$1@snarked.org>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder.erje.net!news.snarked.org!not-for-mailReferences:
<gdb2rs$7av$1@snarked.org> <gdvpnh$qvj$1@news.trigofacile.com>Show Full Headers
Complete Article Headers
Message-ID: <ge1138$79b$1@snarked.org> Subject: Re: A pair of small patches I'd like to see in the mainstream. Date: Sat, 25 Oct 2008 23:00:52 -0700 From: "D. Stussy" <spam@bde-arc.ampr.org> References: <gdb2rs$7av$1@snarked.org> <gdvpnh$qvj$1@news.trigofacile.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20141118.mbox.gz!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder.erje.net!news.snarked.org!not-for-mail Newsgroups: news.software.nntp Lines: 135 Reply-To: "D. Stussy" <replies@newsgroups.kd6lvw.ampr.org> NNTP-Posting-Host: pool-71-118-52-187.lsanca.dsl-w.verizon.net X-Trace: snarked.org 1225000873 7467 71.118.52.187 (26 Oct 2008 06:01:13 GMT) X-Complaints-To: newsmaster@snarked.org NNTP-Posting-Date: Sun, 26 Oct 2008 06:01:13 +0000 (UTC) X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1478 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1478