Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

raw sockets

by Anonymous Monk
on May 06, 2014 at 09:48 UTC ( #1085154=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

sorry to bother you, here is my question:
how to receive packets using perl's SOCK_RAW
without anythying but only 'use Socket;'
So far I've got this.
socket RAW, AF_INET, SOCK_RAW, 255;
How do I tell which interface to use? (eth0 for example)
Is setsockopt for this?
I couldn't google it out. I really really tried.
But I've only seen that first you 'socket' then you 'recv', and that obviously can't work.
Thank you for your time and consideration.

Comment on raw sockets
Download Code
Re: raw sockets
by Anonymous Monk on May 06, 2014 at 10:07 UTC

    ... without anythying but only 'use Socket;' ...

    :) Why not do it without "use Socket"?

Re: raw sockets
by Anonymous Monk on May 06, 2014 at 11:17 UTC

    Perl's raw socket functions more or less mirror the underlying system calls. So when you're looking for documentation, you can Google something like "linux bind to interface", which would lead you to this Stack Overflow answer, which leads you to the SO_BINDTODEVICE option, which is documented in the socket(7) manpage.

    However, from what I can tell the SO_BINDTODEVICE is not available on all OSes, and it's also not available in the Socket module. See this thread for how you could hack it.

    On the other hand, why are you using the low-level functions, when there are higher-level modules such as IO::Socket and the Net:: family around? Also, I think it's much more common to bind your socket to a specific address instead of directly to an interface. Why do you need to bind to a specific interface?

      That was very helpful, thank you very much.
      I'm gonna carefully research all the links you've provided.
      "bind to interface" due to the bridging.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1085154]
Front-paged by Arunbear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (14)
As of 2014-07-28 16:43 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (204 votes), past polls