]>
Commit | Line | Data |
---|---|---|
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 | wxSockAddress(const wxSockAddress& other); | |
34 | virtual ~wxSockAddress(); | |
35 | ||
36 | wxSockAddress& operator=(const wxSockAddress& other); | |
37 | ||
38 | virtual void Clear(); | |
39 | virtual int Type() = 0; | |
40 | ||
41 | GAddress *GetAddress() const { return m_address; } | |
42 | void SetAddress(GAddress *address); | |
43 | ||
44 | // we need to be able to create copies of the addresses polymorphically (i.e. | |
45 | // without knowing the exact address class) | |
46 | virtual wxSockAddress *Clone() const = 0; | |
47 | ||
48 | protected: | |
49 | GAddress *m_address; | |
50 | ||
51 | private: | |
52 | void Init(); | |
53 | }; | |
54 | ||
55 | class WXDLLEXPORT wxIPV4address : public wxSockAddress { | |
56 | DECLARE_DYNAMIC_CLASS(wxIPV4address) | |
57 | public: | |
58 | wxIPV4address(); | |
59 | wxIPV4address(const wxIPV4address& other); | |
60 | virtual ~wxIPV4address(); | |
61 | ||
62 | bool Hostname(const wxString& name); | |
63 | bool Hostname(unsigned long addr); | |
64 | bool Service(const wxString& name); | |
65 | bool Service(unsigned short port); | |
66 | bool LocalHost(); | |
67 | bool AnyAddress(); | |
68 | ||
69 | wxString Hostname(); | |
70 | wxString OrigHostname() { return m_origHostname; } | |
71 | unsigned short Service(); | |
72 | ||
73 | virtual int Type() { return wxSockAddress::IPV4; } | |
74 | virtual wxSockAddress *Clone() const; | |
75 | ||
76 | private: | |
77 | wxString m_origHostname; | |
78 | }; | |
79 | ||
80 | #ifdef ENABLE_IPV6 | |
81 | class WXDLLEXPORT wxIPV6address : public wxSockAddress { | |
82 | DECLARE_DYNAMIC_CLASS(wxIPV6address) | |
83 | private: | |
84 | struct sockaddr_in6 *m_addr; | |
85 | public: | |
86 | wxIPV6address(); | |
87 | wxIPV6address(const wxIPV6address& other); | |
88 | virtual ~wxIPV6address(); | |
89 | ||
90 | bool Hostname(const wxString& name); | |
91 | bool Hostname(unsigned char addr[16]); | |
92 | bool Service(const wxString& name); | |
93 | bool Service(unsigned short port); | |
94 | bool LocalHost(); | |
95 | ||
96 | wxString Hostname() const; | |
97 | unsigned short Service() const; | |
98 | ||
99 | virtual int Type() { return wxSockAddress::IPV6; } | |
100 | virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); } | |
101 | }; | |
102 | #endif | |
103 | ||
104 | #if defined(__UNIX__) && !defined(__WXMAC__) | |
105 | #include <sys/socket.h> | |
106 | #ifndef __VMS__ | |
107 | # include <sys/un.h> | |
108 | #endif | |
109 | ||
110 | class WXDLLEXPORT wxUNIXaddress : public wxSockAddress { | |
111 | DECLARE_DYNAMIC_CLASS(wxUNIXaddress) | |
112 | private: | |
113 | struct sockaddr_un *m_addr; | |
114 | public: | |
115 | wxUNIXaddress(); | |
116 | wxUNIXaddress(const wxUNIXaddress& other); | |
117 | virtual ~wxUNIXaddress(); | |
118 | ||
119 | void Filename(const wxString& name); | |
120 | wxString Filename(); | |
121 | ||
122 | virtual int Type() { return wxSockAddress::UNIX; } | |
123 | virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); } | |
124 | }; | |
125 | #endif | |
126 | // __UNIX__ | |
127 | ||
128 | #endif | |
129 | // wxUSE_SOCKETS | |
130 | ||
131 | #endif | |
132 | // _WX_NETWORK_ADDRESS_H |