]> git.saurik.com Git - wxWidgets.git/blob - include/wx/sckaddr.h
Fix so the Host: header in wxHTTP really works. With virtual hosts it
[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 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 // wihtout knowing the exact address class)
46 virtual wxSockAddress *Clone() const = 0;
47
48 protected:
49 GAddress *m_address;
50 };
51
52 class WXDLLEXPORT wxIPV4address : public wxSockAddress {
53 DECLARE_DYNAMIC_CLASS(wxIPV4address)
54 public:
55 wxIPV4address();
56 wxIPV4address(const wxIPV4address& other);
57 virtual ~wxIPV4address();
58
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();
64 bool AnyAddress();
65
66 wxString Hostname();
67 wxString OrigHostname() { return m_origHostname; }
68 unsigned short Service();
69
70 virtual int Type() { return wxSockAddress::IPV4; }
71 virtual wxSockAddress *Clone() const;
72
73 private:
74 wxString m_origHostname;
75 };
76
77 #ifdef ENABLE_IPV6
78 class WXDLLEXPORT wxIPV6address : public wxSockAddress {
79 DECLARE_DYNAMIC_CLASS(wxIPV6address)
80 private:
81 struct sockaddr_in6 *m_addr;
82 public:
83 wxIPV6address();
84 wxIPV6address(const wxIPV6address& other);
85 virtual ~wxIPV6address();
86
87 bool Hostname(const wxString& name);
88 bool Hostname(unsigned char addr[16]);
89 bool Service(const wxString& name);
90 bool Service(unsigned short port);
91 bool LocalHost();
92
93 wxString Hostname() const;
94 unsigned short Service() const;
95
96 virtual int Type() { return wxSockAddress::IPV6; }
97 virtual wxSockAddress *Clone() const { return new wxIPV6address(*this); }
98 };
99 #endif
100
101 #if defined(__UNIX__) && !defined(__WXMAC__)
102 #include <sys/socket.h>
103 #ifndef __VMS__
104 # include <sys/un.h>
105 #endif
106
107 class WXDLLEXPORT wxUNIXaddress : public wxSockAddress {
108 DECLARE_DYNAMIC_CLASS(wxUNIXaddress)
109 private:
110 struct sockaddr_un *m_addr;
111 public:
112 wxUNIXaddress();
113 wxUNIXaddress(const wxUNIXaddress& other);
114 virtual ~wxUNIXaddress();
115
116 void Filename(const wxString& name);
117 wxString Filename();
118
119 virtual int Type() { return wxSockAddress::UNIX; }
120 virtual wxSockAddress *Clone() const { return new wxUNIXaddress(*this); }
121 };
122 #endif
123 // __UNIX__
124
125 #endif
126 // wxUSE_SOCKETS
127
128 #endif
129 // _WX_NETWORK_ADDRESS_H