Index: syslog.conf.5
===================================================================
RCS file: /home/ncvs/src/usr.sbin/syslogd/syslog.conf.5,v
retrieving revision 1.33
diff -U3 -r1.33 syslog.conf.5
--- syslog.conf.5	30 May 2004 10:04:03 -0000	1.33
+++ syslog.conf.5	2 Jul 2004 04:58:14 -0000
@@ -335,12 +335,13 @@
 option may improve performance,
 especially if the kernel is logging many messages.
 .It
-A hostname (preceded by an at
+A hostname
+.Op :service
+(preceded by an at
 .Pq Dq @
 sign).
-Selected messages are forwarded to the
-.Xr syslogd 8
-program on the named host.
+Selected messages are forwarded to the specified service on the named
+host. If not specified, "syslog" service is assumed.
 .It
 A comma separated list of users.
 Selected messages are written to those users
Index: syslogd.8
===================================================================
RCS file: /home/ncvs/src/usr.sbin/syslogd/syslogd.8,v
retrieving revision 1.50
diff -U3 -r1.50 syslogd.8
--- syslogd.8	8 Sep 2003 19:57:22 -0000	1.50
+++ syslogd.8	2 Jul 2004 04:58:15 -0000
@@ -42,7 +42,7 @@
 .Nm
 .Op Fl 46Acdknosuv
 .Op Fl a Ar allowed_peer
-.Op Fl b Ar bind_address
+.Op Fl b Ar bind_address | bind_address:service | :service
 .Op Fl f Ar config_file
 .Op Fl l Ar path
 .Op Fl m Ar mark_interval
Index: syslogd.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.128
diff -U3 -r1.128 syslogd.c
--- syslogd.c	30 May 2004 10:34:58 -0000	1.128
+++ syslogd.c	2 Jul 2004 04:58:16 -0000
@@ -123,6 +123,7 @@
 static const int withscopeid;
 #endif
 
+const char	*Syslog = "syslog";
 const char	*ConfFile = _PATH_LOGCONF;
 const char	*PidFile = _PATH_LOGPID;
 const char	ctty[] = _PATH_CONSOLE;
@@ -169,7 +170,8 @@
 	union {
 		char	f_uname[MAXUNAMES][UT_NAMESIZE+1];
 		struct {
-			char	f_hname[MAXHOSTNAMELEN];
+			char	*f_hname;
+			const char	*f_port;
 			struct addrinfo *f_addr;
 
 		} f_forw;		/* forwarding address */
@@ -306,7 +308,7 @@
 static void	dodie(int);
 static void	domark(int);
 static void	fprintlog(struct filed *, int, const char *);
-static int	*socksetup(int, const char *);
+static int	*socksetup(int, const char *, const char *);
 static void	init(int);
 static void	logerror(const char *);
 static void	logmsg(int, const char *, const char *, int);
@@ -334,7 +336,7 @@
 	fd_set *fdsr = NULL;
 	FILE *fp;
 	char line[MAXLINE + 1];
-	const char *bindhostname, *hname;
+	const char *bindhostname, *bindport, *hname;
 	struct timeval tv, *tvp;
 	struct sigaction sact;
 	sigset_t mask;
@@ -342,6 +344,7 @@
 	socklen_t len;
 
 	bindhostname = NULL;
+	bindport = Syslog;
 	while ((ch = getopt(argc, argv, "46Aa:b:cdf:kl:m:nop:P:suv")) != -1)
 		switch (ch) {
 		case '4':
@@ -361,6 +364,14 @@
 			break;
 		case 'b':
 			bindhostname = optarg;
+			optarg = strchr(optarg, ':');
+			if (optarg) {
+				if (optarg == bindhostname)
+					/* only port specified */
+					bindhostname = NULL;
+				*optarg = '\0';
+				bindport = optarg + 1;
+			}
 			break;
 		case 'c':
 			no_compress++;
@@ -473,7 +484,7 @@
 		}
 	}
 	if (SecureMode <= 1)
-		finet = socksetup(family, bindhostname);
+		finet = socksetup(family, bindhostname, bindport);
 
 	if (finet) {
 		if (SecureMode) {
@@ -1082,7 +1093,13 @@
 		break;
 
 	case F_FORW:
-		dprintf(" %s\n", f->f_un.f_forw.f_hname);
+		if (Debug) {
+			if (f->f_un.f_forw.f_hname != Syslog)
+				printf(" %s:%s\n", f->f_un.f_forw.f_hname,
+				    f->f_un.f_forw.f_port);
+			else
+				printf(" %s\n", f->f_un.f_forw.f_hname);
+		}
 		/* check for local vs remote messages */
 		if (strcasecmp(f->f_prevhost, LocalHostName))
 			l = snprintf(line, sizeof line - 1,
@@ -1456,8 +1473,13 @@
 			fprintlog(f, 0, (char *)NULL);
 
 		switch (f->f_type) {
-		case F_FILE:
 		case F_FORW:
+			if (f->f_un.f_forw.f_hname)
+				free(f->f_un.f_forw.f_hname);
+			if (f->f_un.f_forw.f_addr)
+				freeaddrinfo(f->f_un.f_forw.f_addr);
+			/* FALLTHROUGH */
+		case F_FILE:
 		case F_CONSOLE:
 		case F_TTY:
 			(void)close(f->f_file);
@@ -1590,6 +1612,8 @@
 
 			case F_FORW:
 				printf("%s", f->f_un.f_forw.f_hname);
+				if (f->f_un.f_forw.f_port != Syslog)
+					printf(":%s", f->f_un.f_forw.f_port);
 				break;
 
 			case F_PIPE:
@@ -1794,13 +1818,27 @@
 
 	switch (*p) {
 	case '@':
-		(void)strlcpy(f->f_un.f_forw.f_hname, ++p,
-			sizeof(f->f_un.f_forw.f_hname));
+		f->f_un.f_forw.f_hname = strdup(++p);
+		if (f->f_un.f_forw.f_hname == NULL) {
+			logerror("strdup");
+			exit(1);
+		}
+		/*
+		 * See if the "hostname" is in the form of
+		 * hostname:service, otherwise, default the service
+		 * to "syslog"
+		 */
+		bp = strchr(f->f_un.f_forw.f_hname, ':');
+		if (bp) {
+			*bp = '\0';
+			f->f_un.f_forw.f_port = bp + 1;
+		} else
+			f->f_un.f_forw.f_port = Syslog;
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_family = family;
 		hints.ai_socktype = SOCK_DGRAM;
-		error = getaddrinfo(f->f_un.f_forw.f_hname, "syslog", &hints,
-				    &res);
+		error = getaddrinfo(f->f_un.f_forw.f_hname,
+		    f->f_un.f_forw.f_port, &hints, &res);
 		if (error) {
 			logerror(gai_strerror(error));
 			break;
@@ -2055,7 +2093,7 @@
 				return (-1); /* port not numeric */
 		}
 	} else {
-		if ((se = getservbyname("syslog", "udp")))
+		if ((se = getservbyname(Syslog, "udp")))
 			ap.port = ntohs(se->s_port);
 		else
 			/* sanity, should not happen */
@@ -2455,7 +2493,7 @@
 }
 
 static int *
-socksetup(int af, const char *bindhostname)
+socksetup(int af, const char *bindhostname, const char *bindport)
 {
 	struct addrinfo hints, *res, *r;
 	int error, maxs, *s, *socks;
@@ -2464,7 +2502,7 @@
 	hints.ai_flags = AI_PASSIVE;
 	hints.ai_family = af;
 	hints.ai_socktype = SOCK_DGRAM;
-	error = getaddrinfo(bindhostname, "syslog", &hints, &res);
+	error = getaddrinfo(bindhostname, bindport, &hints, &res);
 	if (error) {
 		logerror(gai_strerror(error));
 		errno = 0;
