inetd
Daemon
The inetd
daemon is invoked at startup time and is now configured by using
smf
. The configuration was previously performed by
/etc/inet/inetd.conf
file. For more information, see the
inetd
(8), and
smf
(7) man pages.
Use inetconv
to convert the configuration file content into SMF format
services, and then manage these services using inetadm
and
svcadm
. For more information, see the
inetconv
(8),
inetadm
(8) and
svcadm
(8) man pages.
The inetd
daemon polls each socket,
waiting for a connection request to the service corresponding to that
socket. For SOCK_STREAM
type sockets,
inetd
accepts using accept
()
on
the listening socket, forks using fork
(), duplicates
using dup
()
the new socket to file descriptors
0
and 1
(stdin
and stdout
), closes other open file descriptors, and
executes using exec
the appropriate server. For more
information, see the
accept
(3C),
fork
(2),
dup
(2), and
exec
(2) man page.
The primary benefit of using inetd
is that services not in use do not
consume system resources. A secondary benefit is that inetd
does
most of the work to establish a connection. The server started by
inetd
has the socket connected to its client on file
descriptors 0
and 1
. The server can
immediately read, write, send, or receive. Servers can use buffered I/O as provided
by the stdio
conventions, as long as the servers use
fflush
when appropriate. For more information, see the
fflush
(3C) man page.
The getpeername
()
routine returns the
address of the peer (process) connected to a socket. This routine is
useful in servers started by inetd
. For example, you
could use this routine to log the Internet address such as
fec0::56:a00:20ff:fe7d:3dd2
, which is conventional
for representing the IPv6 address of a client. An
inetd
server could use the following sample
code:
struct sockaddr_storage name; int namelen = sizeof (name); char abuf[INET6_ADDRSTRLEN]; struct in6_addr addr6; struct in_addr addr; if (getpeername(fd, (struct sockaddr *) &name, &namelen) == -1) { perror("getpeername"); exit(1); } else { addr = ((struct sockaddr_in *)&name)->sin_addr; addr6 = ((struct sockaddr_in6 *)&name)->sin6_addr; if (name.ss_family == AF_INET) { (void) inet_ntop(AF_INET, &addr, abuf, sizeof (abuf)); } else if (name.ss_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&addr6)) { /* this is a IPv4-mapped IPv6 address */ IN6_MAPPED_TO_IN(&addr6, &addr); (void) inet_ntop(AF_INET, &addr, abuf, sizeof (abuf)); } else if (name.ss_family == AF_INET6) { (void) inet_ntop(AF_INET6, &addr6, abuf, sizeof (abuf)); } syslog("Connection from %s\n", abuf); }