mirror of
https://github.com/taigrr/tplinkController
synced 2025-01-18 04:43:13 -08:00
Style fussing
This commit is contained in:
parent
4be0d86405
commit
80581e5c9c
18
comms.c
18
comms.c
@ -1,16 +1,16 @@
|
|||||||
#include <stddef.h>
|
#include <arpa/inet.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <arpa/inet.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
|
|
||||||
bool hs100_encrypt(uint8_t *d, uint8_t *s, size_t len)
|
bool hs100_encrypt(uint8_t *d, uint8_t *s, size_t len)
|
||||||
{
|
{
|
||||||
if( d == NULL)
|
if (d == NULL)
|
||||||
return false;
|
return false;
|
||||||
if (s == NULL)
|
if (s == NULL)
|
||||||
return false;
|
return false;
|
||||||
@ -36,7 +36,7 @@ bool hs100_decrypt(uint8_t *d, uint8_t *s, size_t len)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint8_t key = 0xab;
|
uint8_t key = 0xab;
|
||||||
for(size_t i=0; i<len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
uint8_t temp = key ^ s[i];
|
uint8_t temp = key ^ s[i];
|
||||||
key = s[i];
|
key = s[i];
|
||||||
d[i] = temp;
|
d[i] = temp;
|
||||||
@ -81,7 +81,7 @@ char *hs100_decode(uint8_t *s, size_t s_len)
|
|||||||
|
|
||||||
char *outbuf = calloc(1, in_s_len + 1);
|
char *outbuf = calloc(1, in_s_len + 1);
|
||||||
|
|
||||||
if (!hs100_decrypt((uint8_t*) outbuf, s + 4, in_s_len)) {
|
if (!hs100_decrypt((uint8_t *) outbuf, s + 4, in_s_len)) {
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -116,15 +116,15 @@ char *hs100_send(char *servaddr, char *msg)
|
|||||||
send(sock, s, s_len, 0);
|
send(sock, s, s_len, 0);
|
||||||
free(s);
|
free(s);
|
||||||
uint32_t msglen;
|
uint32_t msglen;
|
||||||
size_t recvsize = recv (sock, &msglen, sizeof(msglen), MSG_PEEK);
|
size_t recvsize = recv(sock, &msglen, sizeof(msglen), MSG_PEEK);
|
||||||
if (recvsize != sizeof(msglen)) {
|
if (recvsize != sizeof(msglen)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
msglen = ntohl(msglen) + 4;
|
msglen = ntohl(msglen) + 4;
|
||||||
uint8_t *recvbuf = calloc(1, (size_t)msglen);
|
uint8_t *recvbuf = calloc(1, (size_t) msglen);
|
||||||
recvsize = recv(sock, recvbuf, msglen, MSG_WAITALL);
|
recvsize = recv(sock, recvbuf, msglen, MSG_WAITALL);
|
||||||
close(sock);
|
close(sock);
|
||||||
char *recvmsg = hs100_decode(recvbuf, msglen);
|
char *recvmsg = hs100_decode(recvbuf, msglen);
|
||||||
free (recvbuf);
|
free(recvbuf);
|
||||||
return recvmsg;
|
return recvmsg;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
|
||||||
#include "comms.h"
|
#include "comms.h"
|
||||||
|
|
||||||
char *handler_associate(int argc, char *argv[])
|
char *handler_associate(int argc, char *argv[])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user