1. removed wxObject::CopyObject() and Clone() - some objects just can't be
[wxWidgets.git] / include / wx / sckaddr.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sckaddr.h
3 // Purpose: Network address classes
4 // Author: Guilhem Lavaux
5 // Modified by:
6 // Created: 26/04/1997
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997, 1998 Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_NETWORK_ADDRESS_H
13 #define _WX_NETWORK_ADDRESS_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include "wx/defs.h"
20
21 #if wxUSE_SOCKETS
22
23 #include "wx/string.h"
24 #include "wx/gsocket.h"
25
26
27 class WXDLLEXPORT wxSockAddress : public wxObject {
28 DECLARE_ABSTRACT_CLASS(wxSockAddress)
29 public:
30 typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr;
31
32 wxSockAddress();
33 virtual ~wxSockAddress();
34
35 virtual void Clear();
36 virtual int Type() = 0;
37
38 GAddress *GetAddress() const { return m_address; }
39 void SetAddress(GAddress *address);
40 const wxSockAddress& operator =(const wxSockAddress& addr);
41
42 // we need to be able to create copies of the addresses polymorphically (i.e.
43 // wihtout knowing the exact address class)
44 virtual wxSockAddress *Clone() const = 0;
45
46 protected:
47 GAddress *m_address;
48 };
49
50 class WXDLLEXPORT wxIPV4address : public wxSockAddress {
51 DECLARE_DYNAMIC_CLASS(wxIPV4address)
52 public:
53 wxIPV4address();
54 virtual ~wxIPV4address();
55
56 bool Hostname(const wxString& name);
57 bool Hostname(unsigned long addr);
58 bool Service(const wxString& name);
59 bool Service(unsigned short port);
60 bool LocalHost();
61 bool AnyAddress();
62
63 wxString Hostname();
64 unsigned short Service();
65
66 virtual int Type() { return wxSockAddress::IPV4; }
67 virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); }
68 };
69
70 #ifdef ENABLE_IPV6
71 class WXDLLEXPORT wxIPV6address : public wxSockAddress {
72 DECLARE_DYNAMIC_CLASS(wxIPV6address)
73 private:
74 struct sockaddr_in6 *m_addr;
75 public:
76 wxIPV6address();
77 ~wxIPV6address();
78
79 bool Hostname(const wxString& name);
80 bool Hostname(unsigned char addr[16]);
81 bool Service(const wxString& name);
82 bool Service(unsigned short port);
83 bool LocalHost();
84
85 wxString Hostname() const;
86 unsigned short Service() const;
87
88 virtual int Type() { return wxSockAddress::IPV6; }
89 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
90 };
91 #endif
92
93 #if defined(__UNIX__) && !defined(__WXMAC__)
94 #include <sys/socket.h>
95 #ifndef __VMS__
96 # include <sys/un.h>
97 #endif
98
99 class WXDLLEXPORT wxUNIXaddress : public wxSockAddress {
100 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
101 private:
102 struct sockaddr_un *m_addr;
103 public:
104 wxUNIXaddress();
105 ~wxUNIXaddress();
106
107 void Filename(const wxString& name);
108 wxString Filename();
109
110 virtual int Type() { return wxSockAddress::UNIX; }
111 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
112 };
113 #endif
114 // __UNIX__
115
116 #endif
117 // wxUSE_SOCKETS
118
119 #endif
120 // _WX_NETWORK_ADDRESS_H