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

I'm trying to have a server which takes the packets it receives from a client and processes them. I need to be able to view the entire tcp packet, not just the data contained in the inner layer. I can do this with pcap, but since the server already has Socket being used, and I want to try to minimize the number of required packages, doing the same with Socket would be great.

Replies are listed 'Best First'.
Re: Using socket instead of pcap
by NetWallah (Canon) on May 07, 2010 at 04:53 UTC
    Sockets are interfaces between applications (Layer 5 and above) and the transport (Layer 4) - See the OSI Model reference at Wikipedea.

    pcap and friends capture and analyze packets at layer 2 and above.

    I'm hoping that is enough said - case closed.

         Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Re: Using socket instead of pcap
by MediocreGopher (Initiate) on May 07, 2010 at 01:47 UTC

    ....wow, ok. What I was asking was whether it was possible, not for someone to write the code for me, but upon re-reading my OP I guess that wasn't as clear as I thought it was. I tried to find examples online of how to do it but couldn't find any that didn't use pcap. And I didn't post any code because I don't have any, beyond creating the Socket object and binding it to a port.

      I suppose it might be theoretically possible to write a pure Perl replacement for libpcap. Of course, you'd have to know all the intimate details of network protocols and *nix and even then you would likely find that your Perl ran too slow to be useful in real time analysis of busy networks. So, you profile and find the slow parts which you convert to XS aka C and when you're done, you'll probably find that you've recreated a vastly inferior version of libpcap.

      If you know the protocols, OS details and Perl well enough to pull this off, you should already know the answer to this question. Use libpcap and enjoy standing on the shoulders of giants.

Re: Using socket instead of pcap
by MediocreGopher (Initiate) on May 07, 2010 at 05:33 UTC
    Alright, thanks everyone for the responses. I'll make do with not doing more work then
Re: Using socket instead of pcap
by ww (Archbishop) on May 07, 2010 at 00:58 UTC

    Why, yes! Gosh, golly gee; it sure would!

    So have you written code which does so?

    Or did you really intend to ask "Will you -- pretty please with sugar on it -- do the work for me?"

    If so, I'd suggest reading On asking for help and How do I post a question effectively?, putting together some code, and then improving this thread by posting code, along with a description of how it fails to do your job and the verbatim error messages (if any).

    Bottom line: we're here to help you learn; not to do the job for you.