Skip to content

Commit 6fb6e63

Browse files
committed
YunServer: added method to allow listening on localhost only
1 parent ad280d5 commit 6fb6e63

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

hardware/arduino/avr/libraries/Bridge/YunServer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <YunServer.h>
2020

2121
YunServer::YunServer(uint16_t _p, BridgeClass &_b) :
22-
bridge(_b), port(_p), listening(false) {
22+
bridge(_b), port(_p), listening(false), useLocalhost(false) {
2323
}
2424

2525
void YunServer::begin() {
@@ -29,7 +29,10 @@ void YunServer::begin() {
2929
port & 0xFF
3030
};
3131
uint8_t res[1];
32-
bridge.transfer(tmp, 3, (const uint8_t *)"0.0.0.0", 7, res, 1);
32+
String address = F("127.0.0.1");
33+
if (!useLocalhost)
34+
address = F("0.0.0.0");
35+
bridge.transfer(tmp, 3, (const uint8_t *)address.c_str(), address.length(), res, 1);
3336
listening = (res[0] == 1);
3437
}
3538

hardware/arduino/avr/libraries/Bridge/YunServer.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ class YunServer : public Server {
3535

3636
virtual size_t write(uint8_t c) { /* TODO */ }
3737

38+
void listenOnLocalhost() { useLocalhost = true; }
39+
void noListenOnLocalhost() { useLocalhost = false; }
40+
3841
private:
3942
uint16_t port;
4043
bool listening;
44+
bool useLocalhost;
4145
BridgeClass &bridge;
4246
};
4347

0 commit comments

Comments
 (0)