There are some uses of 'caddr_t' in Inetutils. This is a prehistoric
BSD type. I think it was because early versions of C didn't
automatically convert 'void *' to the appropriate type.

On GNU/Linux:

    $ grep -Er 'caddr_t;' /usr/include/
    /usr/include/asm-generic/posix_types.h:typedef char *               
__kernel_caddr_t;
    /usr/include/linux/coda.h:typedef void * caddr_t;
    /usr/include/bits/types.h:typedef char *__caddr_t;
    /usr/include/sys/types.h:typedef __caddr_t caddr_t;
    /usr/include/X11/Xw32defs.h:typedef char *caddr_t;
    /usr/include/X11/Xw32defs.h:typedef char *caddr_t;
    /usr/include/tirpc/rpc/types.h:typedef __caddr_t caddr_t;

Patch 0001 adds a syntax check for this type and patch 0002 removes
it's uses since this type is not standardized.

I think it would be nice continue removing old C stuff like this.
Another example is 'index' vs 'strchr' and 'rindex' vs 'strrchr'.
That stuff probably hinders portability more than it helps as the
years go on. :)

Collin
From 17afd1df789db615f9a6867688a54e18b8e2f316 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 5 May 2024 18:26:21 -0700
Subject: [PATCH 1/2] cfg.mk: Add checks for 'caddr_t'.

* cfg.mk (sc_bsd_caddr): New rule to check for use of the 'caddr_t'
type. This is an old BSD type representing a 'void *' or similar.
---
 cfg.mk | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cfg.mk b/cfg.mk
index 1be7e6f9..2966ea15 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -90,6 +90,11 @@ sc_unsigned_int:
 	halt='don'\''t use u''_int; instead use unsigned int' \
 	  $(_sc_search_regexp)
 
+sc_bsd_caddr:
+	@prohibit=caddr''_t \
+	halt='don'\''t use caddr''_t; instead use a standard pointer' \
+	  $(_sc_search_regexp)
+
 sc_assignment_in_if:
 	prohibit='\<if *\(.* = ' halt="don't use assignments in if statements"	\
 	  $(_sc_search_regexp)
-- 
2.45.0

From ab637a79ad2efe9285d301f23c91eb38185b4344 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Sun, 5 May 2024 18:47:17 -0700
Subject: [PATCH 2/2] Fix sc_bsd_caddr checks.

* libinetutils/if_index.c (if_nameindex): Don't cast non-void pointer
arithmetic.
* ftp/ftp.c (hookup): Don't cast pointers to memmove and memset.
* src/inetd.c (getconfigent): Likewise.
* telnet/commands.c (tn): Likewise.
---
 ftp/ftp.c               | 2 +-
 libinetutils/if_index.c | 2 +-
 src/inetd.c             | 4 ++--
 telnet/commands.c       | 3 +--
 4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/ftp/ftp.c b/ftp/ftp.c
index ca0eae6e..74232afc 100644
--- a/ftp/ftp.c
+++ b/ftp/ftp.c
@@ -219,7 +219,7 @@ hookup (char *host, int port)
 			 sizeof (timeout));
 
       ctladdrlen = ai->ai_addrlen;
-      memmove ((caddr_t) & hisctladdr, ai->ai_addr, ai->ai_addrlen);
+      memmove (&hisctladdr, ai->ai_addr, ai->ai_addrlen);
       break;
     }				/* for (ai = ai->ai_next) */
 
diff --git a/libinetutils/if_index.c b/libinetutils/if_index.c
index ac1f27a8..3b8c4307 100644
--- a/libinetutils/if_index.c
+++ b/libinetutils/if_index.c
@@ -125,7 +125,7 @@ if_nameindex (void)
 
   i = 0;
   ifr = (struct ifreq *) ifc.ifc_req;
-  end = (struct ifreq *) ((caddr_t) ifr + ifc.ifc_len);
+  end = (struct ifreq *) (ifr + ifc.ifc_len);
   while (ifr < end)
     {
       cur = ifr;
diff --git a/src/inetd.c b/src/inetd.c
index 2d2bd52d..aa7be731 100644
--- a/src/inetd.c
+++ b/src/inetd.c
@@ -994,13 +994,13 @@ getconfigent (FILE *fconfig, const char *file, size_t *line)
   if (serv_node)
     return next_node_sep (sep);
 
-  memset ((caddr_t) sep, 0, sizeof *sep);
+  memset (sep, 0, sizeof *sep);
 
   while (1)
     {
       argcv_free (argc, argv);
       freeconfig (sep);
-      memset ((caddr_t) sep, 0, sizeof *sep);
+      memset (sep, 0, sizeof *sep);
 
       do
 	{
diff --git a/telnet/commands.c b/telnet/commands.c
index 1288fdbd..2212c7f3 100644
--- a/telnet/commands.c
+++ b/telnet/commands.c
@@ -2820,8 +2820,7 @@ tn (int argc, char *argv[])
 	      errno = oerrno;
 	      perror ((char *) 0);
 	      host->h_addr_list++;
-	      memmove ((caddr_t) & sin.sin_addr,
-		       host->h_addr_list[0], host->h_length);
+	      memmove (&sin.sin_addr, host->h_addr_list[0], host->h_length);
 	      close (net);
 	      continue;
 	    }
-- 
2.45.0

  • cfg.mk: Add... Collin Funk
    • Re: cf... Simon Josefsson via Bug reports for the GNU Internet utilities
      • Re... Collin Funk
        • ... Simon Josefsson via Bug reports for the GNU Internet utilities

Reply via email to