1998-09-06 14:28:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2009-02-22 18:38:07 -05:00
|
|
|
// Name: wx/sckaddr.h
|
1998-09-06 14:28:00 -04:00
|
|
|
// Purpose: Network address classes
|
|
|
|
// Author: Guilhem Lavaux
|
2009-02-22 18:38:52 -05:00
|
|
|
// Modified by: Vadim Zeitlin to switch to wxSockAddressImpl implementation
|
1998-09-06 14:28:00 -04:00
|
|
|
// Created: 26/04/1997
|
|
|
|
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
2009-02-22 18:38:52 -05:00
|
|
|
// (c) 2008, 2009 Vadim Zeitlin
|
2004-05-23 16:53:33 -04:00
|
|
|
// Licence: wxWindows licence
|
1998-09-06 14:28:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1999-06-22 04:36:29 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
#ifndef _WX_SCKADDR_H_
|
|
|
|
#define _WX_SCKADDR_H_
|
1998-09-06 14:28:00 -04:00
|
|
|
|
1999-06-22 04:36:29 -04:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_SOCKETS
|
|
|
|
|
|
|
|
#include "wx/string.h"
|
1999-07-22 13:51:54 -04:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
class wxSockAddressImpl;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2009-02-22 18:38:07 -05:00
|
|
|
// forward declare it instead of including the system headers defining it which
|
|
|
|
// can bring in <windows.h> under Windows which we don't want to include from
|
|
|
|
// public wx headers
|
|
|
|
struct sockaddr;
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// Any socket address kind
|
|
|
|
class WXDLLIMPEXP_NET wxSockAddress : public wxObject
|
|
|
|
{
|
1998-09-06 14:28:00 -04:00
|
|
|
public:
|
2008-12-29 09:35:48 -05:00
|
|
|
enum Family
|
2008-09-28 13:24:09 -04:00
|
|
|
{
|
2008-12-29 09:35:48 -05:00
|
|
|
NONE,
|
|
|
|
IPV4,
|
|
|
|
IPV6,
|
|
|
|
UNIX
|
|
|
|
};
|
2008-09-28 13:24:09 -04:00
|
|
|
|
|
|
|
wxSockAddress();
|
|
|
|
wxSockAddress(const wxSockAddress& other);
|
|
|
|
virtual ~wxSockAddress();
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
wxSockAddress& operator=(const wxSockAddress& other);
|
1999-07-22 13:51:54 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
virtual void Clear();
|
2008-12-29 09:35:48 -05:00
|
|
|
virtual Family Type() = 0;
|
2001-11-22 05:38:02 -05:00
|
|
|
|
2009-02-22 18:38:07 -05:00
|
|
|
// accessors for the low level address represented by this object
|
|
|
|
const sockaddr *GetAddressData() const;
|
|
|
|
int GetAddressDataLen() const;
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// we need to be able to create copies of the addresses polymorphically
|
|
|
|
// (i.e. without knowing the exact address class)
|
|
|
|
virtual wxSockAddress *Clone() const = 0;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// implementation only, don't use
|
2008-12-29 09:35:48 -05:00
|
|
|
const wxSockAddressImpl& GetAddress() const { return *m_impl; }
|
|
|
|
void SetAddress(const wxSockAddressImpl& address);
|
1998-09-06 14:28:00 -04:00
|
|
|
|
1999-07-22 13:51:54 -04:00
|
|
|
protected:
|
2008-12-29 09:35:48 -05:00
|
|
|
wxSockAddressImpl *m_impl;
|
2002-02-24 08:51:43 -05:00
|
|
|
|
|
|
|
private:
|
2008-09-28 13:24:09 -04:00
|
|
|
void Init();
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxSockAddress);
|
1998-09-06 14:28:00 -04:00
|
|
|
};
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// An IP address (either IPv4 or IPv6)
|
|
|
|
class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
|
|
|
|
{
|
2004-01-11 10:50:10 -05:00
|
|
|
public:
|
2008-12-29 09:35:48 -05:00
|
|
|
wxIPaddress() : wxSockAddress() { }
|
|
|
|
wxIPaddress(const wxIPaddress& other)
|
|
|
|
: wxSockAddress(other),
|
|
|
|
m_origHostname(other.m_origHostname)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const wxIPaddress& addr) const;
|
2004-01-11 10:50:10 -05:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
bool Hostname(const wxString& name);
|
|
|
|
bool Service(const wxString& name);
|
|
|
|
bool Service(unsigned short port);
|
2004-01-11 10:50:10 -05:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
bool LocalHost();
|
2008-09-28 13:24:09 -04:00
|
|
|
virtual bool IsLocalHost() const = 0;
|
2004-01-11 10:50:10 -05:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
bool AnyAddress();
|
2004-01-11 10:50:10 -05:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
virtual wxString IPAddress() const = 0;
|
2004-01-11 10:50:10 -05:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
wxString Hostname() const;
|
|
|
|
unsigned short Service() const;
|
|
|
|
|
|
|
|
wxString OrigHostname() const { return m_origHostname; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// get m_impl initialized to the right family if it hadn't been done yet
|
|
|
|
wxSockAddressImpl& GetImpl();
|
|
|
|
const wxSockAddressImpl& GetImpl() const
|
|
|
|
{
|
|
|
|
return const_cast<wxIPaddress *>(this)->GetImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
// host name originally passed to Hostname()
|
|
|
|
wxString m_origHostname;
|
|
|
|
|
|
|
|
private:
|
|
|
|
// create the wxSockAddressImpl object of the correct family if it's
|
|
|
|
// currently uninitialized
|
|
|
|
virtual void DoInitImpl() = 0;
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_ABSTRACT_CLASS(wxIPaddress);
|
2004-01-11 10:50:10 -05:00
|
|
|
};
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// An IPv4 address
|
|
|
|
class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
|
|
|
|
{
|
1998-09-06 14:28:00 -04:00
|
|
|
public:
|
2008-12-29 09:35:48 -05:00
|
|
|
wxIPV4address() : wxIPaddress() { }
|
|
|
|
wxIPV4address(const wxIPV4address& other) : wxIPaddress(other) { }
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// implement wxSockAddress pure virtuals:
|
2015-09-06 20:20:42 -04:00
|
|
|
virtual Family Type() wxOVERRIDE { return IPV4; }
|
|
|
|
virtual wxSockAddress *Clone() const wxOVERRIDE { return new wxIPV4address(*this); }
|
2004-01-11 10:50:10 -05:00
|
|
|
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// implement wxIPaddress pure virtuals:
|
2015-09-06 20:20:42 -04:00
|
|
|
virtual bool IsLocalHost() const wxOVERRIDE;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2015-09-06 20:20:42 -04:00
|
|
|
virtual wxString IPAddress() const wxOVERRIDE;
|
2008-09-28 13:24:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
// IPv4-specific methods:
|
|
|
|
bool Hostname(unsigned long addr);
|
2008-12-29 09:35:48 -05:00
|
|
|
|
2009-01-01 12:08:41 -05:00
|
|
|
// make base class methods hidden by our overload visible
|
2014-05-15 18:32:17 -04:00
|
|
|
using wxIPaddress::Hostname;
|
2008-12-29 09:35:48 -05:00
|
|
|
|
2009-01-01 12:08:41 -05:00
|
|
|
bool BroadcastAddress();
|
2002-02-20 19:01:32 -05:00
|
|
|
|
|
|
|
private:
|
2015-09-06 20:20:42 -04:00
|
|
|
virtual void DoInitImpl() wxOVERRIDE;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxIPV4address);
|
2008-09-28 13:24:09 -04:00
|
|
|
};
|
2005-08-03 20:28:58 -04:00
|
|
|
|
|
|
|
|
2004-01-11 10:50:10 -05:00
|
|
|
#if wxUSE_IPV6
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// An IPv6 address
|
|
|
|
class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
|
|
|
|
{
|
1998-09-06 14:28:00 -04:00
|
|
|
public:
|
2008-12-29 09:35:48 -05:00
|
|
|
wxIPV6address() : wxIPaddress() { }
|
|
|
|
wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
|
2008-09-28 13:24:09 -04:00
|
|
|
|
|
|
|
// implement wxSockAddress pure virtuals:
|
2008-12-29 09:35:48 -05:00
|
|
|
virtual Family Type() { return IPV6; }
|
2008-09-28 13:24:09 -04:00
|
|
|
virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
|
|
|
|
|
|
|
|
|
|
|
|
// implement wxIPaddress pure virtuals:
|
|
|
|
virtual bool IsLocalHost() const;
|
|
|
|
|
|
|
|
virtual wxString IPAddress() const;
|
|
|
|
|
|
|
|
// IPv6-specific methods:
|
|
|
|
bool Hostname(unsigned char addr[16]);
|
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
using wxIPaddress::Hostname;
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
private:
|
2008-12-29 09:35:48 -05:00
|
|
|
virtual void DoInitImpl();
|
2008-09-28 13:24:09 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxIPV6address);
|
1998-09-06 14:28:00 -04:00
|
|
|
};
|
2004-01-11 10:50:10 -05:00
|
|
|
|
|
|
|
#endif // wxUSE_IPV6
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
// Unix domain sockets are only available under, well, Unix
|
|
|
|
#if defined(__UNIX__) && !defined(__WINDOWS__) && !defined(__WINE__)
|
|
|
|
#define wxHAS_UNIX_DOMAIN_SOCKETS
|
1999-11-12 06:27:07 -05:00
|
|
|
#endif
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
// A Unix domain socket address
|
|
|
|
class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
|
|
|
|
{
|
1998-09-06 14:28:00 -04:00
|
|
|
public:
|
2008-12-29 09:35:48 -05:00
|
|
|
wxUNIXaddress() : wxSockAddress() { }
|
|
|
|
wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
|
2008-09-28 13:24:09 -04:00
|
|
|
|
|
|
|
void Filename(const wxString& name);
|
2008-12-29 09:35:48 -05:00
|
|
|
wxString Filename() const;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2015-09-06 20:20:42 -04:00
|
|
|
virtual Family Type() wxOVERRIDE { return UNIX; }
|
|
|
|
virtual wxSockAddress *Clone() const wxOVERRIDE { return new wxUNIXaddress(*this); }
|
2008-09-28 13:24:09 -04:00
|
|
|
|
|
|
|
private:
|
2008-12-29 09:35:48 -05:00
|
|
|
wxSockAddressImpl& GetUNIX();
|
|
|
|
const wxSockAddressImpl& GetUNIX() const
|
|
|
|
{
|
|
|
|
return const_cast<wxUNIXaddress *>(this)->GetUNIX();
|
|
|
|
}
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2015-04-23 07:49:01 -04:00
|
|
|
wxDECLARE_DYNAMIC_CLASS(wxUNIXaddress);
|
1998-09-06 14:28:00 -04:00
|
|
|
};
|
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
#endif // wxHAS_UNIX_DOMAIN_SOCKETS
|
1999-07-29 01:27:19 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
#endif // wxUSE_SOCKETS
|
|
|
|
|
|
|
|
#endif // _WX_SCKADDR_H_
|