mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
Fix client tools resolve dns failed bug
This commit is contained in:
parent
c20b819a29
commit
0d78b908a7
7 changed files with 21 additions and 14 deletions
|
@ -124,7 +124,7 @@ srs_error_t SrsUdpListener::listen()
|
|||
|
||||
addrinfo* r = NULL;
|
||||
SrsAutoFree(addrinfo, r);
|
||||
if(getaddrinfo(ip.c_str(), sport, (const addrinfo*)&hints, &r) != 0) {
|
||||
if(getaddrinfo(ip.c_str(), sport, (const addrinfo*)&hints, &r)) {
|
||||
return srs_error_new(ERROR_SYSTEM_IP_INVALID, "get address info");
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ srs_error_t SrsTcpListener::listen()
|
|||
|
||||
addrinfo* r = NULL;
|
||||
SrsAutoFree(addrinfo, r);
|
||||
if(getaddrinfo(ip.c_str(), sport, (const addrinfo*)&hints, &r) != 0) {
|
||||
if(getaddrinfo(ip.c_str(), sport, (const addrinfo*)&hints, &r)) {
|
||||
return srs_error_new(ERROR_SYSTEM_IP_INVALID, "get address info");
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ srs_error_t SrsMpegtsOverUdp::on_udp_packet(const sockaddr* from, const int from
|
|||
if(getnameinfo(from, fromlen,
|
||||
(char*)&address_string, sizeof(address_string),
|
||||
(char*)&port_string, sizeof(port_string),
|
||||
NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
|
||||
NI_NUMERICHOST|NI_NUMERICSERV)) {
|
||||
return srs_error_new(ERROR_SYSTEM_IP_INVALID, "bad address");
|
||||
}
|
||||
std::string peer_ip = std::string(address_string);
|
||||
|
|
|
@ -1117,7 +1117,7 @@ string srs_get_local_ip(int fd)
|
|||
char* h = (char*)saddr;
|
||||
socklen_t nbh = (socklen_t)sizeof(saddr);
|
||||
const int r0 = getnameinfo((const sockaddr*)&addr, addrlen, h, nbh,NULL, 0, NI_NUMERICHOST);
|
||||
if(r0 != 0) {
|
||||
if(r0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -1159,7 +1159,7 @@ string srs_get_peer_ip(int fd)
|
|||
char* h = (char*)saddr;
|
||||
socklen_t nbh = (socklen_t)sizeof(saddr);
|
||||
const int r0 = getnameinfo((const sockaddr*)&addr, addrlen, h, nbh, NULL, 0, NI_NUMERICHOST);
|
||||
if(r0 != 0) {
|
||||
if(r0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
@ -164,7 +164,7 @@ string srs_dns_resolve(string host, int& family)
|
|||
addrinfo* r = NULL;
|
||||
SrsAutoFree(addrinfo, r);
|
||||
|
||||
if(getaddrinfo(host.c_str(), NULL, NULL, &r) != 0) {
|
||||
if(getaddrinfo(host.c_str(), NULL, NULL, &r)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ string srs_dns_resolve(string host, int& family)
|
|||
socklen_t nbh = sizeof(saddr);
|
||||
const int r0 = getnameinfo(r->ai_addr, r->ai_addrlen, h, nbh, NULL, 0, NI_NUMERICHOST);
|
||||
|
||||
if(r0) {
|
||||
if(!r0) {
|
||||
family = r->ai_family;
|
||||
return string(saddr);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
#include <srs_lib_simple_socket.hpp>
|
||||
|
||||
#include <netinet/tcp.h>
|
||||
|
||||
#include <srs_kernel_error.hpp>
|
||||
|
||||
// for srs-librtmp, @see https://github.com/ossrs/srs/issues/213
|
||||
|
@ -119,6 +121,10 @@ int srs_hijack_io_create_socket(srs_hijack_io_t ctx, srs_rtmp_t owner)
|
|||
if (!SOCKET_VALID(skt->fd)) {
|
||||
return ERROR_SOCKET_CREATE;
|
||||
}
|
||||
|
||||
// No TCP cache.
|
||||
int v = 1;
|
||||
setsockopt(skt->fd, IPPROTO_TCP, TCP_NODELAY, &v, sizeof(v));
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
@ -133,14 +139,15 @@ int srs_hijack_io_connect(srs_hijack_io_t ctx, const char* server_ip, int port)
|
|||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = skt->family;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_NUMERICHOST;
|
||||
|
||||
addrinfo* r = NULL;
|
||||
SrsAutoFree(addrinfo, r);
|
||||
if(getaddrinfo(server_ip, sport, (const addrinfo*)&hints, &r) == 0) {
|
||||
if(::connect(skt->fd, r->ai_addr, r->ai_addrlen) < 0){
|
||||
return ERROR_SOCKET_CONNECT;
|
||||
}
|
||||
if(getaddrinfo(server_ip, sport, (const addrinfo*)&hints, &r)) {
|
||||
return ERROR_SOCKET_CONNECT;
|
||||
}
|
||||
|
||||
if(::connect(skt->fd, r->ai_addr, r->ai_addrlen) < 0){
|
||||
return ERROR_SOCKET_CONNECT;
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
|
|
|
@ -124,7 +124,7 @@ srs_error_t srs_socket_connect(string server, int port, int64_t tm, srs_netfd_t*
|
|||
|
||||
addrinfo* r = NULL;
|
||||
SrsAutoFree(addrinfo, r);
|
||||
if(getaddrinfo(server.c_str(), sport, (const addrinfo*)&hints, &r) != 0) {
|
||||
if(getaddrinfo(server.c_str(), sport, (const addrinfo*)&hints, &r)) {
|
||||
return srs_error_new(ERROR_SYSTEM_IP_INVALID, "get address info");
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ void discover_network_iface(ifaddrs* cur, vector<string>& ips, stringstream& ss0
|
|||
char* h = (char*)saddr;
|
||||
socklen_t nbh = (socklen_t)sizeof(saddr);
|
||||
const int r0 = getnameinfo(cur->ifa_addr, sizeof(sockaddr_storage), h, nbh, NULL, 0, NI_NUMERICHOST);
|
||||
if(r0 != 0) {
|
||||
if(r0) {
|
||||
srs_warn("convert local ip failed: %s", gai_strerror(r0));
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue