]>
Commit | Line | Data |
---|---|---|
f4ada568 GL |
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 | ///////////////////////////////////////////////////////////////////////////// | |
2df7be7f | 11 | |
f4ada568 GL |
12 | #ifndef _WX_NETWORK_ADDRESS_H |
13 | #define _WX_NETWORK_ADDRESS_H | |
14 | ||
2df7be7f RR |
15 | #ifdef __GNUG__ |
16 | #pragma interface | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_SOCKETS | |
22 | ||
2df7be7f | 23 | #include "wx/string.h" |
65ccd2b8 | 24 | #include "wx/gsocket.h" |
a324a7bc | 25 | |
f4ada568 GL |
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 | ||
a324a7bc | 32 | wxSockAddress(); |
1539c2f5 | 33 | wxSockAddress(const wxSockAddress& other); |
a324a7bc GL |
34 | virtual ~wxSockAddress(); |
35 | ||
1539c2f5 VZ |
36 | wxSockAddress& operator=(const wxSockAddress& other); |
37 | ||
a324a7bc GL |
38 | virtual void Clear(); |
39 | virtual int Type() = 0; | |
f4ada568 | 40 | |
a324a7bc GL |
41 | GAddress *GetAddress() const { return m_address; } |
42 | void SetAddress(GAddress *address); | |
f4ada568 | 43 | |
acd15a3f VZ |
44 | // we need to be able to create copies of the addresses polymorphically (i.e. |
45 | // wihtout knowing the exact address class) | |
46 | virtual wxSockAddress *Clone() const = 0; | |
f4ada568 | 47 | |
a324a7bc GL |
48 | protected: |
49 | GAddress *m_address; | |
f4ada568 GL |
50 | }; |
51 | ||
52 | class WXDLLEXPORT wxIPV4address : public wxSockAddress { | |
53 | DECLARE_DYNAMIC_CLASS(wxIPV4address) | |
f4ada568 GL |
54 | public: |
55 | wxIPV4address(); | |
1539c2f5 | 56 | wxIPV4address(const wxIPV4address& other); |
f4ada568 GL |
57 | virtual ~wxIPV4address(); |
58 | ||
a324a7bc GL |
59 | bool Hostname(const wxString& name); |
60 | bool Hostname(unsigned long addr); | |
61 | bool Service(const wxString& name); | |
62 | bool Service(unsigned short port); | |
63 | bool LocalHost(); | |
636c47a7 | 64 | bool AnyAddress(); |
f4ada568 GL |
65 | |
66 | wxString Hostname(); | |
67 | unsigned short Service(); | |
68 | ||
acd15a3f VZ |
69 | virtual int Type() { return wxSockAddress::IPV4; } |
70 | virtual wxSockAddress *Clone() const { return new wxIPV4address(*this); } | |
f4ada568 GL |
71 | }; |
72 | ||
73 | #ifdef ENABLE_IPV6 | |
74 | class WXDLLEXPORT wxIPV6address : public wxSockAddress { | |
75 | DECLARE_DYNAMIC_CLASS(wxIPV6address) | |
76 | private: | |
77 | struct sockaddr_in6 *m_addr; | |
78 | public: | |
79 | wxIPV6address(); | |
1539c2f5 VZ |
80 | wxIPV6address(const wxIPV6address& other); |
81 | virtual ~wxIPV6address(); | |
f4ada568 | 82 | |
f4ada568 GL |
83 | bool Hostname(const wxString& name); |
84 | bool Hostname(unsigned char addr[16]); | |
85 | bool Service(const wxString& name); | |
86 | bool Service(unsigned short port); | |
87 | bool LocalHost(); | |
88 | ||
89 | wxString Hostname() const; | |
90 | unsigned short Service() const; | |
91 | ||
acd15a3f VZ |
92 | virtual int Type() { return wxSockAddress::IPV6; } |
93 | virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); } | |
f4ada568 GL |
94 | }; |
95 | #endif | |
96 | ||
f11bdd03 | 97 | #if defined(__UNIX__) && !defined(__WXMAC__) |
fd9811b1 | 98 | #include <sys/socket.h> |
e1c70641 JJ |
99 | #ifndef __VMS__ |
100 | # include <sys/un.h> | |
101 | #endif | |
f4ada568 GL |
102 | |
103 | class WXDLLEXPORT wxUNIXaddress : public wxSockAddress { | |
104 | DECLARE_DYNAMIC_CLASS(wxUNIXaddress) | |
105 | private: | |
106 | struct sockaddr_un *m_addr; | |
107 | public: | |
108 | wxUNIXaddress(); | |
1539c2f5 VZ |
109 | wxUNIXaddress(const wxUNIXaddress& other); |
110 | virtual ~wxUNIXaddress(); | |
f4ada568 | 111 | |
f4ada568 GL |
112 | void Filename(const wxString& name); |
113 | wxString Filename(); | |
114 | ||
acd15a3f VZ |
115 | virtual int Type() { return wxSockAddress::UNIX; } |
116 | virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); } | |
f4ada568 GL |
117 | }; |
118 | #endif | |
2df7be7f | 119 | // __UNIX__ |
f4ada568 GL |
120 | |
121 | #endif | |
2df7be7f | 122 | // wxUSE_SOCKETS |
65ccd2b8 | 123 | |
2df7be7f RR |
124 | #endif |
125 | // _WX_NETWORK_ADDRESS_H |