Agilent Technologies 8714ET Switch User Manual


 
LAN Interface Supplement 6-29
Controlling the Analyzer via the LAN
Controlling Multiple Analyzers using a Perl Script
($name, $alias, $proto) = getprotobyname('tcp');
#
# Create arguments for bind() and connect() calls, below.
# 0000 = Wildcard address
#
$thisport = pack($sockaddr, $AF_INET, $port, "\0\0\0\0");
select(NEW_SOCK); $| = 1; select(stdout);
#
# Open a network connection via a socket
#
socket(SOCK, $PF_INET, $SOCK_STREAM, $proto) ||
die "cannot create socket: $!\n";
bind(SOCK, $thisport) ||
die "cannot bind socket: $!\n";
listen(SOCK, SOMAXCONN) ||
die "cannot listen socket: $!\n";
printf "Listening on port %d.\n", $port;
#
#
for ($con = 1;; $con++) {
#
# Wait for incomming connections
#
$client_addr = accept(NEW_SOCK, SOCK) ||
die "cannot accept socket: $!\n";
# We have a connection!
# printf("Accepted connection #$con!\n");
#
# Here we used to call fork() to fork a child process.
# However, this causes problems if the parent doesn't wait()
# for the child -- zombie child processes are left behind!
# To fix this, it might be better to exec() the child process
# code so that it doesn't wait for the parent.
# This way, we can handle multipe overlapping messages.
# Even if we don't fork(), listen() will allow multiple
# pending connections.
#
# if (($child = fork()) == 0) {
#
# Get info about incoming connection, and print it
#
($af, $port, $ipaddr) = unpack($sockaddr, $client_addr);
@ipaddr = unpack('C4', $ipaddr);
$IP_addr = sprintf("%d.%d.%d.%d",
@ipaddr[0], @ipaddr[1], @ipaddr[2], @ipaddr[3]);
$Date = &ctime(time()); # "Mon Oct 21 21:52:22 PDT 1996\n"
printf "%d: Got message from %s at %s", $con, $IP_addr, $Date;
#
# Read incoming message, and save it to a file