Merge branch 'next' of git.gitorious.org:fg/simgear into next
This commit is contained in:
@@ -311,6 +311,10 @@ bool IPAddress::lookupNonblocking(const char* host, IPAddress& addr)
|
|||||||
|
|
||||||
const char* IPAddress::getHost () const
|
const char* IPAddress::getHost () const
|
||||||
{
|
{
|
||||||
|
if (!addr) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static char buf [32];
|
static char buf [32];
|
||||||
long x = ntohl(addr->sin_addr.s_addr);
|
long x = ntohl(addr->sin_addr.s_addr);
|
||||||
sprintf(buf, "%d.%d.%d.%d",
|
sprintf(buf, "%d.%d.%d.%d",
|
||||||
@@ -321,21 +325,37 @@ const char* IPAddress::getHost () const
|
|||||||
|
|
||||||
unsigned int IPAddress::getIP () const
|
unsigned int IPAddress::getIP () const
|
||||||
{
|
{
|
||||||
|
if (!addr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return addr->sin_addr.s_addr;
|
return addr->sin_addr.s_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IPAddress::getPort() const
|
unsigned int IPAddress::getPort() const
|
||||||
{
|
{
|
||||||
|
if (!addr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ntohs(addr->sin_port);
|
return ntohs(addr->sin_port);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IPAddress::setPort(int port)
|
void IPAddress::setPort(int port)
|
||||||
{
|
{
|
||||||
|
if (!addr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
addr->sin_port = htons(port);
|
addr->sin_port = htons(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IPAddress::getFamily () const
|
unsigned int IPAddress::getFamily () const
|
||||||
{
|
{
|
||||||
|
if (!addr) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return addr->sin_family;
|
return addr->sin_family;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +383,11 @@ const char* IPAddress::getLocalHost ()
|
|||||||
|
|
||||||
bool IPAddress::getBroadcast () const
|
bool IPAddress::getBroadcast () const
|
||||||
{
|
{
|
||||||
return (addr->sin_addr.s_addr == INADDR_BROADCAST);
|
if (!addr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (addr->sin_addr.s_addr == INADDR_BROADCAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int IPAddress::getAddrLen() const
|
unsigned int IPAddress::getAddrLen() const
|
||||||
@@ -381,6 +405,11 @@ struct sockaddr* IPAddress::getAddr() const
|
|||||||
return (struct sockaddr*) addr;
|
return (struct sockaddr*) addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IPAddress::isValid() const
|
||||||
|
{
|
||||||
|
return (addr != NULL);
|
||||||
|
}
|
||||||
|
|
||||||
Socket::Socket ()
|
Socket::Socket ()
|
||||||
{
|
{
|
||||||
handle = -1 ;
|
handle = -1 ;
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ public:
|
|||||||
IPAddress( const IPAddress& other );
|
IPAddress( const IPAddress& other );
|
||||||
const IPAddress& operator=(const IPAddress& other);
|
const IPAddress& operator=(const IPAddress& other);
|
||||||
|
|
||||||
|
bool isValid () const;
|
||||||
void set ( const char* host, int port ) ;
|
void set ( const char* host, int port ) ;
|
||||||
const char* getHost () const ;
|
const char* getHost () const ;
|
||||||
unsigned int getPort() const ;
|
unsigned int getPort() const ;
|
||||||
|
|||||||
@@ -209,6 +209,13 @@ NetChannel::handleResolve()
|
|||||||
return 0; // not looked up yet, wait longer
|
return 0; // not looked up yet, wait longer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!addr.isValid()) {
|
||||||
|
SG_LOG(SG_IO, SG_WARN, "Network: host lookup failed:" << host);
|
||||||
|
handleError (0);
|
||||||
|
close();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
resolving_host = false;
|
resolving_host = false;
|
||||||
addr.setPort(port);
|
addr.setPort(port);
|
||||||
int result = Socket::connect ( &addr ) ;
|
int result = Socket::connect ( &addr ) ;
|
||||||
|
|||||||
Reference in New Issue
Block a user