From 396c50b0c10ef7bd39a5ac7d7232a64ee4e41160 Mon Sep 17 00:00:00 2001
From: dd
Date: Sat, 1 Sep 2001 08:42:49 +0000
Subject: [PATCH] Introduce a -b option that allows the user to specify which
address to bind to. This is useful for hosts running jails that need syslog
to maintain an open socket to log to a remote host.
Reviewed by: sheldonh
---
usr.sbin/syslogd/syslogd.8 | 5 +++++
usr.sbin/syslogd/syslogd.c | 16 +++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/usr.sbin/syslogd/syslogd.8 b/usr.sbin/syslogd/syslogd.8
index 5e56d2572dbf..641bb4ad2ee1 100644
--- a/usr.sbin/syslogd/syslogd.8
+++ b/usr.sbin/syslogd/syslogd.8
@@ -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 @@ The
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
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index f05f4331bfd8..2a837aad7a30 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -294,7 +294,7 @@ void die __P((int));
void dodie __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));
@@ -324,13 +324,15 @@ main(argc, argv)
fd_set *fdsr = NULL;
FILE *fp;
char *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;
@@ -347,6 +349,9 @@ main(argc, argv)
if (allowaddr(optarg) == -1)
usage();
break;
+ case 'b':
+ bindhostname = optarg;
+ break;
case 'd': /* debug */
Debug++;
break;
@@ -447,7 +452,7 @@ main(argc, argv)
}
}
if (SecureMode <= 1)
- finet = socksetup(family);
+ finet = socksetup(family, bindhostname);
if (finet) {
if (SecureMode) {
@@ -2292,8 +2297,9 @@ log_deadchild(pid, status, name)
}
int *
-socksetup(af)
+socksetup(af, bindhostname)
int af;
+ const char *bindhostname;
{
struct addrinfo hints, *res, *r;
int error, maxs, *s, *socks;
@@ -2302,7 +2308,7 @@ socksetup(af)
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;