🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #79567

Re: A pair of small patches I'd like to see in the mainstream.

#79567
From: Julien ÉLIE
Date: Sat, 25 Oct 2008 18:49
100 lines
4730 bytes
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)...


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...

-- 
Julien ÉLIE

« Avec les machines NEDAP, le vote est TELLEMENT secret que même les
  électeurs n'ont aucune garantie que leur vote soit réellement crédité au
  compte de voix du candidat de son choix ! »
Technical Details
Message-ID: <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!feeder1.news.weretis.net!newsfeeder.dynfx.net!weretis.net!news.trigofacile.com!not-for-mail
References: <gdb2rs$7av$1@snarked.org>

Show Full Headers
Complete Article Headers
Message-ID: <gdvpnh$qvj$1@news.trigofacile.com>
Subject: Re: A pair of small patches I'd like to see in the mainstream.
Date: Sat, 25 Oct 2008 20:49:20 +0200
From: Julien ÉLIE <iulius@nom-de-mon-site.com.invalid>
References: <gdb2rs$7av$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!feeder1.news.weretis.net!newsfeeder.dynfx.net!weretis.net!news.trigofacile.com!not-for-mail
Newsgroups: news.software.nntp
Organization: TrigoFACILE -- http://www.trigofacile.com/
Lines: 100
NNTP-Posting-Host: aaubervilliers-151-1-40-153.w83-112.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 1224960562 27635 83.112.151.153 (25 Oct 2008
X-Complaints-To: abuse@trigofacile.com
NNTP-Posting-Date: Sat, 25 Oct 2008 18:49:22 +0000 (UTC)
In-Reply-To: <gdb2rs$7av$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