]> git.tdb.fi Git - libs/net.git/blob - source/net/constants.cpp
Implement an asynchronous name resolver class
[libs/net.git] / source / net / constants.cpp
1 #include <stdexcept>
2 #ifdef WIN32
3 #include <winsock2.h>
4 #else
5 #include <sys/socket.h>
6 #endif
7 #include "constants.h"
8
9 using namespace std;
10
11 namespace Msp {
12 namespace Net {
13
14 int family_to_sys(Family f)
15 {
16         switch(f)
17         {
18         case UNSPEC: return AF_UNSPEC;
19         case INET:   return AF_INET;
20         case INET6:  return AF_INET6;
21         case UNIX:   return AF_UNIX;
22         default: throw invalid_argument("family_to_sys");
23         }
24 }
25
26 Family family_from_sys(int f)
27 {
28         switch(f)
29         {
30         case AF_UNSPEC: return UNSPEC;
31         case AF_INET:   return INET;
32         case AF_INET6:  return INET6;
33         case AF_UNIX:   return UNIX;
34         default: throw invalid_argument("family_from_sys");
35         }
36 }
37
38 } // namespace Net
39 } // namespace Msp