Skip to content

netsocket: add get_remote_peer() method to InternetSocket #8565

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions features/netsocket/InternetSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,7 @@ void InternetSocket::attach(Callback<void()> callback)
{
sigio(callback);
}

const SocketAddress* InternetSocket::getpeername() {
return &_remote_peer;
}
6 changes: 6 additions & 0 deletions features/netsocket/InternetSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class InternetSocket : public Socket {
*/
virtual void sigio(mbed::Callback<void()> func);

/** Get the remote-end peer associated with this socket.
*
* @return pointer to the remote_peer SocketAddress
*/
const SocketAddress* getpeername();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For lifetime reasons and general POSIX compatibility - aligning with the way we've mapped other functions - this should be prototyped as virtual nsapi_error_t getpeername(SocketAddress *address), assuming implementing a pure virtual in Socket as suggested.

(Other calls already omit the POSIX length parameter for addresses, on the assumption SocketAddress has space for all possible address types...)


/** Register a callback on state change of the socket.
*
* @see Socket::sigio
Expand Down