Log messages on packet reception

This commit is contained in:
Théophile Bastian 2016-11-24 15:41:34 +01:00
parent 18741af602
commit 750f9e3672

View file

@ -163,7 +163,6 @@ void Protocol::pollNetwork() {
struct sockaddr* fromAddr = (struct sockaddr*)&fromAddr6;
socklen_t fromAddrLen;
while(!terminating) {
//TODO is it blocking?
ssize_t readDat = recvfrom(sock, buffer, MAX_MTU, 0,
fromAddr, &fromAddrLen);
if(readDat <= 0)
@ -172,21 +171,21 @@ void Protocol::pollNetwork() {
u8 magic, version;
data >> magic >> version;
if(magic != csts::MAGIC) {
//TODO log
fprintf(stderr, "[WARNING] Bad magic byte %u\n", magic);
continue;
}
if(version != csts::VERSION) {
//TODO log
fprintf(stderr, "[WARNING] Bad version %d\n", version);
continue;
}
u16 bodyLen;
data >> bodyLen;
if(data.size() < bodyLen + 64u) {
//TODO log bad length
fprintf(stderr, "[WARNING] Body too short\n");
continue;
}
else if(data.size() != bodyLen + 64u) {
//TODO log warning bad length
fprintf(stderr, "[WARNING] Body too long\n");
}
SockAddr convFromAddr;