From ef0f1e593f7af6463642154ec1eb675e1231cb45 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 1 Jul 2013 19:09:43 +0200 Subject: YunServer: added method to allow listening on localhost only --- libraries/Bridge/YunServer.cpp | 7 +++++-- libraries/Bridge/YunServer.h | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'libraries') diff --git a/libraries/Bridge/YunServer.cpp b/libraries/Bridge/YunServer.cpp index c6d54e4..c0ed88c 100644 --- a/libraries/Bridge/YunServer.cpp +++ b/libraries/Bridge/YunServer.cpp @@ -19,7 +19,7 @@ #include YunServer::YunServer(uint16_t _p, BridgeClass &_b) : - bridge(_b), port(_p), listening(false) { + bridge(_b), port(_p), listening(false), useLocalhost(false) { } void YunServer::begin() { @@ -29,7 +29,10 @@ void YunServer::begin() { port & 0xFF }; uint8_t res[1]; - bridge.transfer(tmp, 3, (const uint8_t *)"0.0.0.0", 7, res, 1); + String address = F("127.0.0.1"); + if (!useLocalhost) + address = F("0.0.0.0"); + bridge.transfer(tmp, 3, (const uint8_t *)address.c_str(), address.length(), res, 1); listening = (res[0] == 1); } diff --git a/libraries/Bridge/YunServer.h b/libraries/Bridge/YunServer.h index e1be55a..eb16703 100644 --- a/libraries/Bridge/YunServer.h +++ b/libraries/Bridge/YunServer.h @@ -35,9 +35,13 @@ public: virtual size_t write(uint8_t c) { /* TODO */ } + void listenOnLocalhost() { useLocalhost = true; } + void noListenOnLocalhost() { useLocalhost = false; } + private: uint16_t port; bool listening; + bool useLocalhost; BridgeClass &bridge; }; -- cgit v1.2.3-18-g5258