1
0
mirror of https://github.com/CPunch/Laika.git synced 2026-01-27 12:20:08 +00:00

Refactored LAIKAPKT_HANDSHAKE_REQ, laikaS_acceptFrom

- added inet member to peer structs
This commit is contained in:
2022-03-04 20:17:03 -06:00
parent 12a1329101
commit 0c2d4968d9
11 changed files with 59 additions and 36 deletions

View File

@@ -17,7 +17,9 @@ struct sLaika_peer *laikaS_newPeer(struct sLaika_peerPacketInfo *pktTbl, struct
peer->inStart = -1;
peer->useSecure = false;
/* zero-out peer info */
memset(peer->hostname, 0, LAIKA_HOSTNAME_LEN);
memset(peer->inet, 0, LAIKA_INET_LEN);
memset(peer->ipv4, 0, LAIKA_IPV4_LEN);
return peer;
}

View File

@@ -148,13 +148,22 @@ void laikaS_bind(struct sLaika_socket *sock, uint16_t port) {
LAIKA_ERROR("listen() failed!\n");
}
void laikaS_acceptFrom(struct sLaika_socket *sock, struct sLaika_socket *from) {
void laikaS_acceptFrom(struct sLaika_socket *sock, struct sLaika_socket *from, char *ipv4) {
socklen_t addressSize;
struct sockaddr address;
struct sockaddr_in address;
sock->sock = accept(from->sock, &address, &addressSize);
sock->sock = accept(from->sock, (struct sockaddr*)&address, &addressSize);
if (SOCKETINVALID(sock->sock))
LAIKA_ERROR("accept() failed!\n");
/* read ipv4 */
if (ipv4 != NULL) {
if (inet_ntop(AF_INET, &address, ipv4, LAIKA_IPV4_LEN) == NULL)
LAIKA_ERROR("inet_ntop() failed!\n");
/* restore null terminator */
ipv4[LAIKA_INET_LEN-1] = '\0';
}
}
bool laikaS_setNonBlock(struct sLaika_socket *sock) {