inetd UNIX socket bug (and small fix)

Aragon Gouveia aragon at
Fri Oct 20 13:23:12 PDT 2006


I have been trying to setup a UNIX socket service in inetd, but it appears
the functionality has been broken for some time.  I guess I'm the first to

With a UNIX socket service entry in inetd.conf the socket file is created as
it should be, but when I try make a connection to the socket, it establishes
and then immediately closes.  There is nothing logged to syslog and not
much info when in debug mode (inetd -d).

In my code references below I should mention that I'm still running
4.10-RELEASE so my line numbering might be out.  But from looking at HEAD
via CVSweb it looks like the bug is still there.  Hopefully this
information is of relevance.

I had a look through inetd.c and found the following in cpmip() starting at
line 2202:

                        case AF_INET:
                                p = (char *)&sin4->sin_addr;
                                addrlen = sizeof(struct in_addr);
#ifdef INET6
                        case AF_INET6:
                                p = (char *)&sin6->sin6_addr;
                                addrlen = sizeof(struct in6_addr);
                                /* should not happen */
                                return -1;

There is no case entry for AF_UNIX.  From my testing execution was reaching
the default: entry when an AF_UNIX connection was established.  When cpmip()
returns a negative value it looks like inetd silently closes the socket.

At the bottom of this message is a patch which seems to make it work.  The
only oddity is that when logging is enabled (inetd -l), AF_UNIX connections
are logged as coming from "unknown".  No biggie for me, but there might be a
better fix.

Should I create a PR for this?


--- inetd.c.orig        Sun Jul 27 15:58:05 2003
+++ inetd.c     Fri Oct 20 21:18:59 2006
@@ -2209,6 +2209,10 @@
                                addrlen = sizeof(struct in6_addr);
+                       case AF_UNIX:
+                               p = (char *)&sin4->sin_addr;
+                               addrlen = sizeof(struct in_addr);
+                               break;
                                /* should not happen */
                                return -1;

More information about the freebsd-bugs mailing list