1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

For #1920, refine rtmp listen ip and port check (#2581)

This commit is contained in:
ChenGH 2021-09-05 14:05:28 +08:00 committed by GitHub
parent 714e182096
commit 3f94d26ca4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 3 deletions

View file

@ -258,6 +258,24 @@ void srs_parse_endpoint(string hostport, string& ip, int& port)
}
}
bool srs_check_ip_addr_valid(string ip)
{
unsigned char buf[sizeof(struct in6_addr)];
// check ipv4
int ret = inet_pton(AF_INET, ip.data(), buf);
if (ret > 0) {
return true;
}
ret = inet_pton(AF_INET6, ip.data(), buf);
if (ret > 0) {
return true;
}
return false;
}
string srs_int2str(int64_t value)
{
// len(max int64_t) is 20, plus one "+-."

View file

@ -45,6 +45,9 @@ extern void srs_parse_hostport(std::string hostport, std::string& host, int& por
// @remark The hostport format in <[ip:]port>, where ip is default to "0.0.0.0".
extern void srs_parse_endpoint(std::string hostport, std::string& ip, int& port);
// Check whether the ip is valid.
extern bool srs_check_ip_addr_valid(std::string ip);
// Parse the int64 value to string.
extern std::string srs_int2str(int64_t value);
// Parse the float value to string, precise is 2.