shekarkcb has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,
Greetings.

I have a setup where i am receiving udp streams. I need to check whether these streams are coming in properly or not. Basically vlc player on the same network is streaming a file with udp, and i need to verify whether it is coming to destination properly.
I can achive this using tcpdump,
tcpdump -i eth0 dst 225.1.1.100,
here it displays packets if receiving from 225.1.1.100. Is there any using Perl i can automate this?

Please guide me to resolve this...

Thanks

Replies are listed 'Best First'.
Re: Check udp stream coming in
by moritz (Cardinal) on Oct 12, 2010 at 08:11 UTC
    You can open a pipe to a tcpdump process, and parse its output. See also: perlopentut (search for "Pipe Opens").
    Perl 6 - links to (nearly) everything that is Perl 6.
Re: Check udp stream coming in
by mjscott2702 (Pilgrim) on Oct 12, 2010 at 08:51 UTC
    Yes, there are ways in Perl to automate this - now you just need to define what you are automating!

    As moritz alluded to, you could open a pipe from the tcpdump command, parse the output from that command and do something with that.

    Please be more specific about what you are trying to achieve, maybe show some sample output from the tcpdump command, and what the desired result is. The friendly Monks will be your, erm, friend.

      Hi All,
      Thanks for the reply.

      Let me explain once again. I will be getting udp packets on my machine say 192.168.1.1 (eth1). I will verify this using
      tcpdump
      command. The output would look like this.

      tcpdump -i eth1 dst 225.1.1.152 tcpdump: verbose output suppressed, use -v or -vv for full protocol de +code listening on eth1, link-type EN10MB (Ethernet), capture size 96 bytes + 00:54:45.314015 IP 192.0.0.152.sieve > 225.1.1.152.sieve: UDP, length +1316 00:54:45.314234 IP 192.0.0.152.sieve > 225.1.1.152.sieve: UDP, length +1316 00:54:45.314580 IP 192.0.0.152.sieve > 225.1.1.152.sieve: UDP, length +1316 00:54:45.314768 IP 192.0.0.152.sieve > 225.1.1.152.sieve: UDP, length +1316

      Now 'tcpdump' is a tool which can snif tcp/udp packets, to show that its is coming in properly. I can't every time login to system and run tcpdump and redirect the output to some file, parse the file, extract packet and see whether its fine or not. So i was thinking some script in Perl i can write to automate this. I don't want to use | (pipe) to tcpdump, get the output to a file etc. All i wanted to know is there any way in Perl to see packets are coming in to system? , say bind to system ip , listen for perticular port , check any data is coming in from destination ip etc(Some body told me about Socket programin, i thought i should try that before giving up on Perl). Since i am a newbie.. , Please guide me what kind of packages, tools do i need to use to achive this.
      Your help is appreciated...

      Thanks
        What was being suggested was creating a script that would execute the tcpdump command for you, parse its output, and display whatever you want, based upon the results - no intermediate files, or anything. Without knowing what you are looking for, I can't specify an actual test for the desired output.

        use strict; use warnings; open(my $tcp, "/usr/sbin/tcpdump |"); my $ok = undef; while(<$tcp>) { $ok = 1 if m/\w/; # your test here } print "All things groovy\n" if $ok;
Re: Check udp stream coming in
by locked_user sundialsvc4 (Abbot) on Oct 12, 2010 at 14:13 UTC

    You might be able to do things that way ... but it would be “damned expensive.”   :-<   Much too expensive, I think, to be useful.

    Since it is reasonable to assume that you are “stuck with UDP,” you probably need to deal with the message integrity problem using the nature of the messages that sender and receiver exchange with one another.   Serial numbers and checksums, for example.   Does the VLC protocol that these two programs are using, not already have such things?

    UDP (vs. TCP/IP) by design provides un-verified communications.   In exchange for much lighter network loads, it is possible that not all of the traffic will go through, and the two programs must be prepared to deal with that.

      Thank you all for the reply.

      I was looking for something else. Since tcpdump was a command that would give the o/p, i was interested in that. I could check for udp packets using that, and it works fine. But i heard of socket programing, and hence looking for any similar module that will
      1). Check the UDP packet coming in or not from a particular ip
      2). If possible look into UDP packet, get the TS header, get the program NO, Audio PID, Video PID etc. Any pointers would be greatly appreciated. Thanks.