X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1eddcfafba914bff0c9674985d5c8a7205a741c6..b0655a87f40073577bdb8ba4378e5e683a163d44:/src/common/sckaddr.cpp?ds=sidebyside diff --git a/src/common/sckaddr.cpp b/src/common/sckaddr.cpp index f3a3f48026..1656a2c8b7 100644 --- a/src/common/sckaddr.cpp +++ b/src/common/sckaddr.cpp @@ -20,6 +20,8 @@ #pragma hdrstop #endif +#if wxUSE_SOCKETS + #ifndef WX_PRECOMP #endif @@ -55,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" @@ -118,14 +128,14 @@ bool wxIPV4address::Hostname(const wxString& name) return FALSE; if (!name.IsNumber()) { - if ((theHostent = 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; @@ -153,11 +163,11 @@ bool wxIPV4address::Service(const wxString& name) return FALSE; if (!name.IsNumber()) { - if ((theServent = getservbyname(name, "tcp")) == 0) + if ((theServent = getservbyname(name.fn_str(), "tcp")) == 0) return FALSE; } else { - if ((theServent = 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; } } @@ -188,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() @@ -385,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() @@ -406,3 +420,6 @@ void wxUNIXaddress::Disassemble(struct sockaddr *addr, size_t len) *m_addr = *(struct sockaddr_un *)addr; } #endif + +#endif + // wxUSE_SOCKETS