core-legacy/helpers/get_server_port.cc
Tobias Reisinger a38a6e63b3 add: filters
add: schedule api calls
2019-07-20 14:51:45 +02:00

18 lines
No EOL
323 B
C++

#include <netdb.h>
#include <helpers.h>
int
helpers::get_server_port(int fd)
{
if(fd == -1)
{
return -1;
}
struct sockaddr_in sin{};
socklen_t addrlen = sizeof(sin);
if(getsockname(fd, (struct sockaddr *)&sin, &addrlen) == 0)
{
return ntohs(sin.sin_port);
}
return -1;
}