mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2026-04-13 03:06:10 +00:00
Initial commit
This commit is contained in:
22
limelight-common/PlatformSockets.cpp
Normal file
22
limelight-common/PlatformSockets.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "PlatformSockets.h"
|
||||
|
||||
SOCKET connectTcpSocket(IP_ADDRESS dstaddr, unsigned short port) {
|
||||
SOCKET s;
|
||||
struct sockaddr_in addr;
|
||||
|
||||
s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (s == INVALID_SOCKET) {
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
memcpy(&addr.sin_addr, &dstaddr, sizeof(dstaddr));
|
||||
if (connect(s, (struct sockaddr*) &addr, sizeof(addr)) == SOCKET_ERROR) {
|
||||
closesocket(s);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
Reference in New Issue
Block a user