#!/bin/perl
#This TCP server sends the IP adress of the client back to the client.
use Socket;
use FileHandle;

socket(S, AF_INET, SOCK_STREAM, 0) or die "$0: $!";
bind(S, sockaddr_in(10566, INADDR_ANY)) or die "$0: $!";
listen(S, SOMAXCONN) or die "$0: $!";
$clientaddress = accept(CLIENT, S) or die "$0: $!";
CLIENT->autoflush();

($port, $ip) = sockaddr_in($clientaddress);
print CLIENT "Your IP address is ", inet_ntoa($ip), ".  Goodbye.\n";

shutdown(CLIENT, SHUT_RDWR) or die "$0: $!";
exit 0;
