mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
TCP: Log the remote port for client.
This commit is contained in:
parent
e01b98c91e
commit
81a7c252d6
14 changed files with 68 additions and 39 deletions
|
@ -1143,6 +1143,28 @@ string srs_get_peer_ip(int fd)
|
|||
return std::string(saddr);
|
||||
}
|
||||
|
||||
int srs_get_peer_port(int fd)
|
||||
{
|
||||
// discovery client information
|
||||
sockaddr_storage addr;
|
||||
socklen_t addrlen = sizeof(addr);
|
||||
if (getpeername(fd, (sockaddr*)&addr, &addrlen) == -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int port = 0;
|
||||
switch(addr.ss_family) {
|
||||
case AF_INET:
|
||||
port = ntohs(((sockaddr_in*)&addr)->sin_port);
|
||||
break;
|
||||
case AF_INET6:
|
||||
port = ntohs(((sockaddr_in6*)&addr)->sin6_port);
|
||||
break;
|
||||
}
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
bool srs_is_boolean(string str)
|
||||
{
|
||||
return str == "true" || str == "false";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue