package NETSERVER;

use Socket qw(AF_INET PF_INET SOCK_STREAM SOL_SOCKET SO_REUSEADDR INADDR_ANY);

sub startlistener { # Socket fd, port#
    my($LISTENSOCKET,$port) = @_;
    my($proto, $sockin);
    $proto = (getprotobyname("tcp"))[2];
    socket($LISTENSOCKET, PF_INET, SOCK_STREAM, $proto)
	|| die "socket: $!";
    $sockin = Socket::sockaddr_in($port, INADDR_ANY);
    setsockopt($LISTENSOCKET,SOL_SOCKET,SO_REUSEADDR,pack("L",1))
	|| die "Can't reuse addr: $!";;
    bind($LISTENSOCKET, $sockin)
	|| die "bind: $!";
    listen($LISTENSOCKET, 5) 
	|| die "listen: $!";
}

1;
