1 /* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2019 Couchbase, Inc.
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 /*
19  * Header including C socket portability declarations
20  */
21 #pragma once
22 
23 #include <platform/dynamic.h>
24 #include <platform/visibility.h>
25 
26 #include <stdint.h>
27 
28 #ifdef WIN32
29 #include <winsock2.h>
30 #endif
31 
32 #ifdef __sun
33 #include <arpa/inet.h>
34 #endif
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef WIN32
41 #define CB_DONT_NEED_BYTEORDER 1
42 struct iovec {
43     size_t iov_len;
44     void* iov_base;
45 };
46 
47 #define IOV_MAX 1024
48 
49 struct msghdr {
50     void* msg_name; /* Socket name */
51     int msg_namelen; /* Length of name */
52     struct iovec* msg_iov; /* Data blocks */
53     int msg_iovlen; /* Number of blocks */
54 };
55 
56 PLATFORM_PUBLIC_API
57 int sendmsg(SOCKET sock, const struct msghdr* msg, int flags);
58 
59 /**
60  * Initialize the winsock library
61  */
62 PLATFORM_PUBLIC_API
63 void cb_initialize_sockets(void);
64 #else // WIN32
65 #define cb_initialize_sockets()
66 #endif // WIN32
67 
68 #ifndef CB_DONT_NEED_BYTEORDER
69 PLATFORM_PUBLIC_API
70 uint64_t ntohll(uint64_t);
71 
72 PLATFORM_PUBLIC_API
73 uint64_t htonll(uint64_t);
74 #endif
75 
76 #ifdef __cplusplus
77 }
78 #endif
79