forked from checkedc/checkedc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_checked.h
153 lines (122 loc) · 4.19 KB
/
socket_checked.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//---------------------------------------------------------------------//
// Bounds-safe interfaces for functions in POSIX socket.h. // //
// //
/////////////////////////////////////////////////////////////////////////
// The Windows environment may not have sys/socket.h
#if defined __has_include_next && __has_include_next(<sys/socket.h>)
#ifdef __checkedc
#pragma CHECKED_SCOPE push
#pragma CHECKED_SCOPE off
#endif
#include_next <sys/socket.h>
#ifdef __checkedc
#pragma CHECKED_SCOPE pop
#endif
#ifdef __checkedc
#ifndef __SOCKET_CHECKED_H
#define __SOCKET_CHECKED_H
#pragma CHECKED_SCOPE push
#pragma CHECKED_SCOPE on
#ifndef __CONST_SOCKADDR_ARG
#define __CONST_SOCKADDR_ARG const struct sockaddr *
#endif
#ifndef __SOCKADDR_ARG
#define __SOCKADDR_ARG struct sockaddr *__restrict
#endif
#ifdef __APPLE__
// Seems not to be a thing for Mac
#define __THROW
#endif
extern int socketpair (int __domain, int __type, int __protocol,
int __fds[2] : itype(int _Checked[2])) __THROW;
/*
extern int bind (
int __fd,
__CONST_SOCKADDR_ARG __addr : itype(_Ptr<const struct sockaddr>),
socklen_t __len)
__THROW;
extern int getsockname (
int __fd,
__SOCKADDR_ARG __addr : itype(_Ptr<struct sockaddr> __restrict),
socklen_t *__restrict __len : itype(_Ptr<socklen_t> __restrict)
) __THROW;
extern int connect (
int __fd,
__CONST_SOCKADDR_ARG __addr : itype(_Ptr<const struct sockaddr>),
socklen_t __len);
extern int getpeername (
int __fd,
__SOCKADDR_ARG __addr : itype(_Ptr<struct sockaddr> __restrict),
socklen_t *__restrict __len : itype(_Ptr<socklen_t> __restrict)
) __THROW;
extern ssize_t send(
int __fd,
const void *__buf : itype(_Array_ptr<const void>) byte_count(__n),
size_t __n, int __flags);
extern ssize_t recv (
int __fd,
void *__buf : itype(_Array_ptr<void>) byte_count(__n),
size_t __n, int __flags);
extern ssize_t sendto (
int __fd,
const void *__buf : itype(_Array_ptr<const void>) byte_count(__n),
size_t __n,
int __flags,
__CONST_SOCKADDR_ARG __addr : itype(_Ptr<const struct sockaddr>),
socklen_t __addr_len);
extern ssize_t recvfrom (
int __fd,
void *__restrict __buf : itype(_Array_ptr<void> __restrict) byte_count(__n),
size_t __n, int __flags,
__SOCKADDR_ARG __addr : itype(_Ptr<struct sockaddr> __restrict),
socklen_t *__restrict __addr_len : itype(_Ptr<socklen_t> __restrict));
extern ssize_t sendmsg (
int __fd,
const struct msghdr *__message : itype(_Ptr<const struct msghdr>),
int __flags);
#ifdef __USE_GNU
extern int sendmmsg (
int __fd,
struct mmsghdr *__vmessages : itype(_Array_ptr<struct mmsghdr>) count(__vlen),
unsigned int __vlen,
int __flags);
#endif
extern ssize_t recvmsg (
int __fd,
struct msghdr *__message : itype(_Ptr<struct msghdr>),
int __flags);
#ifdef __USE_GNU
extern int recvmmsg (
int __fd,
struct mmsghdr *__vmessages : itype(_Array_ptr<struct mmsghdr>) count(__vlen),
unsigned int __vlen,
int __flags,
struct timespec *__tmo : itype(_Ptr<struct timespec>));
#endif
extern int getsockopt (
int __fd, int __level, int __optname,
void *__restrict __optval : itype(_Array_ptr<void> __restrict) byte_count(*__optlen),
socklen_t *__restrict __optlen : itype(_Ptr<socklen_t> __restrict)
) __THROW;
extern int setsockopt (
int __fd, int __level, int __optname,
const void *__optval : itype(_Array_ptr<const void>) byte_count(__optlen),
socklen_t __optlen) __THROW;
extern int accept (
int __fd,
__SOCKADDR_ARG __addr : itype(_Ptr<struct sockaddr> __restrict),
socklen_t *__restrict __addr_len : itype(_Ptr<socklen_t> __restrict));
#ifdef __USE_GNU
extern int accept4 (
int __fd,
__SOCKADDR_ARG __addr : itype(_Ptr<struct sockaddr> __restrict),
socklen_t *__restrict __addr_len : itype(_Ptr<socklen_t> __restrict),
int __flags);
#endif
*/
#pragma CHECKED_SCOPE pop
#endif // guard
#endif // Checked C
#else // doesn't have sys/socket.h
#error "cannot include 'sys/socket_checked.h' because this system does not have the original 'sys/socket.h'"
#endif