I'm writing a script that uses Net:PcapUtils to capture traffic on an ethernet segment. I have the capture working fine, using the Net:PcapUtils::Loop function. Inside that loop, I want the script to stop periodically and listen for a UDP request from a client. The client sends a request like this: 198.59.115.4:34, and the script sends a response like this: 34 198.59.115.4:34, which is a count of how many times it has seen that IP:Port as a destination.
It works, sort of. It counts, it listens, it answers. The problem is this, if it does not receive a request, it seems to wait until it does, not counting in the meantime. I was hoping that an if statement would make it so that if there was no request, it would just continue, but it does not seem to work that way:
So I start up this script and send a request to it from the client. I get a response. If I don't send a request for an hour and then send one, the count is the same. If I just sit there and send mutliple requests, the count goes up.$count ++; if ($count == 500) { $MAXLEN = 1024; $PORTNO = 5151; $sock = IO:SOCKET::INET->new(LocalPort => $PORTNO, Proto => 'udp') or die "socket: $@"; if ($sock->recv($request, $MAXLEN)) { ... close($sock); } $count = 0; }
Any idea how I can get this to work the way I want?
jgentry@swcp.com
In reply to Check for request from UDP client by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |