Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Probleme mit der Fkt. sendto()

Empfohlene Antworten

Veröffentlicht

Hallo,

ich haben folgende Funktion in meinem Programm:


bool WOL_WakeOn(LPCTSTR mac)

{

	UDP udp;

	udp.port_source      = htons(3333);

	udp.port_destination = htons(53);

	udp.length           = htons(8);

	udp.checksum         = 0;


	IPV4 ipv4;

	ipv4.ihl            = 5;

	ipv4.version        = 4;

	ipv4.tos            = 0;

	ipv4.length         = htons(20);

	ipv4.id             = (unsigned short)htonl(67);

	ipv4.offset         = 0;

	ipv4.ttl            = 100;

	ipv4.type           = 17;

	ipv4.ip_source      = inet_addr("255.255.255.255");

	ipv4.ip_destination = INADDR_BROADCAST;


	WSADATA wsa;

    WSAStartup(MAKEWORD(2,2),&wsa);

	SOCKET s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);


	int optval = 1;

	setsockopt(s, IPPROTO_IP, IP_HDRINCL, (char*)&optval, sizeof(optval));

	setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char*)&optval, sizeof(optval));


	optval   = 0xFF;

	DWORD cb = 0;

	unsigned char data[65535];

	for(int i = 0; i < 6; i++)

	{

		memcpy(data + cb, &optval, 1);

		cb ++;

	}


	for(int k = 0; k < 16; k++)

	{

		for(int i = 0; i < 17; i += 3)

		{	

			optval  = mac[i] >= 48 && mac[i] <= 57 ? mac[i] - 48 : mac[i] - 55;

			optval += mac[i + 1] >= 48 && mac[i + 1] <= 57 ? mac[i + 1] - 48 : mac[i + 1] - 55;

			memcpy(data + cb, &optval, 1);

			cb ++;

		}

	}


	unsigned char buf[65535];

	memcpy(buf,                              &ipv4, sizeof(IPV4));

	memcpy(buf + sizeof(IPV4),               &udp,  sizeof(UDP));

	memcpy(buf + sizeof(IPV4) + sizeof(UDP), &data, cb);

	int len = sizeof(IPV4) + sizeof(UDP) + cb;


    SOCKADDR_IN to;

	to.sin_family            = AF_INET;

	to.sin_addr.S_un.S_addr  = INADDR_BROADCAST;


	int n = sendto(s, (const char*)buf, len, 0, (const sockaddr*)&to, sizeof(SOCKADDR_IN));

	if (n == SOCKET_ERROR)

	{

                int e = WSAGetLastError();

		SAv4_Error(0, "FEHLER");

		// !!! FEHLER !!!

	}

	closesocket(s);

	WSACleanup();


	return n > 1;

}

ein paar Überprüfungen fehlen noch. Das Problem ist nun allerdings an der Stelle mit dem Kommentar "!!! FEHLER !!!". Ich erhalte nach dem Aufruf der Fkt. sendto den Fehler 10004: "Ein Blockierungsvorgang wurde durch einen Aufruf von WSACancelBlockingCall unterbrochen. "

Weiß vielleicht jemand warum ich den Fehler bekomme und wie ich das ändern kann.

RAW sockets? Evtl. XP SP2?

Unter XP SP2 sind einige Arten von RAW Sockets verboten, insbesondere solche, die beim Senden Absender-Adresse verfälschen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.