1998-09-06 18:28:00 +00: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 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-11-26 12:07:20 +00:00
|
|
|
struct GAddress;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
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-09-28 17:24:09 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
IPV4 = 1,
|
|
|
|
IPV6 = 2,
|
|
|
|
UNIX = 3
|
|
|
|
} Addr;
|
|
|
|
|
|
|
|
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();
|
|
|
|
virtual int Type() = 0;
|
2001-11-22 10:38:02 +00:00
|
|
|
|
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
|
|
|
|
GAddress *GetAddress() const { return m_address; }
|
|
|
|
void SetAddress(GAddress *address);
|
1998-09-06 18:28:00 +00:00
|
|
|
|
1999-07-22 17:51:54 +00:00
|
|
|
protected:
|
2008-09-28 17:24:09 +00:00
|
|
|
GAddress *m_address;
|
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-09-28 17:24:09 +00:00
|
|
|
wxIPaddress();
|
|
|
|
wxIPaddress(const wxIPaddress& other);
|
|
|
|
virtual ~wxIPaddress();
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual bool Hostname(const wxString& name) = 0;
|
|
|
|
virtual bool Service(const wxString& name) = 0;
|
|
|
|
virtual bool Service(unsigned short port) = 0;
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual bool LocalHost() = 0;
|
|
|
|
virtual bool IsLocalHost() const = 0;
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual bool AnyAddress() = 0;
|
|
|
|
virtual bool BroadcastAddress() = 0;
|
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-09-28 17:24:09 +00:00
|
|
|
virtual wxString Hostname() const = 0;
|
|
|
|
virtual unsigned short Service() const = 0;
|
|
|
|
|
|
|
|
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-09-28 17:24:09 +00:00
|
|
|
wxIPV4address();
|
|
|
|
wxIPV4address(const wxIPV4address& other);
|
|
|
|
virtual ~wxIPV4address();
|
|
|
|
|
|
|
|
bool operator==(const wxIPV4address& addr) const;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// implement wxSockAddress pure virtuals:
|
|
|
|
virtual int Type() { return wxSockAddress::IPV4; }
|
|
|
|
virtual wxSockAddress *Clone() const;
|
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:
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// handles the usual dotted quad format too
|
|
|
|
virtual bool Hostname(const wxString& name);
|
|
|
|
virtual bool Service(const wxString& name);
|
|
|
|
virtual bool Service(unsigned short port);
|
2004-01-11 15:50:10 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// localhost (127.0.0.1)
|
|
|
|
virtual bool LocalHost();
|
|
|
|
virtual bool IsLocalHost() const;
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// any (0.0.0.0)
|
|
|
|
virtual bool AnyAddress();
|
|
|
|
// all (255.255.255.255)
|
|
|
|
virtual bool BroadcastAddress();
|
2004-09-22 14:38:52 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
// a.b.c.d
|
|
|
|
virtual wxString IPAddress() const;
|
|
|
|
|
|
|
|
virtual wxString Hostname() const;
|
|
|
|
virtual unsigned short Service() const;
|
|
|
|
|
|
|
|
|
|
|
|
// IPv4-specific methods:
|
|
|
|
|
|
|
|
bool Hostname(unsigned long addr);
|
|
|
|
wxString OrigHostname() { return m_origHostname; }
|
2002-02-21 00:01:32 +00:00
|
|
|
|
|
|
|
private:
|
2008-09-28 17:24:09 +00:00
|
|
|
wxString m_origHostname;
|
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-09-28 17:24:09 +00:00
|
|
|
wxIPV6address();
|
|
|
|
wxIPV6address(const wxIPV6address& other);
|
|
|
|
virtual ~wxIPV6address();
|
|
|
|
|
|
|
|
// implement wxSockAddress pure virtuals:
|
|
|
|
|
|
|
|
virtual int Type() { return wxSockAddress::IPV6; }
|
|
|
|
virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
|
|
|
|
|
|
|
|
|
|
|
|
// implement wxIPaddress pure virtuals:
|
|
|
|
|
|
|
|
virtual bool Hostname(const wxString& name);
|
|
|
|
virtual bool Service(const wxString& name);
|
|
|
|
virtual bool Service(unsigned short port);
|
|
|
|
|
|
|
|
// localhost (0000:0000:0000:0000:0000:0000:0000:0001 (::1))
|
|
|
|
virtual bool LocalHost();
|
|
|
|
virtual bool IsLocalHost() const;
|
|
|
|
|
|
|
|
// any (0000:0000:0000:0000:0000:0000:0000:0000 (::))
|
|
|
|
virtual bool AnyAddress();
|
|
|
|
// all (?)
|
|
|
|
virtual bool BroadcastAddress();
|
|
|
|
|
|
|
|
// 3ffe:ffff:0100:f101:0210:a4ff:fee3:9566
|
|
|
|
virtual wxString IPAddress() const;
|
|
|
|
|
|
|
|
virtual wxString Hostname() const;
|
|
|
|
virtual unsigned short Service() const;
|
|
|
|
|
|
|
|
|
|
|
|
// IPv6-specific methods:
|
|
|
|
|
|
|
|
bool Hostname(unsigned char addr[16]);
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxString m_origHostname;
|
|
|
|
|
|
|
|
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-09-28 17:24:09 +00:00
|
|
|
#if defined(__UNIX__) && !defined(__WINE__)
|
|
|
|
|
1999-08-16 12:18:40 +00:00
|
|
|
#include <sys/socket.h>
|
1999-11-12 11:27:07 +00:00
|
|
|
#ifndef __VMS__
|
2008-09-28 17:24:09 +00:00
|
|
|
#include <sys/un.h>
|
1999-11-12 11:27:07 +00:00
|
|
|
#endif
|
1998-09-06 18:28:00 +00:00
|
|
|
|
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-09-28 17:24:09 +00:00
|
|
|
wxUNIXaddress();
|
|
|
|
wxUNIXaddress(const wxUNIXaddress& other);
|
|
|
|
virtual ~wxUNIXaddress();
|
|
|
|
|
|
|
|
void Filename(const wxString& name);
|
|
|
|
wxString Filename();
|
1998-09-06 18:28:00 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
virtual int Type() { return wxSockAddress::UNIX; }
|
|
|
|
virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct sockaddr_un *m_addr;
|
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-09-28 17:24:09 +00:00
|
|
|
#endif // __UNIX__
|
1999-07-29 05:27:19 +00:00
|
|
|
|
2008-09-28 17:24:09 +00:00
|
|
|
#endif // wxUSE_SOCKETS
|
|
|
|
|
|
|
|
#endif // _WX_SCKADDR_H_
|