File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,34 @@ uint16_t WiFiClient::remotePort() const
346
346
return remotePort (fd ());
347
347
}
348
348
349
+ IPAddress WiFiClient::localIP (int fd) const
350
+ {
351
+ struct sockaddr_storage addr;
352
+ socklen_t len = sizeof addr;
353
+ getsockname (fd, (struct sockaddr *)&addr, &len);
354
+ struct sockaddr_in *s = (struct sockaddr_in *)&addr;
355
+ return IPAddress ((uint32_t )(s->sin_addr .s_addr ));
356
+ }
357
+
358
+ uint16_t WiFiClient::localPort (int fd) const
359
+ {
360
+ struct sockaddr_storage addr;
361
+ socklen_t len = sizeof addr;
362
+ getsockname (fd, (struct sockaddr *)&addr, &len);
363
+ struct sockaddr_in *s = (struct sockaddr_in *)&addr;
364
+ return ntohs (s->sin_port );
365
+ }
366
+
367
+ IPAddress WiFiClient::localIP () const
368
+ {
369
+ return localIP (fd ());
370
+ }
371
+
372
+ uint16_t WiFiClient::localPort () const
373
+ {
374
+ return localPort (fd ());
375
+ }
376
+
349
377
bool WiFiClient::operator ==(const WiFiClient& rhs)
350
378
{
351
379
return clientSocketHandle == rhs.clientSocketHandle && remotePort () == rhs.remotePort () && remoteIP () == rhs.remoteIP ();
Original file line number Diff line number Diff line change @@ -85,6 +85,11 @@ class WiFiClient : public Client
85
85
uint16_t remotePort () const ;
86
86
uint16_t remotePort (int fd) const ;
87
87
88
+ IPAddress localIP () const ;
89
+ IPAddress localIP (int fd) const ;
90
+ uint16_t localPort () const ;
91
+ uint16_t localPort (int fd) const ;
92
+
88
93
// friend class WiFiServer;
89
94
using Print::write;
90
95
};
You can’t perform that action at this time.
0 commit comments