Hi All,
Sorry to reposting the similar question.
I was going through socket programing, got a doubt, what is the difference between udp client and server?
Suppose if i need to listen in my machine for a perticular port (40150 - which will have x amounts of udp packets coming in from a server - direct push) how can i code this on Perl?
i have written this code
# $IP will have the actual ip from where packets are coming in
system(" tcpdump -v -i eth1 dst $IP > file.txt & ");
my $GREP=`ps aux | grep 'tcpdump ' | grep -v grep | awk '{pri
+nt \$2}'`;
chomp($GREP);
print "PID for |$IP| IS -->|$GREP|\n";
print "SLEEEPING FOR 5 seconds....\n";
sleep(5);
chomp($GREP);
print "KILLING PROCESS ID ------->|$GREP|\n";
system("kill -9 $GREP");
my $LINES=`wc -l $path\/file.txt | awk '{ print \$1}'`;
chomp($LINES);
if($LINES > 5) {
# I have ip coming in
} else {
# Looks like ip with udp packets is not coming in
}
}
This subroutine tests given ip is listed on tcpdump, It works great, but i don't want to use tcpdump or any unix related tools (awk, grepm, kill etc). Looks like this is using huge amount of memory. Is there any way i can write this using socket programing?
Any hint ???
Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.