1998-09-06 18:28:00 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2009-02-22 23:38:07 +00:00
|
|
|
// Name: wx/sckaddr.h
|
1998-09-06 18:28:00 +00:00
|
|
|
// Purpose: Network address classes
|
|
|
|
// Author: Guilhem Lavaux
|
2009-02-22 23:38:52 +00:00
|
|
|
// Modified by: Vadim Zeitlin to switch to wxSockAddressImpl implementation
|
1998-09-06 18:28:00 +00:00
|
|
|
// Created: 26/04/1997
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
2009-02-22 23:38:52 +00:00
|
|
|
// (c) 2008, 2009 Vadim Zeitlin
|
2004-05-23 20:53:33 +00:00
|
|
|
// Licence: wxWindows licence
|
1998-09-06 18:28:00 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
1999-06-22 08:36:29 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
#ifndef _WX_SCKADDR_H_
|
|
|
|
#define _WX_SCKADDR_H_
|
1998-09-06 18:28:00 +00:00
|
|
|
|
1999-06-22 08:36:29 +00:00
|
|
|
#include "wx/defs.h"
|
|
|
|
|
|
|
|
#if wxUSE_SOCKETS
|
|
|
|
|
|
|
|
#include "wx/string.h"
|
1999-07-22 17:51:54 +00:00
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
class wxSockAddressImpl;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2009-02-22 23:38:07 +00: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 17:24:09 +00:00
|
|
|
// Any socket address kind
|
|
|
|
class WXDLLIMPEXP_NET wxSockAddress : public wxObject
|
|
|
|
{
|
1998-09-06 18:28:00 +00:00
|
|
|
public:
|
2008-12-29 14:35:48 +00:00
|
|
|
enum Family
|
2008-09-28 17:24:09 +00:00
|
|
|
{
|
2008-12-29 14:35:48 +00:00
|
|
|
NONE,
|
|
|
|
IPV4,
|
|
|
|
IPV6,
|
|
|
|
UNIX
|
|
|
|
};
|
2008-09-28 17:24:09 +00:00
|
|
|
|
|
|
|
wxSockAddress();
|
|
|
|
wxSockAddress(const wxSockAddress& other);
|
|
|
|
virtual ~wxSockAddress();
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
wxSockAddress& operator=(const wxSockAddress& other);
|
1999-07-22 17:51:54 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual void Clear();
|
2008-12-29 14:35:48 +00:00
|
|
|
virtual Family Type() = 0;
|
2001-11-22 10:38:02 +00:00
|
|
|
|
2009-02-22 23:38:07 +00:00
|
|
|
// accessors for the low level address represented by this object
|
|
|
|
const sockaddr *GetAddressData() const;
|
|
|
|
int GetAddressDataLen() const;
|
|
|
|
|
2008-09-28 17:24:09 +00: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 18:28:00 +00:00
|
|
|
|
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// implementation only, don't use
|
2008-12-29 14:35:48 +00:00
|
|
|
const wxSockAddressImpl& GetAddress() const { return *m_impl; }
|
|
|
|
void SetAddress(const wxSockAddressImpl& address);
|
1998-09-06 18:28:00 +00:00
|
|
|
|
1999-07-22 17:51:54 +00:00
|
|
|
protected:
|
2008-12-29 14:35:48 +00:00
|
|
|
wxSockAddressImpl *m_impl;
|
2002-02-24 13:51:43 +00:00
|
|
|
|
|
|
|
private:
|
2008-09-28 17:24:09 +00:00
|
|
|
void Init();
|
|
|
|
DECLARE_ABSTRACT_CLASS(wxSockAddress)
|
1998-09-06 18:28:00 +00:00
|
|
|
};
|
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// An IP address (either IPv4 or IPv6)
|
|
|
|
class WXDLLIMPEXP_NET wxIPaddress : public wxSockAddress
|
|
|
|
{
|
2004-01-11 15:50:10 +00:00
|
|
|
public:
|
2008-12-29 14:35:48 +00:00
|
|
|
wxIPaddress() : wxSockAddress() { }
|
|
|
|
wxIPaddress(const wxIPaddress& other)
|
|
|
|
: wxSockAddress(other),
|
|
|
|
m_origHostname(other.m_origHostname)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const wxIPaddress& addr) const;
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
bool Hostname(const wxString& name);
|
|
|
|
bool Service(const wxString& name);
|
|
|
|
bool Service(unsigned short port);
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
bool LocalHost();
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual bool IsLocalHost() const = 0;
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
bool AnyAddress();
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual wxString IPAddress() const = 0;
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-12-29 14:35:48 +00: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 17:24:09 +00:00
|
|
|
|
|
|
|
DECLARE_ABSTRACT_CLASS(wxIPaddress)
|
2004-01-11 15:50:10 +00:00
|
|
|
};
|
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// An IPv4 address
|
|
|
|
class WXDLLIMPEXP_NET wxIPV4address : public wxIPaddress
|
|
|
|
{
|
1998-09-06 18:28:00 +00:00
|
|
|
public:
|
2008-12-29 14:35:48 +00:00
|
|
|
wxIPV4address() : wxIPaddress() { }
|
|
|
|
wxIPV4address(const wxIPV4address& other) : wxIPaddress(other) { }
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// implement wxSockAddress pure virtuals:
|
2008-12-29 14:35:48 +00:00
|
|
|
virtual Family Type() { return IPV4; }
|
|
|
|
virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); }
|
2004-01-11 15:50:10 +00:00
|
|
|
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// implement wxIPaddress pure virtuals:
|
|
|
|
virtual bool IsLocalHost() const;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual wxString IPAddress() const;
|
|
|
|
|
|
|
|
|
|
|
|
// IPv4-specific methods:
|
|
|
|
bool Hostname(unsigned long addr);
|
2008-12-29 14:35:48 +00:00
|
|
|
|
2009-01-01 17:08:41 +00:00
|
|
|
// make base class methods hidden by our overload visible
|
|
|
|
//
|
|
|
|
// FIXME-VC6: replace this with "using IPAddress::Hostname" (not supported
|
|
|
|
// by VC6) when support for it is dropped
|
|
|
|
wxString Hostname() const { return wxIPaddress::Hostname(); }
|
|
|
|
bool Hostname(const wxString& name) { return wxIPaddress::Hostname(name); }
|
2008-12-29 14:35:48 +00:00
|
|
|
|
2009-01-01 17:08:41 +00:00
|
|
|
bool BroadcastAddress();
|
2002-02-21 00:01:32 +00:00
|
|
|
|
|
|
|
private:
|
2008-12-29 14:35:48 +00:00
|
|
|
virtual void DoInitImpl();
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxIPV4address)
|
|
|
|
};
|
2005-08-04 00:28:58 +00:00
|
|
|
|
|
|
|
|
2004-01-11 15:50:10 +00:00
|
|
|
#if wxUSE_IPV6
|
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// An IPv6 address
|
|
|
|
class WXDLLIMPEXP_NET wxIPV6address : public wxIPaddress
|
|
|
|
{
|
1998-09-06 18:28:00 +00:00
|
|
|
public:
|
2008-12-29 14:35:48 +00:00
|
|
|
wxIPV6address() : wxIPaddress() { }
|
|
|
|
wxIPV6address(const wxIPV6address& other) : wxIPaddress(other) { }
|
2008-09-28 17:24:09 +00:00
|
|
|
|
|
|
|
// implement wxSockAddress pure virtuals:
|
2008-12-29 14:35:48 +00:00
|
|
|
virtual Family Type() { return IPV6; }
|
2008-09-28 17:24:09 +00: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 14:35:48 +00:00
|
|
|
using wxIPaddress::Hostname;
|
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
private:
|
2008-12-29 14:35:48 +00:00
|
|
|
virtual void DoInitImpl();
|
2008-09-28 17:24:09 +00:00
|
|
|
|
|
|
|
DECLARE_DYNAMIC_CLASS(wxIPV6address)
|
1998-09-06 18:28:00 +00:00
|
|
|
};
|
2004-01-11 15:50:10 +00:00
|
|
|
|
|
|
|
#endif // wxUSE_IPV6
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-12-29 14:35:48 +00: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 11:27:07 +00:00
|
|
|
#endif
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
#ifdef wxHAS_UNIX_DOMAIN_SOCKETS
|
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// A Unix domain socket address
|
|
|
|
class WXDLLIMPEXP_NET wxUNIXaddress : public wxSockAddress
|
|
|
|
{
|
1998-09-06 18:28:00 +00:00
|
|
|
public:
|
2008-12-29 14:35:48 +00:00
|
|
|
wxUNIXaddress() : wxSockAddress() { }
|
|
|
|
wxUNIXaddress(const wxUNIXaddress& other) : wxSockAddress(other) { }
|
2008-09-28 17:24:09 +00:00
|
|
|
|
|
|
|
void Filename(const wxString& name);
|
2008-12-29 14:35:48 +00:00
|
|
|
wxString Filename() const;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
virtual Family Type() { return UNIX; }
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
|
|
|
|
|
|
|
|
private:
|
2008-12-29 14:35:48 +00:00
|
|
|
wxSockAddressImpl& GetUNIX();
|
|
|
|
const wxSockAddressImpl& GetUNIX() const
|
|
|
|
{
|
|
|
|
return const_cast<wxUNIXaddress *>(this)->GetUNIX();
|
|
|
|
}
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
|
1998-09-06 18:28:00 +00:00
|
|
|
};
|
|
|
|
|
2008-12-29 14:35:48 +00:00
|
|
|
#endif // wxHAS_UNIX_DOMAIN_SOCKETS
|
1999-07-29 05:27:19 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
#endif // wxUSE_SOCKETS
|
|
|
|
|
|
|
|
#endif // _WX_SCKADDR_H_
|