25 lines
480 B
C
25 lines
480 B
C
|
#include <sys/socket.h>
|
||
|
#include <arpa/inet.h>
|
||
|
#include <stdint.h>
|
||
|
#include <errno.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include <helpers.h>
|
||
|
#include <logger.h>
|
||
|
|
||
|
uint16_t
|
||
|
helper_get_port(int sock)
|
||
|
{
|
||
|
struct sockaddr_in sin;
|
||
|
socklen_t len = sizeof(sin);
|
||
|
if (getsockname(sock, (struct sockaddr *)&sin, &len) == -1)
|
||
|
{
|
||
|
LOG_ERROR("could not get socket name for port: %s\n", strerror(errno));
|
||
|
return 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return ntohs(sin.sin_port);
|
||
|
}
|
||
|
}
|