mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-10-30 08:01:01 +00:00
Due to my compile & launch scripts, I was silently ignoring warnings this whole time. I've fixed my process, and gone back to fixed all of the warnings I could (even outside of my code).
44 lines
1.4 KiB
C
44 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include "socket.h"
|
|
#include "../network.h"
|
|
|
|
int socket_bind(SOCKET sock, unsigned int port) {
|
|
struct sockaddr_in rxAddr;
|
|
rxAddr.sin_family = AF_INET;
|
|
rxAddr.sin_port = htons(port);
|
|
rxAddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
|
|
int rc = bind(sock, (SOCKADDR*)&rxAddr, sizeof(rxAddr));
|
|
if (rc != 0) {
|
|
printf("%s bind failed with error %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR);
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
int socket_send(SOCKET sock, struct sockaddr_in* txAddr, char* buffer, int bufferLength) {
|
|
int txAddrSize = sizeof(struct sockaddr_in);
|
|
int rc = sendto(sock, buffer, bufferLength, 0, (struct sockaddr*)txAddr, txAddrSize);
|
|
if (rc == SOCKET_ERROR) {
|
|
printf("%s sendto failed with error: %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR);
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
int socket_receive(SOCKET sock, struct sockaddr_in* rxAddr, char* buffer, int bufferLength, int* receiveLength) {
|
|
*receiveLength = 0;
|
|
|
|
int rxAddrSize = sizeof(struct sockaddr_in);
|
|
int rc = recvfrom(sock, buffer, bufferLength, 0, (struct sockaddr*)rxAddr, &rxAddrSize);
|
|
if (rc == SOCKET_ERROR) {
|
|
int error = SOCKET_LAST_ERROR;
|
|
if (error != SOCKET_EWOULDBLOCK && error != SOCKET_ECONNRESET) {
|
|
printf("%s recvfrom failed with error %d\n", NETWORKTYPESTR, SOCKET_LAST_ERROR);
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
*receiveLength = rc;
|
|
return NO_ERROR;
|
|
}
|