Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Recieving Raw IP packets.

by Jimmmy Features (Initiate)
on Dec 07, 2005 at 23:27 UTC ( #515070=perlquestion: print w/replies, xml ) Need Help??
Jimmmy Features has asked for the wisdom of the Perl Monks concerning the following question:

Hi. I made a small script in perl that uses the Net::RawIP module to send a tcp packet with the syn flag set to another computer. How would I go about listening for the return packet?

Replies are listed 'Best First'.
Re: Recieving Raw IP packets.
by Celada (Monk) on Dec 08, 2005 at 04:04 UTC
    Since you are dealing with raw packets, you have to listen to everything and filter yourself for the packets you are interested in. You will probably want to consider the packets that are received on the port you used to send packets from, and discard all others. This code will listen to every TCP packet and show you the IP addresses and port numbers involved.
    #!/usr/bin/perl use strict; use Socket; socket S, PF_INET, SOCK_RAW, 6; my $result; while (my $sender = recv(S, $result, 2000, 0)) { print "got a ", length($result), " byte TCP packet...\n"; if (length($result) < 20) { print " ...which is too small to be an IP packet\n"; } else { printf " from %d.%d.%d.%d to %d.%d.%d.%d\n", map { unpack("C", substr($result, $_, 1)) } (12..19); if (length($result) < 40) { print " ...and is too small to be a TCP packet\n"; } else { printf " from port %d to port %d\n", map { unpack("n", substr($result, $_, 2)) } (20, 22); } } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://515070]
Approved by GrandFather
[marto]: holli perfect
[ambrus]: Corion: four days a week? hmm
[Corion]: ambrus: I did that in 2012 and 2013, to try it out, and I found the available time to be worth more to me than the money
[Corion]: I've started that again this month (now forever instead of a limited time), and it already destresses me a lot
[holli]: There are Anti Vaxxer weeks at IKEA.
[Corion]: Of course, it's a 20% cut in the money I receive, while the work doesn't necessarily reduce at all, but my approach is to make the work take longer instead of fitting 5 days worth of work into 4
[holli]: 50% off all children coffins.
[Corion]: holli: Ooof :)
[hippo]: Cut should beless than 20% after tax, though. :-)

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2017-09-21 15:06 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (249 votes). Check out past polls.