--- /dev/null
+#include <stdexcept>
+#ifdef WIN32
+#include <winsock2.h>
+#else
+#include <sys/socket.h>
+#endif
+#include "constants.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Net {
+
+int family_to_sys(Family f)
+{
+ switch(f)
+ {
+ case UNSPEC: return AF_UNSPEC;
+ case INET: return AF_INET;
+ case INET6: return AF_INET6;
+ case UNIX: return AF_UNIX;
+ default: throw invalid_argument("family_to_sys");
+ }
+}
+
+Family family_from_sys(int f)
+{
+ switch(f)
+ {
+ case AF_UNSPEC: return UNSPEC;
+ case AF_INET: return INET;
+ case AF_INET6: return INET6;
+ case AF_UNIX: return UNIX;
+ default: throw invalid_argument("family_from_sys");
+ }
+}
+
+} // namespace Net
+} // namespace Msp
#ifndef MSP_NET_CONSTANTS_H_
#define MSP_NET_CONSTANTS_H_
-#ifdef WIN32
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#endif
-
namespace Msp {
namespace Net {
enum Family
{
- UNSPEC = AF_UNSPEC,
- INET = AF_INET,
- INET6 = AF_INET6,
- UNIF = AF_UNIX
+ UNSPEC,
+ INET,
+ INET6,
+ UNIX
};
+int family_to_sys(Family);
+Family family_from_sys(int);
+
} // namespace Net
} // namespace Msp
host = s;
}
- addrinfo hints = {0, family, 0, 0, 0, 0, 0, 0};
+ addrinfo hints = { 0, family_to_sys(family), 0, 0, 0, 0, 0, 0 };
addrinfo *res;
const char *chost = (host.empty() ? 0 : host.c_str());
const char *cserv = (serv.empty() ? 0 : serv.c_str());
local_addr(0),
peer_addr(0)
{
- priv->handle = socket(af, type, proto);
+ priv->handle = socket(family_to_sys(af), type, proto);
#ifdef WIN32
*priv->event = CreateEvent(0, false, false, 0);