Raw Sockets ab Windows XP SP 2 gesperrt?
-
Hallo,
wollte mich jetzt mal demnächst mit Raw Sockets befassen.
Jetzt habe ich mehrmals gelesen das man die Raw Sockets ab Windows XP Service Pack 2 nicht mehr benutzen kann.
Stimmt das?
-
In der Vista SDK steht "Support for sockets with type SOCK_RAW is not required, but service providers are encouraged to support raw sockets as practicable."
Also kann sein muß aber nicht.
-
msdn schrieb:
Limitations on Raw Sockets
On Windows 7, Windows Server 2008 R2, Windows Vista, and Windows XP with Service Pack 2 (SP2), the ability to send traffic over raw sockets has been restricted in several ways:
* TCP data cannot be sent over raw sockets.
* UDP datagrams with an invalid source address cannot be sent over raw sockets. The IP source address for any outgoing UDP datagram must exist on a network interface or the datagram is dropped. This change was made to limit the ability of malicious code to create distributed denial-of-service attacks and limits the ability to send spoofed packets (TCP/IP packets with a forged source IP address).
* A call to the bind function with a raw socket is not allowed.These above restrictions do not apply to Windows Server 2008 , Windows Server 2003, or to versions of the operating system earlier than Windows XP with SP2.
Note The Microsoft implementation of TCP/IP on Windows is capable of opening a raw UDP or TCP socket based on the above restrictions. But other Winsock providers may not support the use of raw sockets.
Vermeide Raw-Sockets einfach
Fürs Pingen gibts ne extra API:
http://msdn.microsoft.com/en-us/library/aa366050(VS.85).aspx
-
Fürs Pingen gibts ne extra API:
http://msdn.microsoft.com/en-us/library/aa366050(VS.85).aspxJa eigentlich wollte ich mich nur mit den Raw Sockets beschäftigen wegen ner Ping Funktion.
Habe jetzt aber mal den Bsp Code benutzt und wenn ich ein Ping an Google senden will erhalte ich immer folgende Ausgabe:Call to IcmpSendEcho failed.
IcmpSendEcho returned error: 11050Aber warum geht der Bsp. Code auch nicht?
-
Zeig mal deinen Code
-
Du kannst weiterhin Raw Sockets benutzen. Es gibt keine Probleme, wenn Du "lieb" bist... bist Du hingegen "böse", so wurden einige Riegel vorgeschoben...
Du kannst also weiterhin einen PING via Raw-Sockets schreiben... das geht ohne Probleme...
-
Zeig mal deinen Code
#include <winsock2.h> #include <iphlpapi.h> #include <icmpapi.h> #include <stdio.h> #pragma comment(lib, "iphlpapi.lib") #pragma comment(lib, "ws2_32.lib") int __cdecl main(int argc, char **argv) { // Declare and initialize variables HANDLE hIcmpFile; unsigned long ipaddr = INADDR_NONE; DWORD dwRetVal = 0; char SendData[] = "Data Buffer"; LPVOID ReplyBuffer = NULL; DWORD ReplySize = 0; // Validate the parameters if (argc != 2) { printf("usage: %s IP address\n", argv[0]); return 1; } ipaddr = inet_addr(argv[1]); if (ipaddr == INADDR_NONE) { printf("usage: %s IP address\n", argv[0]); return 1; } hIcmpFile = IcmpCreateFile(); if (hIcmpFile == INVALID_HANDLE_VALUE) { printf("\tUnable to open handle.\n"); printf("IcmpCreatefile returned error: %ld\n", GetLastError() ); return 1; } ReplySize = sizeof(ICMP_ECHO_REPLY) + sizeof(SendData); ReplyBuffer = (VOID*) malloc(ReplySize); if (ReplyBuffer == NULL) { printf("\tUnable to allocate memory\n"); return 1; } dwRetVal = IcmpSendEcho(hIcmpFile, ipaddr, SendData, sizeof(SendData), NULL, ReplyBuffer, ReplySize, 1000); if (dwRetVal != 0) { PICMP_ECHO_REPLY pEchoReply = (PICMP_ECHO_REPLY)ReplyBuffer; struct in_addr ReplyAddr; ReplyAddr.S_un.S_addr = pEchoReply->Address; printf("\tSent icmp message to %s\n", argv[1]); if (dwRetVal > 1) { printf("\tReceived %ld icmp message responses\n", dwRetVal); printf("\tInformation from the first response:\n"); } else { printf("\tReceived %ld icmp message response\n", dwRetVal); printf("\tInformation from this response:\n"); } printf("\t Received from %s\n", inet_ntoa( ReplyAddr ) ); printf("\t Status = %ld\n", pEchoReply->Status); printf("\t Roundtrip time = %ld milliseconds\n", pEchoReply->RoundTripTime); } else { printf("\tCall to IcmpSendEcho failed.\n"); printf("\tIcmpSendEcho returned error: %ld\n", GetLastError() ); return 1; } return 0; }
Du kannst also weiterhin einen PING via Raw-Sockets schreiben... das geht ohne Probleme...
Ok gut zu wissen,dann beschäftige ich mich doch mal mit den Raw-Sockets.
-
Da scheint Microsofts Beispielcode und die Doku wohl fehlerhaft zu sein
Wenn man den Text hier etwas länger macht...char SendData[] = "Data Buffer";
...verschwindet der Fehler. Scheinbar muss SendData ne bestimmte Mindestgröße haben?
Außerdem ist wie dort auch jemand schreibt ein IcmpCloseHandle()