]>
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 | #if defined(__WINDOWS__) && defined(WXSOCK_INTERNAL) | |
24 | #include <winsock.h> | |
25 | ||
26 | #elif defined(__UNIX__) && defined(WXSOCK_INTERNAL) | |
27 | ||
28 | #include <sys/types.h> | |
29 | #include <sys/socket.h> | |
30 | #include <netinet/in.h> | |
31 | #endif | |
32 | ||
33 | #include "wx/string.h" | |
34 | ||
35 | class WXDLLEXPORT wxSockAddress : public wxObject { | |
36 | DECLARE_ABSTRACT_CLASS(wxSockAddress) | |
37 | public: | |
38 | typedef enum { IPV4=1, IPV6=2, UNIX=3 } Addr; | |
39 | ||
40 | wxSockAddress() {}; | |
41 | virtual ~wxSockAddress() {}; | |
42 | ||
43 | virtual void Clear() = 0; | |
44 | ||
45 | virtual void Build(struct sockaddr*& addr, size_t& len) = 0; | |
46 | virtual void Disassemble(struct sockaddr *addr, size_t len) = 0; | |
47 | virtual int SockAddrLen() = 0; | |
48 | ||
49 | virtual int GetFamily() = 0; | |
50 | virtual int Type() = 0; | |
51 | }; | |
52 | ||
53 | class WXDLLEXPORT wxIPV4address : public wxSockAddress { | |
54 | DECLARE_DYNAMIC_CLASS(wxIPV4address) | |
55 | private: | |
56 | struct sockaddr_in *m_addr; | |
57 | public: | |
58 | wxIPV4address(); | |
59 | virtual ~wxIPV4address(); | |
60 | ||
61 | virtual void Clear(); | |
62 | // const wxSockAddress& operator =(const wxSockAddress& addr); | |
63 | ||
64 | virtual bool Hostname(const wxString& name); | |
65 | virtual bool Hostname(unsigned long addr); | |
66 | virtual bool Service(const wxString& name); | |
67 | virtual bool Service(unsigned short port); | |
68 | virtual bool LocalHost(); | |
69 | ||
70 | wxString Hostname(); | |
71 | unsigned short Service(); | |
72 | ||
73 | void Build(struct sockaddr*& addr, size_t& len); | |
74 | void Disassemble(struct sockaddr *addr, size_t len); | |
75 | ||
76 | inline int SockAddrLen(); | |
77 | inline int GetFamily(); | |
78 | inline int Type() { return wxSockAddress::IPV4; } | |
79 | }; | |
80 | ||
81 | #ifdef ENABLE_IPV6 | |
82 | class WXDLLEXPORT wxIPV6address : public wxSockAddress { | |
83 | DECLARE_DYNAMIC_CLASS(wxIPV6address) | |
84 | private: | |
85 | struct sockaddr_in6 *m_addr; | |
86 | public: | |
87 | wxIPV6address(); | |
88 | ~wxIPV6address(); | |
89 | ||
90 | void Clear(); | |
91 | // const wxSockAddress& operator =(const wxSockAddress& addr); | |
92 | ||
93 | bool Hostname(const wxString& name); | |
94 | bool Hostname(unsigned char addr[16]); | |
95 | bool Service(const wxString& name); | |
96 | bool Service(unsigned short port); | |
97 | bool LocalHost(); | |
98 | ||
99 | wxString Hostname() const; | |
100 | unsigned short Service() const; | |
101 | ||
102 | void Build(struct sockaddr*& addr, size_t& len); | |
103 | void Disassemble(struct sockaddr *addr, size_t len); | |
104 | ||
105 | inline int SockAddrLen(); | |
106 | inline int GetFamily(); | |
107 | inline int Type() { return wxSockAddress::IPV6; } | |
108 | }; | |
109 | #endif | |
110 | ||
111 | #ifdef __UNIX__ | |
112 | #include <sys/un.h> | |
113 | ||
114 | class WXDLLEXPORT wxUNIXaddress : public wxSockAddress { | |
115 | DECLARE_DYNAMIC_CLASS(wxUNIXaddress) | |
116 | private: | |
117 | struct sockaddr_un *m_addr; | |
118 | public: | |
119 | wxUNIXaddress(); | |
120 | ~wxUNIXaddress(); | |
121 | ||
122 | void Clear(); | |
123 | // const wxSockAddress& operator =(const wxSockAddress& addr); | |
124 | ||
125 | void Filename(const wxString& name); | |
126 | wxString Filename(); | |
127 | ||
128 | void Build(struct sockaddr*& addr, size_t& len); | |
129 | void Disassemble(struct sockaddr *addr, size_t len); | |
130 | ||
131 | inline int SockAddrLen(); | |
132 | inline int GetFamily(); | |
133 | inline int Type() { return wxSockAddress::UNIX; } | |
134 | }; | |
135 | #endif | |
136 | // __UNIX__ | |
137 | ||
138 | #endif | |
139 | // wxUSE_SOCKETS | |
140 | ||
141 | #endif | |
142 | // _WX_NETWORK_ADDRESS_H |