Perl socket communications problem

Top Page
Attachments:
Message as email
+ (text/plain)
+ (text/html)
Delete this message
Reply to this message
Author: Ben Weatherall
Date:  
To: PLUG-discuss
Subject: Perl socket communications problem
This is probably somewhat off-topic, but I thought some of the members of this group would be able to assist me. If nothing else, point me to the correct lists for help!

I am working on a daemon in perl that accepts internet style socket connections on a specific port. So far, no problems. It then does an 'accept' so that it can free up the listening socket for further connection requests. Again, no problem... except that I need to be able to tell it what range of ports to "map" the subsequent communications to. If I listen to port 4567, when I do the 'accept' it will transfer further communications to 1039, or maybe 3276, or 59236, or... You get the idea. Due to firewall issues, I need to limit the ports 'accept' will use to something like 4568 - 4599. Any ideas?

See the code snippet below:

my ($name, $aliases, $proto);
($name, $aliases, $proto) = getprotobyname('tcp');
my $mypaddr = pack($sockaddr, $AF_INET, $port, "\0\0\0\0");
select(SOCK); $| = 1;select(STDOUT);
socket(SERVER, $AF_INET, $SOCK_STREAM, $proto)      || die "socket: $!\n";
bind(SERVER, $mypaddr)                              || die "bind: $!\n";
listen(SERVER, SOMAXCONN)                           || die "listen: $!\n";
while($client_address = accept(SOCK, SERVER)) {
    my ($client_port, $client_packed_ip) = sockaddr_in($client_address);
    # Communications to client proceeds using client_port
}



Thanks in advance,
-Ben