diff options
author | Oliver Fromme <olli@FreeBSD.org> | 2010-08-07 16:20:12 +0000 |
---|---|---|
committer | Oliver Fromme <olli@FreeBSD.org> | 2010-08-07 16:20:12 +0000 |
commit | 974835c956ee8041ed16066038326475d443d15b (patch) | |
tree | 4049e8751d59c1b4729c17a0cbab04c84dc26601 /usr.sbin/syslogd | |
parent | ce617aca0add5e7889a0e51316ec2cca95f3285e (diff) | |
download | src-974835c956ee8041ed16066038326475d443d15b.tar.gz src-974835c956ee8041ed16066038326475d443d15b.zip |
Notes
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r-- | usr.sbin/syslogd/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/syslogd/syslogd.8 | 27 | ||||
-rw-r--r-- | usr.sbin/syslogd/syslogd.c | 40 |
3 files changed, 60 insertions, 9 deletions
diff --git a/usr.sbin/syslogd/Makefile b/usr.sbin/syslogd/Makefile index 1682b499de05..3a2a80b30e0c 100644 --- a/usr.sbin/syslogd/Makefile +++ b/usr.sbin/syslogd/Makefile @@ -12,7 +12,7 @@ SRCS= syslogd.c ttymsg.c DPADD= ${LIBUTIL} LDADD= -lutil -WARNS?= 3 +WARNS?= 6 .if ${MK_INET6_SUPPORT} != "no" CFLAGS+= -DINET6 diff --git a/usr.sbin/syslogd/syslogd.8 b/usr.sbin/syslogd/syslogd.8 index aae9b4f92343..ff0141daa08c 100644 --- a/usr.sbin/syslogd/syslogd.8 +++ b/usr.sbin/syslogd/syslogd.8 @@ -171,10 +171,29 @@ 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 Xo +.Fl b +.Sm off +.Ar bind_address Op : Ar service +.Sm on +.Xc +.It Xo +.Fl b +.Sm off +.Li : Ar service +.Sm on +.Xc +Bind to a specific address and/or port. +The address can be specified as a hostname, +and the port as a service name. +If an IPv6 address is specified, it should be enclosed with +.Ql \&[ +and +.Ql \&] . +The default +.Ar service +is +.Ql syslog . .It Fl C Create log files that do not exist (permission is set to .Li 0600 ) . diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c index b803969c8547..e97f8dc77213 100644 --- a/usr.sbin/syslogd/syslogd.c +++ b/usr.sbin/syslogd/syslogd.c @@ -317,7 +317,7 @@ static void dodie(int); static void dofsync(void); static void domark(int); static void fprintlog(struct filed *, int, const char *); -static int *socksetup(int, const char *); +static int *socksetup(int, char *); static void init(int); static void logerror(const char *); static void logmsg(int, const char *, const char *, int); @@ -345,7 +345,8 @@ main(int argc, char *argv[]) struct sockaddr_storage frominet; fd_set *fdsr = NULL; char line[MAXLINE + 1]; - const char *bindhostname, *hname; + char *bindhostname; + const char *hname; struct timeval tv, *tvp; struct sigaction sact; struct funix *fx, *fx1; @@ -2605,16 +2606,47 @@ log_deadchild(pid_t pid, int status, const char *name) } static int * -socksetup(int af, const char *bindhostname) +socksetup(int af, char *bindhostname) { struct addrinfo hints, *res, *r; + const char *bindservice; + char *cp; int error, maxs, *s, *socks; + /* + * We have to handle this case for backwards compatibility: + * If there are two (or more) colons but no '[' and ']', + * assume this is an inet6 address without a service. + */ + bindservice = "syslog"; + if (bindhostname != NULL) { +#ifdef INET6 + if (*bindhostname == '[' && + (cp = strchr(bindhostname + 1, ']')) != NULL) { + ++bindhostname; + *cp = '\0'; + if (cp[1] == ':' && cp[2] != '\0') + bindservice = cp + 2; + } else { +#endif + cp = strchr(bindhostname, ':'); + if (cp != NULL && strchr(cp + 1, ':') == NULL) { + *cp = '\0'; + if (cp[1] != '\0') + bindservice = cp + 1; + if (cp == bindhostname) + bindhostname = NULL; + } +#ifdef INET6 + } +#endif + } + memset(&hints, 0, sizeof(hints)); hints.ai_flags = AI_PASSIVE; hints.ai_family = af; hints.ai_socktype = SOCK_DGRAM; - error = getaddrinfo(bindhostname, "syslog", &hints, &res); + error = getaddrinfo(bindhostname, bindservice, &hints, &res); if (error) { logerror(gai_strerror(error)); errno = 0; |