Skip to content
Snippets Groups Projects
Commit 348e9908 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

net: new function to determine connected socket

parent 4bb873b0
Branches
Tags
No related merge requests found
......@@ -143,3 +143,10 @@ int net_connected_socket(int type, const struct sockaddr_storage *dst_addr,
return socket;
}
int net_is_connected(int fd)
{
struct sockaddr_in6 ss;
socklen_t len = sizeof(ss);
return getpeername(fd, &ss, &len) == 0;
}
......@@ -65,6 +65,16 @@ int net_bound_socket(int type, const struct sockaddr_storage *ss);
int net_connected_socket(int type, const struct sockaddr_storage *dst_addr,
const struct sockaddr_storage *src_addr, unsigned flags);
/*!
* \brief Return true if the socket is connected.
*
* @note This could be used to identify connected TCP from UDP sockets.
*
* \param fd Socket.
*
* \return true if connected
*/
int net_is_connected(int fd);
#endif // _KNOTD_NET_H_
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment