Index: src/in.swhoisd.h
--- src/in.swhoisd.h.orig	2001-07-10 18:17:55 +0200
+++ src/in.swhoisd.h	2005-03-31 16:31:13 +0200
@@ -33,12 +33,14 @@
 #endif
 
 #define	MAXLINE			1024	/* for buffering purposes */
-#define	MYNAME			"in.swhoisd"
+#define	MYNAME			"swhoisd"
 #define	NLS_DOMAIN		"swhoisd" /* for GNU gettext */
 
 #define	SYSCONFDIR 		"/etc"
 #define	SYSLOGDIR 		"/var/log"
+#define	SYSPIDDIR 		"/var/run"
 #define	DAEMON_LOG_FILENAME	SYSLOGDIR "/swhoisd.log"
+#define	DAEMON_PID_FILENAME	SYSLOGDIR "/swhoisd.pid"
 
 /* We use the HTTPD "Common Logfile Format"'s time stamp format: */
 #define	TIMESTAMP_FORMAT	"%d/%b/%Y:%H:%M:%M"
@@ -110,6 +112,8 @@
 extern int	standalone_mode;	/* -s flag (-i disables) */
 extern uid_t	desired_uid;		/* -u flag */
 extern gid_t	desired_gid;		/* -u flag */
+extern char *   desired_host;		/* -h flag */
+extern char *   desired_port;		/* -p flag */
 
 /* Perform the requested whois operation: */
 int do_whois(FILE *in_fd, FILE *out_fd, char *ident);
Index: src/main.c
--- src/main.c.orig	2001-07-04 08:15:04 +0200
+++ src/main.c	2005-03-31 16:30:41 +0200
@@ -38,6 +38,8 @@
 #endif
 uid_t	desired_uid;				/* -u flag */
 gid_t	desired_gid;				/* -u flag */
+char *  desired_host;               /* -H flag */
+char *  desired_port;               /* -P flag */
 
 
 /*
@@ -95,6 +97,8 @@
 	/* Set default values for various options */
 	desired_uid = get_nobody_uid();
 	desired_gid = get_nogroup_gid();
+    desired_host = "";
+    desired_port = "43";
 
 #ifndef INET_ONLY
 	/* If stdin is a socket, default to inetd mode: */
@@ -104,7 +108,7 @@
 #endif
 
 	/* Parse command line options, if any */
-	while ((c = getopt(argc, argv, "d:g:hlnsu:")) != EOF) {
+	while ((c = getopt(argc, argv, "d:g:hlnsu:H:P:")) != EOF) {
 		switch (c) {
 		case 'd':
 			delay_time = atoi(optarg);
@@ -132,6 +136,12 @@
 		case 'u':
 			desired_uid = atoi(optarg);
 			break;
+		case 'H':
+			desired_host = optarg;
+			break;
+		case 'P':
+			desired_port = optarg;
+			break;
 		case 'h': /*FALLTHROUGH*/
 		case '?': /*FALLTHROUGH*/
 		default:
Index: src/sysutils.c
--- src/sysutils.c.orig	2004-01-04 06:38:16 +0100
+++ src/sysutils.c	2005-03-31 18:02:25 +0200
@@ -31,6 +31,40 @@
 #include <grp.h>		/* getgrnam_r() */
 #include <pwd.h>		/* getpwnam_r() */
 
+#ifdef __FreeBSD__
+#include <osreldate.h>
+#endif
+#if !((defined(__FreeBSD__) && __FreeBSD_version >= 500000) || defined(__linux__) || defined(__sun__))
+int my_getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
+{
+    int rv = 0;
+    struct passwd *lpwd;
+
+    if ((lpwd = getpwnam(name)) != NULL)
+        memcpy(pwd, lpwd, sizeof(struct passwd));
+    else
+        rv = errno;
+    if (result != NULL)
+        *result = (rv == 0 ? pwd : NULL);
+    return rv;
+}
+int my_getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize, struct group **result)
+{
+    int rv = 0;
+    struct group *lgrp;
+
+    if ((lgrp = getgrnam(name)) != NULL)
+        memcpy(grp, lgrp, sizeof(struct group));
+    else
+        rv = errno;
+    if (result != NULL)
+        *result = (rv == 0 ? grp : NULL);
+    return rv;
+}
+#define getpwnam_r my_getpwnam_r
+#define getgrnam_r my_getgrnam_r
+#endif
+
 /*
  * Socket stuff
  */
@@ -77,7 +111,7 @@
 }
 
 
-#if __sun
+#ifndef __linux__
 /*
  * Return 1 if the fd is of the specified type, 0 if not, -1 on error.
  * Present in Linux (sys/socket.h), but not Solaris.
@@ -171,6 +205,19 @@
 	(void) dup(0);
 	(void) dup(0);
 
+    /* write a daemon pidfile */
+    {
+        pid_t pid;
+        FILE *fp;
+        pid = getpid();
+        if ((fp = fopen(DAEMON_PID_FILENAME, "w")) == NULL) {
+            fprintf(stderr, "swhoisd: Can't write pidfile '%s'", DAEMON_PID_FILENAME);
+            exit(1);
+        }
+        fprintf(fp, "%ld\n", (long)pid);
+        fclose(fp);
+    }
+
 	return (0); /* OK */
 }
 
@@ -187,7 +234,7 @@
 	time_t		curtime = 0L;
 	struct tm	*loctime = NULL;
 	struct tm	tm_buf;
-	extern time_t	timezone; /* not set until AFTER localtime_r called */
+	time_t  	timezone;
 	time_t		timezone_minutes;
 
 	if ((buffer == NULL) || (buffer_size <= 0)) {
@@ -201,6 +248,9 @@
 	(void) memset(&tm_buf, 0, sizeof (tm_buf));
 	loctime = localtime_r(&curtime, &tm_buf);
 
+	/* Determine timezone offset */
+	timezone = (time_t)((long)mktime(gmtime(&curtime)) - (long)curtime);
+
 	/* Immediately save global variable and adjust seconds to minutes: */
 	timezone_minutes	= timezone / 60;
 
@@ -941,6 +991,7 @@
 	/* Startup message: */
 	print_syslog(LOG_NOTICE, MYNAME " initialized\n");
 
+#if 0
 	listenfd = tcp_listen(NULL, WHOIS_SERVICE, &addrlen);
 	if (listenfd < 0) { /* Try port number instead of service name */
 		listenfd = tcp_listen(NULL, WHOIS_PORT, &addrlen);
@@ -948,6 +999,11 @@
 			return (-1); /* error */
 		}
 	}
+#else
+	listenfd = tcp_listen(desired_host, desired_port, &addrlen);
+	if (listenfd < 0)
+		return (-1);
+#endif
 
 	/* Must call AFTER privledged whois port has been opened as root: */
 	(void) initialize2();
Index: src/snprintf.c
--- src/snprintf.c.orig	2001-07-04 08:15:04 +0200
+++ src/snprintf.c	2005-10-15 10:15:23 +0200
@@ -37,7 +37,6 @@
  */
 
 #include "config.h"
-#include "in.swhoisd.h"
 #include <stdarg.h>		/* ANSI C header file */
 #include <stdlib.h>		/* exit() */
 #include <string.h>		/* strlen() */
