none
socket() fails when using SOCK_RAW in Win7 + VC++ 10 express

    Question

  • Hello

    I am porting a sockets library from linux to windows... it was successfully compiled using VC++ 10 express / Win7 and works fine, but the problem is when running the code for raw sockets, it compiles cleanly but the socket() function always returns error code when I use SOCK_RAW no matter what protocol is specified, even UDP or TCP fail.

    How can I know if it is a restriction on the system or a problem with the code?

    sock = socket(AF_INET, SOCK_RAW, IPPROTO_IP);

    sock = socket(AF_INET, SOCK_RAW, IPPROTO_TCP);

    sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP));

    sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

    All of them return error. I've tested with both AF_INET and PF_INET with the same result... What can be the problem? The code is correct, the winsock is successfully initialized, the right socket libraries are linked... but can't create a raw socket in any way :-/

    Any idea of what can be wrong? As far as I know, Win7 supports raw sockets with restrictions for TCP and UDP, but it does not work for any protocol.

    Thanks!

    Friday, August 10, 2012 7:22 AM

Answers

All replies