mini_inetd_addrinfo that takes an addrinfo instead of a port number

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@10840 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2002-02-18 19:08:59 +00:00
parent f1aa540676
commit c92de0b469
2 changed files with 28 additions and 17 deletions

View File

@@ -59,31 +59,19 @@ accept_it (int s)
} }
/* /*
* Listen on `port' emulating inetd. * Listen on a specified port, emulating inetd.
*/ */
void void
mini_inetd (int port) mini_inetd_addrinfo (struct addrinfo *ai)
{ {
int error, ret; int ret;
struct addrinfo *ai, *a, hints; struct addrinfo *a;
char portstr[NI_MAXSERV];
int n, nalloc, i; int n, nalloc, i;
int *fds; int *fds;
fd_set orig_read_set, read_set; fd_set orig_read_set, read_set;
int max_fd = -1; int max_fd = -1;
memset (&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = PF_UNSPEC;
snprintf (portstr, sizeof(portstr), "%d", ntohs(port));
error = getaddrinfo (NULL, portstr, &hints, &ai);
if (error)
errx (1, "getaddrinfo: %s", gai_strerror (error));
for (nalloc = 0, a = ai; a != NULL; a = a->ai_next) for (nalloc = 0, a = ai; a != NULL; a = a->ai_next)
++nalloc; ++nalloc;
@@ -116,7 +104,6 @@ mini_inetd (int port)
max_fd = max(max_fd, fds[i]); max_fd = max(max_fd, fds[i]);
++i; ++i;
} }
freeaddrinfo (ai);
if (i == 0) if (i == 0)
errx (1, "no sockets"); errx (1, "no sockets");
n = i; n = i;
@@ -136,3 +123,26 @@ mini_inetd (int port)
} }
abort (); abort ();
} }
void
mini_inetd (int port)
{
int error;
struct addrinfo *ai, hints;
char portstr[NI_MAXSERV];
memset (&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = PF_UNSPEC;
snprintf (portstr, sizeof(portstr), "%d", ntohs(port));
error = getaddrinfo (NULL, portstr, &hints, &ai);
if (error)
errx (1, "getaddrinfo: %s", gai_strerror (error));
mini_inetd_addrinfo(ai);
freeaddrinfo(ai);
}

View File

@@ -396,6 +396,7 @@ time_t tm2time (struct tm tm, int local);
int unix_verify_user(char *user, char *password); int unix_verify_user(char *user, char *password);
void mini_inetd_addrinfo (struct addrinfo*);
void mini_inetd (int port); void mini_inetd (int port);
int roken_concat (char *s, size_t len, ...); int roken_concat (char *s, size_t len, ...);