WSAStartup.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace AppSecInc
4 {
5  namespace TcpIp
6  {
18  {
19  public:
21  const static int default_major_version = 2;
23  const static int default_minor_version = 1;
26 
27  CWSAStartup();
28  explicit CWSAStartup(WORD version);
29  CWSAStartup(int major, int minor);
30  ~CWSAStartup();
31 
32  bool wasRequestedVersionNegotiated() const;
33  bool initialized() const;
34 
35  WORD negotiatedVersion() const;
38  void negotiatedVersion(BYTE& major, BYTE& minor) const;
39  void negotiatedVersion(int& major, int& minor) const;
40 
41  WORD highestSupportedVersion() const;
42  void highestSupportedVersion(WORD& major, WORD& minor) const;
43  void highestSupportedVersion(int& major, int& minor) const;
44 
45  int ErrorCode() const;
46  std::wstring ErrorMessage() const;
47  const WSADATA& WsaData() const;
48 
49  static std::wstring ErrorMessage(int errcode);
50  static BYTE majorVersion(WORD version) { return LOBYTE(version); }
51  static BYTE minorVersion(WORD version) { return HIBYTE(version); }
52  static WORD packVersion(BYTE major, BYTE minor) { return MAKEWORD(major, minor); }
53  static WORD packVersion(int major, int minor) { return MAKEWORD(major, minor); }
54 
55  private:
56  void CWSAStartup::init();
57 
58  CWSAStartup(const CWSAStartup&);
59  CWSAStartup& operator=(const CWSAStartup&);
60 
61  bool m_bInitialized;
62  bool m_bVersionSupported;
63  int m_rc;
64  BYTE m_requestedMajorVersion;
65  BYTE m_requestedMinorVersion;
66  WSADATA m_wsadata;
67  };
68  }
69 }
CWSAStartup()
Calls WSAStartup to initialize Winsock for the default version: 2.1.
Definition: WSAStartup.cpp:8
static WORD packVersion(BYTE major, BYTE minor)
Definition: WSAStartup.h:52
std::wstring ErrorMessage() const
returns the error message text if there was an error, or an empty string if there was no error...
Definition: WSAStartup.cpp:136
bool initialized() const
returns true if Winsock was successfully initialized, false otherwise.
Definition: WSAStartup.cpp:67
Definition: WSAStartup.h:17
static BYTE minorVersion(WORD version)
Definition: WSAStartup.h:51
BYTE negotiatedMinorVersion() const
Definition: WSAStartup.cpp:106
~CWSAStartup()
Calls WSACleanup, if necessary.
Definition: WSAStartup.cpp:53
static WORD packVersion(int major, int minor)
Definition: WSAStartup.h:53
const WSADATA & WsaData() const
Definition: WSAStartup.cpp:124
WORD negotiatedVersion() const
returns the loaded version of Winsock support.
Definition: WSAStartup.cpp:96
BYTE negotiatedMajorVersion() const
Definition: WSAStartup.cpp:101
bool wasRequestedVersionNegotiated() const
returns true if Winsock was successfully initialized to use the requested version, false otherwise.
Definition: WSAStartup.cpp:61
int ErrorCode() const
returns the error code returnd from WSAStartup, 0 on success.
Definition: WSAStartup.cpp:130
static BYTE majorVersion(WORD version)
Definition: WSAStartup.h:50
WORD highestSupportedVersion() const
Definition: WSAStartup.cpp:76
static const int default_major_version
The application is written and built for this verion of Winsock.
Definition: WSAStartup.h:22
const long BYTE
Definition: File.h:147
static const int default_minor_version
Definition: WSAStartup.h:23
static const int default_version
Definition: WSAStartup.h:24


© Application Security Inc. - All Rights Reserved http://msiext.codeplex.com