-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtdsocket.icc
More file actions
250 lines (199 loc) · 6.93 KB
/
tdsocket.icc
File metadata and controls
250 lines (199 loc) · 6.93 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* $Id$
*
* SocketAPI implementation for the sctplib.
* Copyright (C) 2005-2026 by Thomas Dreibholz
*
* Realized in co-operation between
* - Siemens AG
* - University of Duisburg-Essen, Institute for Experimental Mathematics
* - Münster University of Applied Sciences, Burgsteinfurt
*
* Acknowledgement
* This work was partially funded by the Bundesministerium fuer Bildung und
* Forschung (BMBF) of the Federal Republic of Germany (Foerderkennzeichen 01AK045).
* The authors alone are responsible for the contents.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Contact: discussion@sctp.de
* thomas.dreibholz@gmail.com
* tuexen@fh-muenster.de
*
* Purpose: Socket Implementation
*
*/
#ifndef TDSOCKET_ICC
#define TDSOCKET_ICC
#include "tdsocket.h"
#include "ext_socket.h"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
// ###### Get socket type ###################################################
inline integer Socket::getType() const
{
return(Type);
}
// ###### Get socket family #################################################
inline integer Socket::getFamily() const
{
return(Family);
}
// ###### Get socket protocol ###############################################
inline integer Socket::getProtocol() const
{
return(Protocol);
}
// ###### Check, if socket is ready #########################################
inline bool Socket::ready() const
{
return(SocketDescriptor >= 0);
}
// ###### Get flow info #####################################################
inline card32 Socket::getSendFlowLabel() const
{
return(SendFlow & IPV6_FLOWINFO_FLOWLABEL);
}
// ###### Get traffic class #################################################
inline card8 Socket::getSendTrafficClass() const
{
return((SendFlow & IPV6_FLOWINFO_PRIORITY) >> 20);
}
// ###### Get flow info #####################################################
inline card32 Socket::getReceivedFlowLabel() const
{
return(ReceivedFlow & IPV6_FLOWINFO_FLOWLABEL);
}
// ###### Get traffic class #################################################
inline card8 Socket::getReceivedTrafficClass() const
{
return((ReceivedFlow & IPV6_FLOWINFO_PRIORITY) >> 20);
}
// ###### Socket control ####################################################
inline integer Socket::fcntl(const integer cmd, long arg)
{
const integer result = ext_fcntl(SocketDescriptor,cmd,arg);
if(result != 0) {
LastError = errno;
}
return(result);
}
// ###### Socket control ####################################################
inline integer Socket::fcntl(const integer cmd,
struct flock* lock)
{
const integer result = ext_fcntl(SocketDescriptor,cmd,lock);
if(result != 0) {
LastError = errno;
}
return(result);
}
// ###### Socket control ####################################################
inline integer Socket::ioctl(const integer request, const void* argp)
{
const integer result = ext_ioctl(SocketDescriptor,request,argp);
if(result != 0) {
LastError = errno;
}
return(result);
}
// ###### Wrapper for getsockopt() ##########################################
inline integer Socket::getSocketOption(const cardinal level,
const cardinal optionNumber,
void* optionValue,
socklen_t* optionLength)
{
const integer result = ext_getsockopt(SocketDescriptor,
level,optionNumber,optionValue,optionLength);
if(result != 0) {
LastError = errno;
}
return(result);
}
// ###### Wrapper for setsockopt() ##########################################
inline integer Socket::setSocketOption(const cardinal level,
const cardinal optionNumber,
const void* optionValue,
const socklen_t optionLength)
{
const integer result = ext_setsockopt(SocketDescriptor,
level,optionNumber,optionValue,optionLength);
if(result != 0) {
LastError = errno;
}
return(result);
}
// ###### Get system's socket descriptor ####################################
inline int Socket::getSystemSocketDescriptor() const
{
return(SocketDescriptor);
}
// ###### Get last error ####################################################
inline integer Socket::getLastError()
{
const integer error = LastError;
LastError = 0;
return(error);
}
// ###### Receive data ######################################################
inline ssize_t Socket::receive(void* buffer,
const size_t length,
integer& flags)
{
char socketAddressBuffer[SocketAddress::MaxSockLen];
socklen_t socketAddressLength = SocketAddress::MaxSockLen;
ssize_t result = recvFrom(SocketDescriptor, buffer,
length, flags,
(sockaddr*)&socketAddressBuffer,
&socketAddressLength);
if(result < 0) {
LastError = errno;
result = -LastError;
}
return(result);
}
// ###### Read data #########################################################
inline ssize_t Socket::read(void* buffer, const size_t length)
{
ssize_t result = ext_read(SocketDescriptor,buffer,length);
if(result < 0) {
LastError = errno;
result = -LastError;
}
return(result);
}
// ###### Write data ########################################################
inline ssize_t Socket::write(const void* buffer,
const size_t length)
{
ssize_t result = ext_write(SocketDescriptor,buffer,length);
if(result < 0) {
LastError = errno;
result = -LastError;
}
return(result);
}
// ###### Add multicast membership ##########################################
bool Socket::addMulticastMembership(const SocketAddress& address,
const char* interface)
{
return(multicastMembership(address,interface,true) == 0);
}
// ###### Drop multicast membership #########################################
bool Socket::dropMulticastMembership(const SocketAddress& address,
const char* interface)
{
return(multicastMembership(address,interface,false) == 0);
}
#endif