Enable and fix most C++ warnings

This commit is contained in:
Friedrich Schöller 2017-05-13 01:47:17 +02:00
parent 7991b11a15
commit 295f6b4051
6 changed files with 53 additions and 25 deletions

View File

@ -1,5 +1,6 @@
LDFLAGS = `sh osflags ld $(MODE)` LDFLAGS = `sh osflags ld $(MODE)`
CFLAGS = -c -g `sh osflags c $(MODE)` CFLAGS = -c -g `sh osflags c $(MODE)`
CPPFLAGS = -c -g -std=c++98 -pedantic -Wall -Wextra -Wno-sign-compare -Wno-missing-field-initializers `sh osflags c $(MODE)`
TUN_DEV_FILE = `sh osflags dev $(MODE)` TUN_DEV_FILE = `sh osflags dev $(MODE)`
GCC = gcc GCC = gcc
GPP = g++ GPP = g++
@ -19,40 +20,40 @@ hans: build/tun.o build/sha1.o build/main.o build/client.o build/server.o build/
$(GPP) -o hans build/tun.o build/sha1.o build/main.o build/client.o build/server.o build/auth.o build/worker.o build/time.o build/tun_dev.o build/echo.o build/exception.o build/utility.o $(LDFLAGS) $(GPP) -o hans build/tun.o build/sha1.o build/main.o build/client.o build/server.o build/auth.o build/worker.o build/time.o build/tun_dev.o build/echo.o build/exception.o build/utility.o $(LDFLAGS)
build/utility.o: src/utility.cpp src/utility.h build/utility.o: src/utility.cpp src/utility.h
$(GPP) -c src/utility.cpp -o $@ -o $@ $(CFLAGS) $(GPP) -c src/utility.cpp -o $@ -o $@ $(CPPFLAGS)
build/exception.o: src/exception.cpp src/exception.h build/exception.o: src/exception.cpp src/exception.h
$(GPP) -c src/exception.cpp -o $@ $(CFLAGS) $(GPP) -c src/exception.cpp -o $@ $(CPPFLAGS)
build/echo.o: src/echo.cpp src/echo.h src/exception.h build/echo.o: src/echo.cpp src/echo.h src/exception.h
$(GPP) -c src/echo.cpp -o $@ $(CFLAGS) $(GPP) -c src/echo.cpp -o $@ $(CPPFLAGS)
build/tun.o: src/tun.cpp src/tun.h src/exception.h src/utility.h src/tun_dev.h build/tun.o: src/tun.cpp src/tun.h src/exception.h src/utility.h src/tun_dev.h
$(GPP) -c src/tun.cpp -o $@ $(CFLAGS) $(GPP) -c src/tun.cpp -o $@ $(CPPFLAGS)
build/tun_dev.o: build/tun_dev.o:
$(GCC) -c $(TUN_DEV_FILE) -o build/tun_dev.o -o $@ $(CFLAGS) $(GCC) -c $(TUN_DEV_FILE) -o build/tun_dev.o -o $@ $(CFLAGS)
build/sha1.o: src/sha1.cpp src/sha1.h build/sha1.o: src/sha1.cpp src/sha1.h
$(GPP) -c src/sha1.cpp -o $@ $(CFLAGS) $(GPP) -c src/sha1.cpp -o $@ $(CPPFLAGS)
build/main.o: src/main.cpp src/client.h src/server.h src/exception.h src/worker.h src/auth.h src/time.h src/echo.h src/tun.h src/tun_dev.h build/main.o: src/main.cpp src/client.h src/server.h src/exception.h src/worker.h src/auth.h src/time.h src/echo.h src/tun.h src/tun_dev.h
$(GPP) -c src/main.cpp -o $@ $(CFLAGS) $(GPP) -c src/main.cpp -o $@ $(CPPFLAGS)
build/client.o: src/client.cpp src/client.h src/server.h src/exception.h src/config.h src/worker.h src/auth.h src/time.h src/echo.h src/tun.h src/tun_dev.h build/client.o: src/client.cpp src/client.h src/server.h src/exception.h src/config.h src/worker.h src/auth.h src/time.h src/echo.h src/tun.h src/tun_dev.h
$(GPP) -c src/client.cpp -o $@ $(CFLAGS) $(GPP) -c src/client.cpp -o $@ $(CPPFLAGS)
build/server.o: src/server.cpp src/server.h src/client.h src/utility.h src/config.h src/worker.h src/auth.h src/time.h src/echo.h src/tun.h src/tun_dev.h build/server.o: src/server.cpp src/server.h src/client.h src/utility.h src/config.h src/worker.h src/auth.h src/time.h src/echo.h src/tun.h src/tun_dev.h
$(GPP) -c src/server.cpp -o $@ $(CFLAGS) $(GPP) -c src/server.cpp -o $@ $(CPPFLAGS)
build/auth.o: src/auth.cpp src/auth.h src/sha1.h src/utility.h build/auth.o: src/auth.cpp src/auth.h src/sha1.h src/utility.h
$(GPP) -c src/auth.cpp -o $@ $(CFLAGS) $(GPP) -c src/auth.cpp -o $@ $(CPPFLAGS)
build/worker.o: src/worker.cpp src/worker.h src/tun.h src/exception.h src/time.h src/echo.h src/tun_dev.h src/config.h build/worker.o: src/worker.cpp src/worker.h src/tun.h src/exception.h src/time.h src/echo.h src/tun_dev.h src/config.h
$(GPP) -c src/worker.cpp -o $@ $(CFLAGS) $(GPP) -c src/worker.cpp -o $@ $(CPPFLAGS)
build/time.o: src/time.cpp src/time.h build/time.o: src/time.cpp src/time.h
$(GPP) -c src/time.cpp -o $@ $(CFLAGS) $(GPP) -c src/time.cpp -o $@ $(CPPFLAGS)
clean: clean:
rm -rf build hans rm -rf build hans

View File

@ -89,7 +89,7 @@ void Client::sendChallengeResponse(int dataLength)
setTimeout(5000); setTimeout(5000);
} }
bool Client::handleEchoData(const TunnelHeader &header, int dataLength, uint32_t realIp, bool reply, uint16_t id, uint16_t seq) bool Client::handleEchoData(const TunnelHeader &header, int dataLength, uint32_t realIp, bool reply, uint16_t, uint16_t)
{ {
if (realIp != serverIp || !reply) if (realIp != serverIp || !reply)
return false; return false;
@ -208,7 +208,7 @@ void Client::handleDataFromServer(int dataLength)
sendEchoToServer(TunnelHeader::TYPE_POLL, 0); sendEchoToServer(TunnelHeader::TYPE_POLL, 0);
} }
void Client::handleTunData(int dataLength, uint32_t sourceIp, uint32_t destIp) void Client::handleTunData(int dataLength, uint32_t, uint32_t)
{ {
if (state != STATE_ESTABLISHED) if (state != STATE_ESTABLISHED)
return; return;

View File

@ -24,5 +24,5 @@
#define CHALLENGE_SIZE 20 #define CHALLENGE_SIZE 20
//#define DEBUG_ONLY(a) a // #define DEBUG_ONLY(a) a
#define DEBUG_ONLY(a) #define DEBUG_ONLY(a)

View File

@ -25,6 +25,7 @@
#include <string.h> #include <string.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <syslog.h> #include <syslog.h>
#include <stdio.h>
using namespace std; using namespace std;
@ -223,7 +224,7 @@ Server::ClientData *Server::getClientByRealIp(uint32_t ip)
return &*it->second; return &*it->second;
} }
void Server::handleTunData(int dataLength, uint32_t sourceIp, uint32_t destIp) void Server::handleTunData(int dataLength, uint32_t, uint32_t destIp)
{ {
if (destIp == network + 255) // ignore broadcasts if (destIp == network + 255) // ignore broadcasts
return; return;
@ -246,7 +247,7 @@ void Server::pollReceived(ClientData *client, uint16_t echoId, uint16_t echoSeq)
client->pollIds.push(ClientData::EchoId(echoId, echoSeq)); client->pollIds.push(ClientData::EchoId(echoId, echoSeq));
if (client->pollIds.size() > maxSavedPolls) if (client->pollIds.size() > maxSavedPolls)
client->pollIds.pop(); client->pollIds.pop();
DEBUG_ONLY(printf("poll -> %d\n", client->pollIds.size())); DEBUG_ONLY(printf("poll -> %d\n", (int)client->pollIds.size()));
if (client->pendingPackets.size() > 0) if (client->pendingPackets.size() > 0)
{ {
@ -254,7 +255,7 @@ void Server::pollReceived(ClientData *client, uint16_t echoId, uint16_t echoSeq)
memcpy(echoSendPayloadBuffer(), &packet.data[0], packet.data.size()); memcpy(echoSendPayloadBuffer(), &packet.data[0], packet.data.size());
client->pendingPackets.pop(); client->pendingPackets.pop();
DEBUG_ONLY(printf("pending packet: %d bytes\n", packet.data.size())); DEBUG_ONLY(printf("pending packet: %d bytes\n", (int)packet.data.size()));
sendEchoToClient(client, packet.type, packet.data.size()); sendEchoToClient(client, packet.type, packet.data.size());
} }
@ -274,7 +275,7 @@ void Server::sendEchoToClient(ClientData *client, int type, int dataLength)
ClientData::EchoId echoId = client->pollIds.front(); ClientData::EchoId echoId = client->pollIds.front();
client->pollIds.pop(); client->pollIds.pop();
DEBUG_ONLY(printf("sending -> %d\n", client->pollIds.size())); DEBUG_ONLY(printf("sending -> %d\n", (int)client->pollIds.size()));
sendEcho(magic, type, dataLength, client->realIp, true, echoId.id, echoId.seq); sendEcho(magic, type, dataLength, client->realIp, true, echoId.id, echoId.seq);
return; return;
} }

View File

@ -28,6 +28,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/select.h> #include <sys/select.h>
#include <grp.h> #include <grp.h>
#include <stdio.h>
using namespace std; using namespace std;
@ -160,7 +161,10 @@ void Worker::run()
{ {
TunnelHeader *header = (TunnelHeader *)echo->receivePayloadBuffer(); TunnelHeader *header = (TunnelHeader *)echo->receivePayloadBuffer();
DEBUG_ONLY(printf("received: type %d, length %d, id %d, seq %d\n", header->type, dataLength - sizeof(TunnelHeader), id, seq)); DEBUG_ONLY(
printf("received: type %d, length %d, id %d, seq %d\n",
header->type, (int)(dataLength - sizeof(TunnelHeader)),
id, seq));
valid = handleEchoData(*header, dataLength - sizeof(TunnelHeader), ip, reply, id, seq); valid = handleEchoData(*header, dataLength - sizeof(TunnelHeader), ip, reply, id, seq);
} }
@ -216,3 +220,22 @@ void Worker::dropPrivileges()
privilegesDropped = true; privilegesDropped = true;
#endif #endif
} }
bool Worker::handleEchoData(const TunnelHeader &, int, uint32_t, bool, uint16_t, uint16_t)
{
return true;
}
void Worker::handleTunData(int, uint32_t, uint32_t) { }
void Worker::handleTimeout() { }
char *Worker::echoSendPayloadBuffer()
{
return echo->sendPayloadBuffer() + sizeof(TunnelHeader);
}
char *Worker::echoReceivePayloadBuffer()
{
return echo->receivePayloadBuffer() + sizeof(TunnelHeader);
}

View File

@ -69,17 +69,20 @@ protected:
}; };
}; // size = 5 }; // size = 5
virtual bool handleEchoData(const TunnelHeader &header, int dataLength, uint32_t realIp, bool reply, uint16_t id, uint16_t seq) { return true; } virtual bool handleEchoData(const TunnelHeader &header, int dataLength,
virtual void handleTunData(int dataLength, uint32_t sourceIp, uint32_t destIp) { } // to echoSendPayloadBuffer uint32_t realIp, bool reply, uint16_t id, uint16_t seq);
virtual void handleTimeout() { } virtual void handleTunData(int dataLength, uint32_t sourceIp,
uint32_t destIp); // to echoSendPayloadBuffer
virtual void handleTimeout();
void sendEcho(const TunnelHeader::Magic &magic, int type, int length, uint32_t realIp, bool reply, uint16_t id, uint16_t seq); void sendEcho(const TunnelHeader::Magic &magic, int type, int length,
uint32_t realIp, bool reply, uint16_t id, uint16_t seq);
void sendToTun(int length); // from echoReceivePayloadBuffer void sendToTun(int length); // from echoReceivePayloadBuffer
void setTimeout(Time delta); void setTimeout(Time delta);
char *echoSendPayloadBuffer() { return echo->sendPayloadBuffer() + sizeof(TunnelHeader); } char *echoSendPayloadBuffer();
char *echoReceivePayloadBuffer() { return echo->receivePayloadBuffer() + sizeof(TunnelHeader); } char *echoReceivePayloadBuffer();
int payloadBufferSize() { return tunnelMtu; } int payloadBufferSize() { return tunnelMtu; }