-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Log incoming client IP addresses for API connections #9721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,7 +26,8 @@ void deInitApiServer() | |||||||||||||||||||
| WiFiServerAPI::WiFiServerAPI(WiFiClient &_client) : ServerAPI(_client) | ||||||||||||||||||||
| { | ||||||||||||||||||||
| api_type = TYPE_WIFI; | ||||||||||||||||||||
| LOG_INFO("Incoming wifi connection"); | ||||||||||||||||||||
| auto ip = _client.remoteIP(); | ||||||||||||||||||||
| LOG_INFO("Incoming wifi connection from %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); | ||||||||||||||||||||
|
Comment on lines
+29
to
+30
|
||||||||||||||||||||
| auto ip = _client.remoteIP(); | |
| LOG_INFO("Incoming wifi connection from %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); | |
| auto ip = _client.remoteIP(); | |
| #ifdef ARCH_PORTDUINO | |
| // ARCH_PORTDUINO may not support IPv6 or IPAddress::toString(), so use octet formatting. | |
| LOG_INFO("Incoming wifi connection from %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); | |
| #else | |
| LOG_INFO("Incoming wifi connection from %s", ip.toString().c_str()); | |
| #endif |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,8 @@ void initApiServer(int port) | |||||
|
|
||||||
| ethServerAPI::ethServerAPI(EthernetClient &_client) : ServerAPI(_client) | ||||||
| { | ||||||
| LOG_INFO("Incoming ethernet connection"); | ||||||
| auto ip = _client.remoteIP(); | ||||||
| LOG_INFO("Incoming ethernet connection from %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); | ||||||
|
||||||
| LOG_INFO("Incoming ethernet connection from %u.%u.%u.%u", ip[0], ip[1], ip[2], ip[3]); | |
| LOG_INFO("Incoming ethernet connection from %s", ip.toString().c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IP logging here is hard-coded to IPv4 octets ("%u.%u.%u.%u"). If this code ever runs on an IPv6-capable stack, the output will be incorrect/misleading. Consider formatting via
toString()when available (with an ARCH_PORTDUINO fallback), ideally via a shared helper to keep formatting consistent across API servers.