Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
stunsocket.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 #ifndef STUNSOCKET_H
18 #define STUNSOCKET_H
19 
20 
21 
23 {
24 private:
25  int _sock;
29 
31  void operator=(const CStunSocket&) {;}
32 
33  HRESULT InitCommon(int socktype, const CSocketAddress& addrlocal, SocketRole role, bool fSetReuseFlag);
34 
35  void Reset();
36 
37  HRESULT EnablePktInfoImpl(int level, int option1, int option2, bool fEnable);
38  HRESULT EnablePktInfo_IPV4(bool fEnable);
39  HRESULT EnablePktInfo_IPV6(bool fEnable);
40 
41  HRESULT SetV6Only(int sock);
42 
43 public:
44 
45  CStunSocket();
46  ~CStunSocket();
47 
48  void Close();
49 
50  bool IsValid();
51 
52  HRESULT Attach(int sock);
53  int Detach();
54 
55  int GetSocketHandle() const;
56  const CSocketAddress& GetLocalAddress() const;
57  const CSocketAddress& GetRemoteAddress() const;
58 
59  SocketRole GetRole() const;
60  void SetRole(SocketRole role);
61 
62  HRESULT EnablePktInfoOption(bool fEnable);
63  HRESULT SetNonBlocking(bool fEnable);
64 
65 
66  void UpdateAddresses();
67 
68  HRESULT UDPInit(const CSocketAddress& local, SocketRole role);
69  HRESULT TCPInit(const CSocketAddress& local, SocketRole role, bool fSetReuseFlag);
70 };
71 
72 typedef boost::shared_ptr<CStunSocket> CRefCountedStunSocket;
73 
74 
75 
76 #endif /* STUNSOCKET_H */
77 
HRESULT EnablePktInfoImpl(int level, int option1, int option2, bool fEnable)
Definition: stunsocket.cpp:119
void UpdateAddresses()
Definition: stunsocket.cpp:245
void operator=(const CStunSocket &)
Definition: stunsocket.h:31
void Close()
Definition: stunsocket.cpp:41
void SetRole(SocketRole role)
Definition: stunsocket.cpp:104
CSocketAddress _addrlocal
Definition: stunsocket.h:26
HRESULT SetV6Only(int sock)
Definition: stunsocket.cpp:196
HRESULT EnablePktInfo_IPV4(bool fEnable)
Definition: stunsocket.cpp:145
int GetSocketHandle() const
Definition: stunsocket.cpp:82
HRESULT Attach(int sock)
Definition: stunsocket.cpp:56
SocketRole GetRole() const
Definition: stunsocket.cpp:98
SocketRole
Definition: socketrole.h:22
int32_t HRESULT
Definition: hresult.h:22
int Detach()
Definition: stunsocket.cpp:75
bool IsValid()
Definition: stunsocket.cpp:51
HRESULT EnablePktInfoOption(bool fEnable)
Definition: stunsocket.cpp:179
void Reset()
Definition: stunsocket.cpp:33
HRESULT InitCommon(int socktype, const CSocketAddress &addrlocal, SocketRole role, bool fSetReuseFlag)
Definition: stunsocket.cpp:276
CSocketAddress _addrremote
Definition: stunsocket.h:27
const CSocketAddress & GetRemoteAddress() const
Definition: stunsocket.cpp:92
HRESULT EnablePktInfo_IPV6(bool fEnable)
Definition: stunsocket.cpp:162
boost::shared_ptr< CStunSocket > CRefCountedStunSocket
Definition: stunsocket.h:72
HRESULT UDPInit(const CSocketAddress &local, SocketRole role)
Definition: stunsocket.cpp:322
HRESULT TCPInit(const CSocketAddress &local, SocketRole role, bool fSetReuseFlag)
Definition: stunsocket.cpp:327
HRESULT SetNonBlocking(bool fEnable)
Definition: stunsocket.cpp:217
CStunSocket(const CStunSocket &)
Definition: stunsocket.h:30
const CSocketAddress & GetLocalAddress() const
Definition: stunsocket.cpp:87
SocketRole _role
Definition: stunsocket.h:28