core-legacy/helpers/get_server_port.cc

18 lines
314 B
C++
Raw Normal View History

2019-07-14 22:39:37 +00:00
#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 sin.sin_port;
}
return -1;
}