From 295f6b4051e7b4f902a1018f702514ff8344ec1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Friedrich=20Scho=CC=88ller?= Date: Sat, 13 May 2017 01:47:17 +0200 Subject: [PATCH] Enable and fix most C++ warnings --- Makefile | 23 ++++++++++++----------- src/client.cpp | 4 ++-- src/config.h | 2 +- src/server.cpp | 9 +++++---- src/worker.cpp | 25 ++++++++++++++++++++++++- src/worker.h | 15 +++++++++------ 6 files changed, 53 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 41d5710..332f3d4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ LDFLAGS = `sh osflags ld $(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)` GCC = gcc 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) 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 - $(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 - $(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 - $(GPP) -c src/tun.cpp -o $@ $(CFLAGS) + $(GPP) -c src/tun.cpp -o $@ $(CPPFLAGS) build/tun_dev.o: $(GCC) -c $(TUN_DEV_FILE) -o build/tun_dev.o -o $@ $(CFLAGS) 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 - $(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 - $(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 - $(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 - $(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 - $(GPP) -c src/worker.cpp -o $@ $(CFLAGS) + $(GPP) -c src/worker.cpp -o $@ $(CPPFLAGS) build/time.o: src/time.cpp src/time.h - $(GPP) -c src/time.cpp -o $@ $(CFLAGS) + $(GPP) -c src/time.cpp -o $@ $(CPPFLAGS) clean: rm -rf build hans diff --git a/src/client.cpp b/src/client.cpp index cdc0a94..4c7955a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -89,7 +89,7 @@ void Client::sendChallengeResponse(int dataLength) 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) return false; @@ -208,7 +208,7 @@ void Client::handleDataFromServer(int dataLength) 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) return; diff --git a/src/config.h b/src/config.h index 7d5d6c8..d44a991 100644 --- a/src/config.h +++ b/src/config.h @@ -24,5 +24,5 @@ #define CHALLENGE_SIZE 20 -//#define DEBUG_ONLY(a) a +// #define DEBUG_ONLY(a) a #define DEBUG_ONLY(a) diff --git a/src/server.cpp b/src/server.cpp index 62c7c6c..af95ebb 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace std; @@ -223,7 +224,7 @@ Server::ClientData *Server::getClientByRealIp(uint32_t ip) 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 return; @@ -246,7 +247,7 @@ void Server::pollReceived(ClientData *client, uint16_t echoId, uint16_t echoSeq) client->pollIds.push(ClientData::EchoId(echoId, echoSeq)); if (client->pollIds.size() > maxSavedPolls) 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) { @@ -254,7 +255,7 @@ void Server::pollReceived(ClientData *client, uint16_t echoId, uint16_t echoSeq) memcpy(echoSendPayloadBuffer(), &packet.data[0], packet.data.size()); 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()); } @@ -274,7 +275,7 @@ void Server::sendEchoToClient(ClientData *client, int type, int dataLength) ClientData::EchoId echoId = client->pollIds.front(); 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); return; } diff --git a/src/worker.cpp b/src/worker.cpp index d0b7d20..3cdce79 100644 --- a/src/worker.cpp +++ b/src/worker.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using namespace std; @@ -160,7 +161,10 @@ void Worker::run() { 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); } @@ -216,3 +220,22 @@ void Worker::dropPrivileges() privilegesDropped = true; #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); +} diff --git a/src/worker.h b/src/worker.h index 146aca9..a1f11e7 100644 --- a/src/worker.h +++ b/src/worker.h @@ -69,17 +69,20 @@ protected: }; }; // size = 5 - virtual bool handleEchoData(const TunnelHeader &header, int dataLength, uint32_t realIp, bool reply, uint16_t id, uint16_t seq) { return true; } - virtual void handleTunData(int dataLength, uint32_t sourceIp, uint32_t destIp) { } // to echoSendPayloadBuffer - virtual void handleTimeout() { } + virtual bool handleEchoData(const TunnelHeader &header, int dataLength, + uint32_t realIp, bool reply, uint16_t id, uint16_t seq); + 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 setTimeout(Time delta); - char *echoSendPayloadBuffer() { return echo->sendPayloadBuffer() + sizeof(TunnelHeader); } - char *echoReceivePayloadBuffer() { return echo->receivePayloadBuffer() + sizeof(TunnelHeader); } + char *echoSendPayloadBuffer(); + char *echoReceivePayloadBuffer(); int payloadBufferSize() { return tunnelMtu; }