#!/usr/bin/perl $hostname = $ARGV[0]; while() { s/\x0a/\x0d\x0a/g; $message .= $_; } $userfrom=$ENV{'NAME'}; $fullmessage=sprintf("%04d%s%04d%s",length($userfrom),$userfrom,length($message),$message); #print $fullmessage; &open_connection($hostname, 6711); print S $fullmessage; close(S); # Subroutine to open a tcp connection to the specified hostname and port no. # $file_descriptor = open_connection($hostname, $port); sub open_connection { local($them, $port); $them = $_[0]; $port = $_[1]; $AF_INET = 2; $SOCK_STREAM = 1; $SIG{'INT'} = 'dokill'; sub dokill { kill 9,$child if $child; } $sockaddr = 'S n a4 x8'; chop($hostname = `hostname`); ($name,$aliases,$proto) = getprotobyname('tcp'); ($name,$aliases,$port) = getservbyname($port,'tcp') unless $port =~ /^\d+$/;; ($name,$aliases,$type,$len,$thisaddr) = gethostbyname($hostname); ($name,$aliases,$type,$len,$thataddr) = gethostbyname($them); $this = pack($sockaddr, $AF_INET, 0, $thisaddr); $that = pack($sockaddr, $AF_INET, $port, $thataddr); # Make the socket filehandle. unless (socket(S, $AF_INET, $SOCK_STREAM, $proto)) { die $!; } # Give the socket an address. unless (bind(S, $this)) { die $!; } # Call up the server. unless (connect(S,$that)) { die $!; } # Set socket to be command buffered. select(S); $| = 1; select(STDOUT); S; }