#pragma implementation "sckaddr.h"
#endif
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
+
+#if !defined(__MWERKS__) && !defined(__SALFORDC__)
#include <memory.h>
+#endif
#include "wx/defs.h"
#include "wx/object.h"
+#if defined(__WXMAC__)
+#include "/wx/mac/macsock.h"
+#endif
+
#if defined(__WINDOWS__)
#include <winsock.h>
#endif // __WINDOWS__
#if defined(__UNIX__)
-
#ifdef VMS
#include <socket.h>
#include <in.h>
#else
+#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <netdb.h>
+#ifdef __SUN__
+extern "C"
+{
+ struct hostent *gethostbyname(const char *name);
+};
+#endif
+
#endif // __UNIX__
#include "wx/sckaddr.h"
-#ifdef __BORLANDC__
-#pragma hdrstop
-#endif
-
#define CHECK_ADDRTYPE(var, type)
#if !USE_SHARED_LIBRARY
bool wxIPV4address::Hostname(const wxString& name)
{
- struct hostent *hostent;
+ struct hostent *theHostent;
struct in_addr *addr;
if (name.IsNull())
return FALSE;
if (!name.IsNumber()) {
- if ((hostent = gethostbyname(name.GetData())) == 0) {
+ if ((theHostent = gethostbyname(name.GetData())) == 0) {
return FALSE;
}
} else {
+#ifdef __WXMAC__
+ long len_addr = inet_addr(name.GetData()).s_addr ;
+#else
long len_addr = inet_addr(name.GetData());
+#endif
if (len_addr == -1)
return FALSE;
m_addr->sin_addr.s_addr = len_addr;
return TRUE;
}
- addr = (struct in_addr *) *(hostent->h_addr_list);
+ addr = (struct in_addr *) *(theHostent->h_addr_list);
m_addr->sin_addr.s_addr = addr[0].s_addr;
return TRUE;
bool wxIPV4address::Service(const wxString& name)
{
- struct servent *servent;
+ struct servent *theServent;
if (name.IsNull())
return FALSE;
if (!name.IsNumber()) {
- if ((servent = getservbyname(name, "tcp")) == 0)
+ if ((theServent = getservbyname(name, "tcp")) == 0)
return FALSE;
} else {
- if ((servent = getservbyport(atoi(name), "tcp")) == 0) {
+ if ((theServent = getservbyport(atoi(name), "tcp")) == 0) {
m_addr->sin_port = htons(atoi(name));
return TRUE;
}
}
- m_addr->sin_port = servent->s_port;
+ m_addr->sin_port = theServent->s_port;
return TRUE;
}
h_ent = gethostbyaddr((char *)&(m_addr->sin_addr), sizeof(m_addr->sin_addr),
GetFamily());
- return wxString(h_ent->h_name);
+
+ if (!h_ent)
+ return wxString("");
+ else
+ return wxString(h_ent->h_name);
}
unsigned short wxIPV4address::Service()
bool wxIPV6address::Hostname(const wxString& name)
{
- struct hostent *hostent;
+ struct hostent *theHostent;
struct in_addr *addr;
if (name.IsNull())
if (!name.IsNumber()) {
hostent = gethostbyname2((char*) name, AF_INET6);
- if (!hostent)
+ if (!theHostent)
return FALSE;
} else {
// Don't how to do
return FALSE;
}
- addr = (struct in6_addr *) *(hostent->h_addr_list);
+ addr = (struct in6_addr *) *(theHostent->h_addr_list);
m_addr->sin6_addr.s6_addr = addr[0].s6_addr;
return TRUE;
bool wxIPV6address::Service(const char *name)
{
- struct servent *servent;
+ struct servent *theServent;
if (!name || !strlen(name))
return FALSE;
if (!isdigit(*name)) {
- if ((servent = getservbyname((char*) name, "tcp")) == 0)
+ if ((theServent = getservbyname((char*) name, "tcp")) == 0)
return FALSE;
} else {
- if ((servent = getservbyport(atoi(name), "tcp")) == 0) {
+ if ((theServent = getservbyport(atoi(name), "tcp")) == 0) {
m_addr->sin_port = htons(atoi(name));
return TRUE;
}
}
- m_addr->sin_port = servent->s_port;
+ m_addr->sin_port = theServent->s_port;
return TRUE;
}