mirror of https://github.com/mgba-emu/mgba.git
Add function for connecting to an already-open TCP port
This commit is contained in:
parent
4d8a00c180
commit
8e51ffbf2c
|
@ -52,6 +52,27 @@ static inline Socket SocketOpenTCP(int port, uint32_t bindAddress) {
|
|||
return sock;
|
||||
}
|
||||
|
||||
static inline Socket SocketConnectTCP(int port, uint32_t destinationAddress) {
|
||||
Socket sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
if (sock < 0) {
|
||||
return sock;
|
||||
}
|
||||
|
||||
struct sockaddr_in bindInfo = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = htons(port),
|
||||
.sin_addr = {
|
||||
.s_addr = htonl(destinationAddress)
|
||||
}
|
||||
};
|
||||
int err = connect(sock, (const struct sockaddr*) &bindInfo, sizeof(struct sockaddr_in));
|
||||
if (err) {
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
return sock;
|
||||
}
|
||||
|
||||
static inline Socket SocketListen(Socket socket, int queueLength) {
|
||||
return listen(socket, queueLength);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue