X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/17dff81c7141e142765b168ab225e5c61475669f..b0655a87f40073577bdb8ba4378e5e683a163d44:/src/common/sckaddr.cpp diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index b61afc01a4..1656a2c8b7 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -20,13 +20,16 @@ #pragma hdrstop #endif +#if wxUSE_SOCKETS + #ifndef WX_PRECOMP #endif #include #include #include -#ifndef __MWERKS__ + +#if !defined(__MWERKS__) && !defined(__SALFORDC__) #include #endif @@ -42,14 +45,10 @@ #endif // __WINDOWS__ #if defined(__UNIX__) - #ifdef VMS #include #include #else -#if defined(__FreeBSD__) || defined (__NetBSD__) -#include -#endif #include #include #include @@ -58,6 +57,14 @@ #include #include +#ifdef __SUN__ +extern "C" +{ + struct hostent *gethostbyname(const char *name); + int gethostname(char *name, int namelen); +}; +#endif + #endif // __UNIX__ #include "wx/sckaddr.h" @@ -114,21 +121,21 @@ const wxSockAddress& wxIPV4address::operator =(const wxSockAddress& addr) 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; @@ -136,7 +143,7 @@ bool wxIPV4address::Hostname(const wxString& name) 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; @@ -150,22 +157,22 @@ bool wxIPV4address::Hostname(unsigned long addr) 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; } @@ -191,7 +198,11 @@ wxString wxIPV4address::Hostname() 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() @@ -254,7 +265,7 @@ const wxSockAddress& wxIPV6address::operator =(const wxSockAddress& addr) bool wxIPV6address::Hostname(const wxString& name) { - struct hostent *hostent; + struct hostent *theHostent; struct in_addr *addr; if (name.IsNull()) @@ -262,14 +273,14 @@ bool wxIPV6address::Hostname(const wxString& name) 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; @@ -283,22 +294,22 @@ bool wxIPV6address::Hostname(unsigned char addr[16]) 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; } @@ -388,7 +399,7 @@ const wxSockAddress& wxUNIXaddress::operator =(const wxSockAddress& addr) 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() @@ -409,3 +420,6 @@ void wxUNIXaddress::Disassemble(struct sockaddr *addr, size_t len) *m_addr = *(struct sockaddr_un *)addr; } #endif + +#endif + // wxUSE_SOCKETS