Article View: news.software.nntp
Article #79665Re: A pair of small patches I'd like to see in the mainstream.
From: Julien ÉLIE
Date: Tue, 18 Nov 2008 11:37
Date: Tue, 18 Nov 2008 11:37
75 lines
4241 bytes
4241 bytes
Hi D. Stussy,
> 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.
Let's see whether the substring found is followed by a space or a string
termination.
> 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.
Now up to 256 characters (SMBUF).
I suggest:
Index: status.c
===================================================================
--- status.c (révision 8156)
+++ status.c (copie de travail)
@@ -22,7 +22,9 @@
typedef struct _STATUS {
char name[SMBUF];
- char ip_addr[INET6_ADDRSTRLEN];
+ /* ip_addr may contain a concatenation of several
+ * IPv4 and IPv6 addresses. */
+ char ip_addr[SMBUF];
bool can_stream;
unsigned short activeCxn;
unsigned short sleepingCxns;
@@ -117,6 +119,8 @@
int peers = 0;
char TempString[SMBUF];
char *path;
+ char other_ip_addr[INET6_ADDRSTRLEN];
+ char *p;
STATUS *head, *status, *tmp;
char str[9];
time_t now;
@@ -186,7 +190,21 @@
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.
+ * Make sure we have enough space to write the entire new address. */
+ if ( (((p = strstr(status->ip_addr, other_ip_addr)) == NULL)
+ || ((p != NULL) && (p[strlen(other_ip_addr)] != ' ')
+ && (p[strlen(other_ip_addr)] != '\0')))
+ && (strlen(status->ip_addr) + strlen(other_ip_addr) + 1 <
+ sizeof(status->ip_addr)) ) {
+ 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)
--
Julien ÉLIE
« -- Il ne doit pas être loin et à pied, on va aussi vite que les bœufs !
-- Bien sûr ! Les bœufs sont à pied eux aussi ! » (Astérix)
Technical Details
Message-ID:
<gfu9f2$9tb$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.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!proxad.net!feeder1-2.proxad.net!usenet-fr.net!gegeweb.org!news.trigofacile.com!not-for-mailReferences:
<gdb2rs$7av$1@snarked.org> <gdvpnh$qvj$1@news.trigofacile.com> <ge1138$79b$1@snarked.org>Show Full Headers
Complete Article Headers
Message-ID: <gfu9f2$9tb$1@news.trigofacile.com> Subject: Re: A pair of small patches I'd like to see in the mainstream. Date: Tue, 18 Nov 2008 12:37:58 +0100 From: Julien ÉLIE <iulius@nom-de-mon-site.com.invalid> References: <gdb2rs$7av$1@snarked.org> <gdvpnh$qvj$1@news.trigofacile.com> <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.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!proxad.net!feeder1-2.proxad.net!usenet-fr.net!gegeweb.org!news.trigofacile.com!not-for-mail Newsgroups: news.software.nntp Organization: TrigoFACILE -- http://www.trigofacile.com/ Lines: 75 NNTP-Posting-Host: amontpellier-152-1-44-70.w81-251.abo.wanadoo.fr Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="Windows-1252"; reply-type=original Content-Transfer-Encoding: 8bit X-Trace: news.trigofacile.com 1227008290 10155 81.251.189.70 (18 Nov 2008 X-Complaints-To: abuse@trigofacile.com NNTP-Posting-Date: Tue, 18 Nov 2008 11:38:10 +0000 (UTC) In-Reply-To: <ge1138$79b$1@snarked.org> X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049