mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-02 13:24:12 +01:00
YunServer: added method to allow listening on localhost only
This commit is contained in:
parent
ad280d5d8b
commit
6fb6e63e99
@ -19,7 +19,7 @@
|
|||||||
#include <YunServer.h>
|
#include <YunServer.h>
|
||||||
|
|
||||||
YunServer::YunServer(uint16_t _p, BridgeClass &_b) :
|
YunServer::YunServer(uint16_t _p, BridgeClass &_b) :
|
||||||
bridge(_b), port(_p), listening(false) {
|
bridge(_b), port(_p), listening(false), useLocalhost(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void YunServer::begin() {
|
void YunServer::begin() {
|
||||||
@ -29,7 +29,10 @@ void YunServer::begin() {
|
|||||||
port & 0xFF
|
port & 0xFF
|
||||||
};
|
};
|
||||||
uint8_t res[1];
|
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);
|
listening = (res[0] == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +35,13 @@ public:
|
|||||||
|
|
||||||
virtual size_t write(uint8_t c) { /* TODO */ }
|
virtual size_t write(uint8_t c) { /* TODO */ }
|
||||||
|
|
||||||
|
void listenOnLocalhost() { useLocalhost = true; }
|
||||||
|
void noListenOnLocalhost() { useLocalhost = false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
bool listening;
|
bool listening;
|
||||||
|
bool useLocalhost;
|
||||||
BridgeClass &bridge;
|
BridgeClass &bridge;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user