Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Aug 2001 04:23:06 -0700
From:      Dima Dorfman <dima@unixfreak.org>
To:        hackers@freebsd.org
Subject:   syslogd bound to a specific address?
Message-ID:  <20010827112311.7DD633E31@bazooka.unixfreak.org>

next in thread | raw e-mail | index | archive | help
Is there a compelling reason why syslogd doesn't have an option to
make it bind to a specific address?  Most daemons have one, but
syslogd does not.  I'm asking because jail(8) explicitly mentions that
syslogd doesn't support this, which either means the author knows why
it can't reasonably support it, or doesn't have the time to write it.

The patch attached below seems to work reasonably well for me.  Is
there something I'm missing?

Thanks.

Index: syslogd.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/syslogd/syslogd.8,v
retrieving revision 1.40
diff -u -r1.40 syslogd.8
--- syslogd.8	2001/08/27 11:04:09	1.40
+++ syslogd.8	2001/08/27 11:11:10
@@ -42,6 +42,7 @@
 .Nm
 .Op Fl 46Adknsuv
 .Op Fl a Ar allowed_peer
+.Op Fl b Ar bind_address
 .Op Fl f Ar config_file
 .Op Fl m Ar mark_interval
 .Op Fl p Ar log_socket
@@ -151,6 +152,10 @@
 options are ignored if the
 .Fl s
 option is also specified.
+.It Fl b Ar bind_address
+Specify one specific IP address or hostname to bind to.
+If a hostname is specified,
+the IPv4 or IPv6 address which corresponds to it is used.
 .It Fl d
 Put
 .Nm
Index: syslogd.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.80
diff -u -r1.80 syslogd.c
--- syslogd.c	2001/07/19 22:04:09	1.80
+++ syslogd.c	2001/08/27 11:11:11
@@ -291,7 +291,7 @@
 void	die __P((int));
 void	domark __P((int));
 void	fprintlog __P((struct filed *, int, char *));
-int*	socksetup __P((int));
+int*	socksetup __P((int, const char *));
 void	init __P((int));
 void	logerror __P((const char *));
 void	logmsg __P((int, char *, char *, int));
@@ -319,13 +319,15 @@
 	struct sockaddr_storage frominet;
 	FILE *fp;
 	char *p, *hname, line[MAXLINE + 1];
+	const char *bindhostname;
 	struct timeval tv, *tvp;
 	struct sigaction sact;
 	sigset_t mask;
 	pid_t ppid = 1;
 	socklen_t len;
 
-	while ((ch = getopt(argc, argv, "46Aa:df:kl:m:np:P:suv")) != -1)
+	bindhostname = NULL;
+	while ((ch = getopt(argc, argv, "46Aa:b:df:kl:m:np:P:suv")) != -1)
 		switch (ch) {
 		case '4':
 			family = PF_INET;
@@ -342,6 +344,9 @@
 			if (allowaddr(optarg) == -1)
 				usage();
 			break;
+		case 'b':
+			bindhostname = optarg;
+			break;
 		case 'd':		/* debug */
 			Debug++;
 			break;
@@ -447,7 +452,7 @@
 		}
 	}
 	if (SecureMode <= 1)
-		finet = socksetup(family);
+		finet = socksetup(family, bindhostname);
 
 	if (finet) {
 		if (SecureMode) {
@@ -2235,8 +2240,9 @@
 }
 
 int *
-socksetup(af)
+socksetup(af, bindhostname)
 	int af;
+	const char *bindhostname;
 {
 	struct addrinfo hints, *res, *r;
 	int error, maxs, *s, *socks;
@@ -2245,7 +2251,7 @@
 	hints.ai_flags = AI_PASSIVE;
 	hints.ai_family = af;
 	hints.ai_socktype = SOCK_DGRAM;
-	error = getaddrinfo(NULL, "syslog", &hints, &res);
+	error = getaddrinfo(bindhostname, "syslog", &hints, &res);
 	if (error) {
 		logerror(gai_strerror(error));
 		errno = 0;


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010827112311.7DD633E31>