mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-14 11:46:26 +00:00
Initial commit
This commit is contained in:
80
limelight-common/Handshake.cpp
Normal file
80
limelight-common/Handshake.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
#include "PlatformSockets.h"
|
||||
|
||||
const char HELLO [] = {
|
||||
0x07, 0x00, 0x00, 0x00,
|
||||
0x61, 0x6e, 0x64, 0x72,
|
||||
0x6f, 0x69, 0x64, 0x03,
|
||||
0x01, 0x00, 0x00
|
||||
};
|
||||
|
||||
const char PACKET2 [] = {
|
||||
0x01, 0x03, 0x02, 0x00,
|
||||
0x08, 0x00
|
||||
};
|
||||
|
||||
const char PACKET3 [] = {
|
||||
0x04, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
const char PACKET4 [] = {
|
||||
0x01, 0x01, 0x00, 0x0
|
||||
};
|
||||
|
||||
static int waitAndDiscardResponse(SOCKET sock) {
|
||||
char temp[256];
|
||||
return recv(sock, temp, sizeof(temp), 0);
|
||||
}
|
||||
|
||||
int performHandshake(IP_ADDRESS host) {
|
||||
SOCKET s;
|
||||
int err;
|
||||
|
||||
s = connectTcpSocket(host, 47991);
|
||||
if (s == INVALID_SOCKET) {
|
||||
return LastSocketError();
|
||||
}
|
||||
|
||||
err = send(s, HELLO, sizeof(HELLO), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = waitAndDiscardResponse(s);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = send(s, PACKET2, sizeof(PACKET2), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = waitAndDiscardResponse(s);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = send(s, PACKET3, sizeof(PACKET3), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = waitAndDiscardResponse(s);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
err = send(s, PACKET4, sizeof(PACKET4), 0);
|
||||
if (err == SOCKET_ERROR) {
|
||||
goto CleanupError;
|
||||
}
|
||||
|
||||
closesocket(s);
|
||||
return 0;
|
||||
|
||||
CleanupError:
|
||||
closesocket(s);
|
||||
return LastSocketError();
|
||||
}
|
||||
Reference in New Issue
Block a user