#pragma hdrstop
#endif
+#if wxUSE_SOCKETS
+
#ifndef WX_PRECOMP
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
-#ifndef __MWERKS__
+
+#if !defined(__MWERKS__) && !defined(__SALFORDC__)
#include <memory.h>
#endif
#endif // __WINDOWS__
#if defined(__UNIX__)
-
#ifdef VMS
#include <socket.h>
#include <in.h>
#else
-#if defined(__FreeBSD__) || defined (__NetBSD__)
-#include <sys/types.h>
-#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
+#ifdef __SUN__
+extern "C"
+{
+ struct hostent *gethostbyname(const char *name);
+ int gethostname(char *name, int namelen);
+};
+#endif
+
#endif // __UNIX__
#include "wx/sckaddr.h"
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.fn_str())) == 0) {
return FALSE;
}
} else {
#ifdef __WXMAC__
- long len_addr = inet_addr(name.GetData()).s_addr ;
+ long len_addr = inet_addr(name.fn_str()).s_addr ;
#else
- long len_addr = inet_addr(name.GetData());
+ long len_addr = inet_addr(name.fn_str());
#endif
if (len_addr == -1)
return FALSE;
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.fn_str(), "tcp")) == 0)
return FALSE;
} else {
- if ((servent = getservbyport(atoi(name), "tcp")) == 0) {
- m_addr->sin_port = htons(atoi(name));
+ if ((theServent = getservbyport(wxAtoi(name), "tcp")) == 0) {
+ m_addr->sin_port = htons(wxAtoi(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;
}
void wxUNIXaddress::Filename(const wxString& fname)
{
- sprintf(m_addr->sun_path, "%s", WXSTRINGCAST fname);
+ sprintf(m_addr->sun_path, "%s", MBSTRINGCAST fname.mb_str());
}
wxString wxUNIXaddress::Filename()
*m_addr = *(struct sockaddr_un *)addr;
}
#endif
+
+#endif
+ // wxUSE_SOCKETS