mirror of
https://github.com/ZoneMinder/zoneminder.git
synced 2026-05-05 13:13:02 -04:00
IPv6 improvements
This commit is contained in:
@@ -35,6 +35,10 @@ RemoteCamera::RemoteCamera( int p_id, const std::string &p_protocol, const std::
|
||||
|
||||
RemoteCamera::~RemoteCamera()
|
||||
{
|
||||
if(hp != NULL) {
|
||||
freeaddrinfo(hp);
|
||||
hp = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void RemoteCamera::Initialise()
|
||||
@@ -61,23 +65,15 @@ void RemoteCamera::Initialise()
|
||||
auth64 = base64Encode( auth );
|
||||
}
|
||||
|
||||
if ( !hp )
|
||||
{
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = PF_UNSPEC;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
if ( getaddrinfo(host.c_str(), NULL, &hints, &hp) != 0 )
|
||||
{
|
||||
Fatal( "Can't gethostbyname(%s): %s", host.c_str(), strerror(h_errno) );
|
||||
}
|
||||
//memcpy((char *)&sa.sin_addr, (char *)hp->h_addr, hp->h_length);
|
||||
//sa.sin_family = hp->h_addrtype;
|
||||
//sa.sin_port = htons(atoi(port.c_str()));
|
||||
sa = hp->ai_addr;
|
||||
((struct sockaddr_in *)sa)->sin_port = htons(atoi(port.c_str()));
|
||||
int ret = getaddrinfo(host.c_str(), port.c_str(), &hints, &hp);
|
||||
if ( ret != 0 )
|
||||
{
|
||||
Fatal( "Can't getaddrinfo(%s port %s): %s", host.c_str(), port.c_str(), gai_strerror(ret) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "zm_camera.h"
|
||||
|
||||
#include <string>
|
||||
//#include <netdb.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netdb.h>
|
||||
@@ -43,8 +42,7 @@ protected:
|
||||
std::string auth64;
|
||||
|
||||
protected:
|
||||
struct addrinfo *hp;
|
||||
struct sockaddr *sa;
|
||||
struct addrinfo *hp;
|
||||
|
||||
public:
|
||||
RemoteCamera( int p_id, const std::string &p_proto, const std::string &p_host, const std::string &p_port, const std::string &p_path, int p_width, int p_height, int p_colours, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture );
|
||||
|
||||
@@ -88,22 +88,34 @@ void RemoteCameraHttp::Initialise()
|
||||
|
||||
int RemoteCameraHttp::Connect()
|
||||
{
|
||||
if ( sd < 0 )
|
||||
struct addrinfo *p;
|
||||
|
||||
for(p = hp; p != NULL; p = p->ai_next)
|
||||
{
|
||||
sd = socket( hp->ai_family, SOCK_STREAM, 0 );
|
||||
sd = socket( p->ai_family, p->ai_socktype, p->ai_protocol );
|
||||
if ( sd < 0 )
|
||||
{
|
||||
Error( "Can't create socket: %s", strerror(errno) );
|
||||
return( -1 );
|
||||
Warning("Can't create socket: %s", strerror(errno) );
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( connect( sd, (struct sockaddr *)sa, hp->ai_addrlen ) < 0 )
|
||||
if ( connect( sd, p->ai_addr, p->ai_addrlen ) < 0 )
|
||||
{
|
||||
Error( "Can't connect to remote camera: %s", strerror(errno) );
|
||||
Disconnect();
|
||||
return( -1 );
|
||||
close(sd);
|
||||
sd = -1;
|
||||
Warning("Can't connect to remote camera: %s", strerror(errno) );
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If we got here, we must have connected successfully */
|
||||
break;
|
||||
}
|
||||
|
||||
if(p == NULL) {
|
||||
Error("Unable to connect to the remote camera, aborting");
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
Debug( 3, "Connected to host, socket = %d", sd );
|
||||
return( sd );
|
||||
}
|
||||
@@ -112,7 +124,6 @@ int RemoteCameraHttp::Disconnect()
|
||||
{
|
||||
close( sd );
|
||||
sd = -1;
|
||||
freeaddrinfo(hp);
|
||||
Debug( 3, "Disconnected from host" );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user