[comp.lang.perl] Help with sockets and lpd

cdp@hertz.njit.edu (Chris Peckham) (06/08/90)

I am attempting to connect to the printer daemon which is on tcp port 
515 using sockets.  The system we are running is Ultrix-32 V3.1 (Rev. 9) 
System #7.  The problem is the same even when I vary the $them
variable below. 

The message that comes back to me is: 'Malformed from address'
If I use the same structure to address the ftp port or telnet 
port, I get the header info of that process back.  The lpd should
respond with a 0 or something telling me ok (or is that my 
misunderstanding :-) ).  

Any help would be greatly appreciated.

Chris Peckham, Systems Programmer
	       New Jersey Institute of Technology
	       cdp@hertz.njit.edu

*****************************************************************************
#!/usr/bin/perl
do 'socket.pl' || die "socket.pl";	# Get sockets info

chop($hostname = `hostname`);
$them=$hostname;			# Can change later

$sockaddr = 'S n a4 x8';		# Set TEMPLATE for pack

# Get names and such
($name, $aliases, $proto) = getprotobyname('tcp');
($name, $aliases, $type, $len, $thisaddr) = gethostbyname($hostname);
($name, $aliases, $port) = getservbyname('printer','tcp');
($name, $aliases, $type, $len, $thataddr) = gethostbyname($them);

$client=pack($sockaddr,&AF_INET,0,$thisaddr);
$server=pack($sockaddr,&AF_INET,$port,$thataddr);

socket(S,&AF_INET,&SOCK_STREAM, $proto) || die "socket: $!";
bind(S, $client) || die "bind: $!";
connect(S, $server) || die "connect: $!";

select(S); $| = 1 ; select(STDOUT);
print S '\002lp\n';
read(S,$line,255);			# Here is the trouble maker
print $line;

close S;

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (06/09/90)

In article <1990Jun7.225250.29252@uvaarpa.Virginia.EDU> cdp@hertz.njit.edu writes:
: 
: I am attempting to connect to the printer daemon which is on tcp port 
: 515 using sockets.  The system we are running is Ultrix-32 V3.1 (Rev. 9) 
: System #7.  The problem is the same even when I vary the $them
: variable below. 
: 
: The message that comes back to me is: 'Malformed from address'
: If I use the same structure to address the ftp port or telnet 
: port, I get the header info of that process back.  The lpd should
: respond with a 0 or something telling me ok (or is that my 
: misunderstanding :-) ).  

My guess (without access to the lpd source) is that lpd is requiring the
port to be a privileged port, since lpq is setuid root.  Running your
script as root, it just sits there forever rather than returning the
error, so I think that's what's going on.

Larry