1998-09-06 14:28:00 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: sckaddr.h
|
|
|
|
// Purpose: Network address classes
|
|
|
|
// Author: Guilhem Lavaux
|
|
|
|
// Modified by:
|
|
|
|
// Created: 26/04/1997
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Copyright: (c) 1997, 1998 Guilhem Lavaux
|
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
|
|
|
|
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
|
|
|
|
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();
|
|
|
|
DECLARE_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
|
|
|
|
|
|
|
DECLARE_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:
|
2008-12-29 09:35:48 -05:00
|
|
|
virtual Family Type() { return IPV4; }
|
|
|
|
virtual wxSockAddress *Clone() const { 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:
|
|
|
|
virtual bool IsLocalHost() const;
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
virtual wxString IPAddress() const;
|
|
|
|
|
|
|
|
|
|
|
|
// IPv4-specific methods:
|
|
|
|
bool Hostname(unsigned long addr);
|
2008-12-29 09:35:48 -05:00
|
|
|
|
|
|
|
bool BroadcastAddress();
|
|
|
|
|
|
|
|
using wxIPaddress::Hostname;
|
2002-02-20 19:01:32 -05:00
|
|
|
|
|
|
|
private:
|
2008-12-29 09:35:48 -05:00
|
|
|
virtual void DoInitImpl();
|
1998-09-06 14:28:00 -04:00
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxIPV4address)
|
|
|
|
};
|
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
|
|
|
|
|
|
|
DECLARE_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
|
|
|
|
2008-12-29 09:35:48 -05:00
|
|
|
virtual Family Type() { return UNIX; }
|
2008-09-28 13:24:09 -04:00
|
|
|
virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
|
|
|
|
|
|
|
|
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
|
|
|
|
2008-09-28 13:24:09 -04:00
|
|
|
DECLARE_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_
|