[Techtalk] Perl Sockets Communication

Kai MacTane kmactane at GothPunk.com
Wed Aug 22 14:38:35 EST 2001

Well, I just got my own message, and my HTML-enabled mail reader had a 
little trouble with changepw.pl -- I think it took note of that MIME-type 
header the script emits, and decided the following batch of text, up to the 
</body> tag, must have been intended to be a Web page. Don't you just love 
when technology gets too helpful for its own limited brains?

Just in case anyone else had similar problems, here's another version of 
the code, with the potentially offending bits altered to a format that will 
be clear to humans, but opaque to machines and software.


# changepw.pl
# CGI script to change user password via HTTP.

require "cgi-lib.pl";
require 5.002;
use Socket;
# use strict;

$username = $input{'userid'};
$oldpass = $input{'oldpasswd'};
$newpass = $input{'newpasswd1'};

print "[an HTML MIME-type content header]";

print <<EOF;
[put the beginnings of a Web page here]

[then, in heading level one, write:]
Testing Socket Connection...


my $socket_file = '/tmp/pwchanged_sock';

print "Opening socket file $socket_file...";

socket(SOCK, PF_UNIX, SOCK_STREAM, 0)      or die "Can't open socket: $!";
connect(SOCK, sockaddr_un($socket_file))   or die "Can't connect: $!";

print "Suceeded!<BR>\n";

### Note: have tried both print and send in the next couple of lines;
### no change in observed script behavior.

#print SOCK "Username: $username; Old Password: $old_pass; New Password: 

send SOCK, "Username: $username; Old Password: $old_pass; New Password: 
$new_pass\n", 0;

print "Sent socket message.<BR>\n";

while (my $line = <SOCK>)
     chomp $line;
     print "Server response: $line<BR>\n";

print "<P>Run complete!\n\n</body>\n</html>\n\n";

exit 0;

There, I hope that comes through properly and is easier to read than the 
screwy version I just got. Again, thanks in advance for any help you all 
can provide.

                                                 --Kai MacTane
"I hear the roar of a big machine,
  Two worlds and in between;
  Hot metal and methedrine.
  I hear your empire down."
                                                 --Sisters of Mercy,
                                                  "Lucretia, My

More information about the Techtalk mailing list