Subject: bin/9975: lpd ignores port number in /etc/printcap "lp" attribute
To: None <gnats-bugs@gnats.netbsd.org>
From: Andreas Gustafsson <gson@nominum.com>
List: netbsd-bugs
Date: 04/24/2000 18:39:15
>Number:         9975
>Category:       bin
>Synopsis:       lpd ignores port number in /etc/printcap "lp" attribute
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Apr 24 18:40:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Andreas Gustafsson
>Release:        NetBSD-current as of Apr 24, 2000
>Organization:
Nominum Inc
>Environment:
System: NetBSD trebuchet.rc.vix.com 1.4U NetBSD 1.4U (TREBUCHET) #0: Thu Mar 9 17:12:21 PST 2000 gson@trebuchet.rc.vix.com:/usr/src/sys/arch/i386/compile/TREBUCHET i386

>Description:

When the /etc/printcap "lp" attribute contains a port@hostname
construct, as in ":lp=9100@hp-laserjet.example.com:", lpd ignores the
port number and tries to send the data to the "printer" port instead.
This was apparently broken by some recent IPv6 related changes to
src/usr.sbin/lpr/common_source/common.c.

>How-To-Repeat:

Try printing directly to a HP LaserJet from a recent -current
system.

>Fix:

Here's a brute force fix.  There are probably cleaner ways...

Index: usr.sbin/lpr/common_source/common.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/lpr/common_source/common.c,v
retrieving revision 1.19
diff -u -r1.19 common.c
--- common.c	2000/04/24 02:53:05	1.19
+++ common.c	2000/04/25 01:20:16
@@ -133,16 +133,21 @@
 	int s, lport = IPPORT_RESERVED - 1;
 	int error;
 	int refuse, trial;
+	char portbuf[16];
 
 	/*
 	 * Get the host address and port number to connect to.
 	 */
 	if (rhost == NULL)
 		fatal("no remote host to connect to");
+	if (rport == 0)
+		strcpy(portbuf, "printer");
+	else
+		sprintf(portbuf, "%d", rport);
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = PF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	error = getaddrinfo(rhost, "printer", &hints, &res);
+	error = getaddrinfo(rhost, portbuf, &hints, &res);
 	if (error)
 		fatal("printer/tcp: %s", gai_strerror(error));
 
>Release-Note:
>Audit-Trail:
>Unformatted: