From 4ff57a3bd643d7e3bb2e3389883b9b4a8abdd7df Mon Sep 17 00:00:00 2001 From: CTurt Date: Mon, 29 Dec 2014 11:28:16 +0000 Subject: [PATCH] Packet changes --- 3DS/source/wireless.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/3DS/source/wireless.c b/3DS/source/wireless.c index 3502203..76146e8 100644 --- a/3DS/source/wireless.c +++ b/3DS/source/wireless.c @@ -1,3 +1,5 @@ +#include + #include "keyboard.h" #include "wireless.h" @@ -6,6 +8,8 @@ int sock; struct sockaddr_in sain, saout; struct packet outBuf, rcvBuf; +socklen_t sockaddr_in_sizePtr = (int)sizeof(struct sockaddr_in); + bool openSocket(int port) { sock = socket(AF_INET, SOCK_DGRAM, 0); @@ -24,10 +28,14 @@ void sendBuf(int length) { sendto(sock, (char *)&outBuf, length, 0, (struct sockaddr *)&saout, sizeof(saout)); } +int receiveBuffer(int length) { + return recvfrom(sock, (char *)&rcvBuf, length, 0, (struct sockaddr *)&sain, &sockaddr_in_sizePtr); +} + void sendConnectionRequest(void) { outBuf.command = CONNECT; outBuf.keyboardActive = keyboardActive; - sendBuf(1); + sendBuf(offsetof(struct packet, connectPacket) + sizeof(struct connectPacket)); } void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch) { @@ -36,5 +44,5 @@ void sendKeys(unsigned int keys, circlePosition circlePad, touchPosition touch) memcpy(&outBuf.keys, &keys, 4); memcpy(&outBuf.circlePad, &circlePad, 4); memcpy(&outBuf.touch, &touch, 4); - sendBuf(sizeof(struct packet)); + sendBuf(offsetof(struct packet, keysPacket) + sizeof(struct keysPacket)); }