sl@0
|
1 |
/* crypto/bio/bio_dgram.c */
|
sl@0
|
2 |
/*
|
sl@0
|
3 |
* DTLS implementation written by Nagendra Modadugu
|
sl@0
|
4 |
* (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
|
sl@0
|
5 |
*/
|
sl@0
|
6 |
/* ====================================================================
|
sl@0
|
7 |
* Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
10 |
* modification, are permitted provided that the following conditions
|
sl@0
|
11 |
* are met:
|
sl@0
|
12 |
*
|
sl@0
|
13 |
* 1. Redistributions of source code must retain the above copyright
|
sl@0
|
14 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
17 |
* notice, this list of conditions and the following disclaimer in
|
sl@0
|
18 |
* the documentation and/or other materials provided with the
|
sl@0
|
19 |
* distribution.
|
sl@0
|
20 |
*
|
sl@0
|
21 |
* 3. All advertising materials mentioning features or use of this
|
sl@0
|
22 |
* software must display the following acknowledgment:
|
sl@0
|
23 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
24 |
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
|
sl@0
|
25 |
*
|
sl@0
|
26 |
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
sl@0
|
27 |
* endorse or promote products derived from this software without
|
sl@0
|
28 |
* prior written permission. For written permission, please contact
|
sl@0
|
29 |
* openssl-core@OpenSSL.org.
|
sl@0
|
30 |
*
|
sl@0
|
31 |
* 5. Products derived from this software may not be called "OpenSSL"
|
sl@0
|
32 |
* nor may "OpenSSL" appear in their names without prior written
|
sl@0
|
33 |
* permission of the OpenSSL Project.
|
sl@0
|
34 |
*
|
sl@0
|
35 |
* 6. Redistributions of any form whatsoever must retain the following
|
sl@0
|
36 |
* acknowledgment:
|
sl@0
|
37 |
* "This product includes software developed by the OpenSSL Project
|
sl@0
|
38 |
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
|
sl@0
|
39 |
*
|
sl@0
|
40 |
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
sl@0
|
41 |
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
42 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
sl@0
|
43 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
sl@0
|
44 |
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
sl@0
|
45 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
sl@0
|
46 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
sl@0
|
47 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
sl@0
|
49 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
sl@0
|
50 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
sl@0
|
51 |
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
sl@0
|
52 |
* ====================================================================
|
sl@0
|
53 |
*
|
sl@0
|
54 |
* This product includes cryptographic software written by Eric Young
|
sl@0
|
55 |
* (eay@cryptsoft.com). This product includes software written by Tim
|
sl@0
|
56 |
* Hudson (tjh@cryptsoft.com).
|
sl@0
|
57 |
*
|
sl@0
|
58 |
*/
|
sl@0
|
59 |
|
sl@0
|
60 |
/*
|
sl@0
|
61 |
© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
|
sl@0
|
62 |
*/
|
sl@0
|
63 |
|
sl@0
|
64 |
#ifndef OPENSSL_NO_DGRAM
|
sl@0
|
65 |
|
sl@0
|
66 |
#include <stdio.h>
|
sl@0
|
67 |
#include <errno.h>
|
sl@0
|
68 |
#define USE_SOCKETS
|
sl@0
|
69 |
#include "cryptlib.h"
|
sl@0
|
70 |
|
sl@0
|
71 |
#include <openssl/bio.h>
|
sl@0
|
72 |
#if (defined(SYMBIAN) && (defined(__WINSCW__) || defined(__WINS__)))
|
sl@0
|
73 |
#include "libcrypto_wsd_macros.h"
|
sl@0
|
74 |
#include "libcrypto_wsd.h"
|
sl@0
|
75 |
#endif
|
sl@0
|
76 |
|
sl@0
|
77 |
#define IP_MTU 14 /* linux is lame */
|
sl@0
|
78 |
|
sl@0
|
79 |
#ifdef WATT32
|
sl@0
|
80 |
#define sock_write SockWrite /* Watt-32 uses same names */
|
sl@0
|
81 |
#define sock_read SockRead
|
sl@0
|
82 |
#define sock_puts SockPuts
|
sl@0
|
83 |
#endif
|
sl@0
|
84 |
|
sl@0
|
85 |
static int dgram_write(BIO *h, const char *buf, int num);
|
sl@0
|
86 |
static int dgram_read(BIO *h, char *buf, int size);
|
sl@0
|
87 |
static int dgram_puts(BIO *h, const char *str);
|
sl@0
|
88 |
static long dgram_ctrl(BIO *h, int cmd, long arg1, void *arg2);
|
sl@0
|
89 |
static int dgram_new(BIO *h);
|
sl@0
|
90 |
static int dgram_free(BIO *data);
|
sl@0
|
91 |
static int dgram_clear(BIO *bio);
|
sl@0
|
92 |
|
sl@0
|
93 |
int BIO_dgram_should_retry(int s);
|
sl@0
|
94 |
|
sl@0
|
95 |
#ifndef EMULATOR
|
sl@0
|
96 |
static BIO_METHOD methods_dgramp=
|
sl@0
|
97 |
{
|
sl@0
|
98 |
BIO_TYPE_DGRAM,
|
sl@0
|
99 |
"datagram socket",
|
sl@0
|
100 |
dgram_write,
|
sl@0
|
101 |
dgram_read,
|
sl@0
|
102 |
dgram_puts,
|
sl@0
|
103 |
NULL, /* dgram_gets, */
|
sl@0
|
104 |
dgram_ctrl,
|
sl@0
|
105 |
dgram_new,
|
sl@0
|
106 |
dgram_free,
|
sl@0
|
107 |
NULL,
|
sl@0
|
108 |
};
|
sl@0
|
109 |
#else
|
sl@0
|
110 |
GET_STATIC_VAR_FROM_TLS(methods_dgramp,bss_dgram,BIO_METHOD)
|
sl@0
|
111 |
#define methods_dgramp (*GET_WSD_VAR_NAME(methods_dgramp,bss_dgram,s)())
|
sl@0
|
112 |
const BIO_METHOD temp_s_methods_dgramp=
|
sl@0
|
113 |
{
|
sl@0
|
114 |
BIO_TYPE_DGRAM,
|
sl@0
|
115 |
"datagram socket",
|
sl@0
|
116 |
dgram_write,
|
sl@0
|
117 |
dgram_read,
|
sl@0
|
118 |
dgram_puts,
|
sl@0
|
119 |
NULL, /* dgram_gets, */
|
sl@0
|
120 |
dgram_ctrl,
|
sl@0
|
121 |
dgram_new,
|
sl@0
|
122 |
dgram_free,
|
sl@0
|
123 |
NULL,
|
sl@0
|
124 |
};
|
sl@0
|
125 |
|
sl@0
|
126 |
#endif
|
sl@0
|
127 |
|
sl@0
|
128 |
typedef struct bio_dgram_data_st
|
sl@0
|
129 |
{
|
sl@0
|
130 |
struct sockaddr peer;
|
sl@0
|
131 |
unsigned int connected;
|
sl@0
|
132 |
unsigned int _errno;
|
sl@0
|
133 |
unsigned int mtu;
|
sl@0
|
134 |
} bio_dgram_data;
|
sl@0
|
135 |
|
sl@0
|
136 |
EXPORT_C BIO_METHOD *BIO_s_datagram(void)
|
sl@0
|
137 |
{
|
sl@0
|
138 |
return(&methods_dgramp);
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
EXPORT_C BIO *BIO_new_dgram(int fd, int close_flag)
|
sl@0
|
142 |
{
|
sl@0
|
143 |
BIO *ret;
|
sl@0
|
144 |
|
sl@0
|
145 |
ret=BIO_new(BIO_s_datagram());
|
sl@0
|
146 |
if (ret == NULL) return(NULL);
|
sl@0
|
147 |
BIO_set_fd(ret,fd,close_flag);
|
sl@0
|
148 |
return(ret);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
static int dgram_new(BIO *bi)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
bio_dgram_data *data = NULL;
|
sl@0
|
154 |
|
sl@0
|
155 |
bi->init=0;
|
sl@0
|
156 |
bi->num=0;
|
sl@0
|
157 |
data = OPENSSL_malloc(sizeof(bio_dgram_data));
|
sl@0
|
158 |
if (data == NULL)
|
sl@0
|
159 |
return 0;
|
sl@0
|
160 |
memset(data, 0x00, sizeof(bio_dgram_data));
|
sl@0
|
161 |
bi->ptr = data;
|
sl@0
|
162 |
|
sl@0
|
163 |
bi->flags=0;
|
sl@0
|
164 |
return(1);
|
sl@0
|
165 |
}
|
sl@0
|
166 |
|
sl@0
|
167 |
static int dgram_free(BIO *a)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
bio_dgram_data *data;
|
sl@0
|
170 |
|
sl@0
|
171 |
if (a == NULL) return(0);
|
sl@0
|
172 |
if ( ! dgram_clear(a))
|
sl@0
|
173 |
return 0;
|
sl@0
|
174 |
|
sl@0
|
175 |
data = (bio_dgram_data *)a->ptr;
|
sl@0
|
176 |
if(data != NULL) OPENSSL_free(data);
|
sl@0
|
177 |
|
sl@0
|
178 |
return(1);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
static int dgram_clear(BIO *a)
|
sl@0
|
182 |
{
|
sl@0
|
183 |
if (a == NULL) return(0);
|
sl@0
|
184 |
if (a->shutdown)
|
sl@0
|
185 |
{
|
sl@0
|
186 |
if (a->init)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
SHUTDOWN2(a->num);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
a->init=0;
|
sl@0
|
191 |
a->flags=0;
|
sl@0
|
192 |
}
|
sl@0
|
193 |
return(1);
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
static int dgram_read(BIO *b, char *out, int outl)
|
sl@0
|
197 |
{
|
sl@0
|
198 |
int ret=0;
|
sl@0
|
199 |
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
|
sl@0
|
200 |
|
sl@0
|
201 |
struct sockaddr peer;
|
sl@0
|
202 |
int peerlen = sizeof(peer);
|
sl@0
|
203 |
|
sl@0
|
204 |
if (out != NULL)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
clear_socket_error();
|
sl@0
|
207 |
memset(&peer, 0x00, peerlen);
|
sl@0
|
208 |
/* Last arg in recvfrom is signed on some platforms and
|
sl@0
|
209 |
* unsigned on others. It is of type socklen_t on some
|
sl@0
|
210 |
* but this is not universal. Cast to (void *) to avoid
|
sl@0
|
211 |
* compiler warnings.
|
sl@0
|
212 |
*/
|
sl@0
|
213 |
ret=recvfrom(b->num,out,outl,0,&peer,(void *)&peerlen);
|
sl@0
|
214 |
|
sl@0
|
215 |
if ( ! data->connected && ret > 0)
|
sl@0
|
216 |
BIO_ctrl(b, BIO_CTRL_DGRAM_CONNECT, 0, &peer);
|
sl@0
|
217 |
|
sl@0
|
218 |
BIO_clear_retry_flags(b);
|
sl@0
|
219 |
if (ret <= 0)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
if (BIO_dgram_should_retry(ret))
|
sl@0
|
222 |
{
|
sl@0
|
223 |
BIO_set_retry_read(b);
|
sl@0
|
224 |
data->_errno = get_last_socket_error();
|
sl@0
|
225 |
}
|
sl@0
|
226 |
}
|
sl@0
|
227 |
}
|
sl@0
|
228 |
return(ret);
|
sl@0
|
229 |
}
|
sl@0
|
230 |
|
sl@0
|
231 |
static int dgram_write(BIO *b, const char *in, int inl)
|
sl@0
|
232 |
{
|
sl@0
|
233 |
int ret;
|
sl@0
|
234 |
bio_dgram_data *data = (bio_dgram_data *)b->ptr;
|
sl@0
|
235 |
clear_socket_error();
|
sl@0
|
236 |
|
sl@0
|
237 |
if ( data->connected )
|
sl@0
|
238 |
ret=send(b->num,in,inl,0);
|
sl@0
|
239 |
else
|
sl@0
|
240 |
ret=sendto(b->num, in, inl, 0, &data->peer, sizeof(data->peer));
|
sl@0
|
241 |
|
sl@0
|
242 |
BIO_clear_retry_flags(b);
|
sl@0
|
243 |
if (ret <= 0)
|
sl@0
|
244 |
{
|
sl@0
|
245 |
if (BIO_sock_should_retry(ret))
|
sl@0
|
246 |
{
|
sl@0
|
247 |
BIO_set_retry_write(b);
|
sl@0
|
248 |
data->_errno = get_last_socket_error();
|
sl@0
|
249 |
|
sl@0
|
250 |
#if 0 /* higher layers are responsible for querying MTU, if necessary */
|
sl@0
|
251 |
if ( data->_errno == EMSGSIZE)
|
sl@0
|
252 |
/* retrieve the new MTU */
|
sl@0
|
253 |
BIO_ctrl(b, BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
|
sl@0
|
254 |
#endif
|
sl@0
|
255 |
}
|
sl@0
|
256 |
}
|
sl@0
|
257 |
return(ret);
|
sl@0
|
258 |
}
|
sl@0
|
259 |
|
sl@0
|
260 |
static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr)
|
sl@0
|
261 |
{
|
sl@0
|
262 |
long ret=1;
|
sl@0
|
263 |
int *ip;
|
sl@0
|
264 |
struct sockaddr *to = NULL;
|
sl@0
|
265 |
bio_dgram_data *data = NULL;
|
sl@0
|
266 |
long sockopt_val = 0;
|
sl@0
|
267 |
unsigned int sockopt_len = 0;
|
sl@0
|
268 |
|
sl@0
|
269 |
data = (bio_dgram_data *)b->ptr;
|
sl@0
|
270 |
|
sl@0
|
271 |
switch (cmd)
|
sl@0
|
272 |
{
|
sl@0
|
273 |
case BIO_CTRL_RESET:
|
sl@0
|
274 |
num=0;
|
sl@0
|
275 |
case BIO_C_FILE_SEEK:
|
sl@0
|
276 |
ret=0;
|
sl@0
|
277 |
break;
|
sl@0
|
278 |
case BIO_C_FILE_TELL:
|
sl@0
|
279 |
case BIO_CTRL_INFO:
|
sl@0
|
280 |
ret=0;
|
sl@0
|
281 |
break;
|
sl@0
|
282 |
case BIO_C_SET_FD:
|
sl@0
|
283 |
dgram_clear(b);
|
sl@0
|
284 |
b->num= *((int *)ptr);
|
sl@0
|
285 |
b->shutdown=(int)num;
|
sl@0
|
286 |
b->init=1;
|
sl@0
|
287 |
break;
|
sl@0
|
288 |
case BIO_C_GET_FD:
|
sl@0
|
289 |
if (b->init)
|
sl@0
|
290 |
{
|
sl@0
|
291 |
ip=(int *)ptr;
|
sl@0
|
292 |
if (ip != NULL) *ip=b->num;
|
sl@0
|
293 |
ret=b->num;
|
sl@0
|
294 |
}
|
sl@0
|
295 |
else
|
sl@0
|
296 |
ret= -1;
|
sl@0
|
297 |
break;
|
sl@0
|
298 |
case BIO_CTRL_GET_CLOSE:
|
sl@0
|
299 |
ret=b->shutdown;
|
sl@0
|
300 |
break;
|
sl@0
|
301 |
case BIO_CTRL_SET_CLOSE:
|
sl@0
|
302 |
b->shutdown=(int)num;
|
sl@0
|
303 |
break;
|
sl@0
|
304 |
case BIO_CTRL_PENDING:
|
sl@0
|
305 |
case BIO_CTRL_WPENDING:
|
sl@0
|
306 |
ret=0;
|
sl@0
|
307 |
break;
|
sl@0
|
308 |
case BIO_CTRL_DUP:
|
sl@0
|
309 |
case BIO_CTRL_FLUSH:
|
sl@0
|
310 |
ret=1;
|
sl@0
|
311 |
break;
|
sl@0
|
312 |
case BIO_CTRL_DGRAM_CONNECT:
|
sl@0
|
313 |
to = (struct sockaddr *)ptr;
|
sl@0
|
314 |
#if 0
|
sl@0
|
315 |
if (connect(b->num, to, sizeof(struct sockaddr)) < 0)
|
sl@0
|
316 |
{ perror("connect"); ret = 0; }
|
sl@0
|
317 |
else
|
sl@0
|
318 |
{
|
sl@0
|
319 |
#endif
|
sl@0
|
320 |
memcpy(&(data->peer),to, sizeof(struct sockaddr));
|
sl@0
|
321 |
#if 0
|
sl@0
|
322 |
}
|
sl@0
|
323 |
#endif
|
sl@0
|
324 |
break;
|
sl@0
|
325 |
/* (Linux)kernel sets DF bit on outgoing IP packets */
|
sl@0
|
326 |
#ifdef IP_MTU_DISCOVER
|
sl@0
|
327 |
case BIO_CTRL_DGRAM_MTU_DISCOVER:
|
sl@0
|
328 |
sockopt_val = IP_PMTUDISC_DO;
|
sl@0
|
329 |
if ((ret = setsockopt(b->num, IPPROTO_IP, IP_MTU_DISCOVER,
|
sl@0
|
330 |
&sockopt_val, sizeof(sockopt_val))) < 0)
|
sl@0
|
331 |
perror("setsockopt");
|
sl@0
|
332 |
break;
|
sl@0
|
333 |
#endif
|
sl@0
|
334 |
case BIO_CTRL_DGRAM_QUERY_MTU:
|
sl@0
|
335 |
sockopt_len = sizeof(sockopt_val);
|
sl@0
|
336 |
if ((ret = getsockopt(b->num, IPPROTO_IP, IP_MTU, (void *)&sockopt_val,
|
sl@0
|
337 |
&sockopt_len)) < 0 || sockopt_val < 0)
|
sl@0
|
338 |
{ ret = 0; }
|
sl@0
|
339 |
else
|
sl@0
|
340 |
{
|
sl@0
|
341 |
data->mtu = sockopt_val;
|
sl@0
|
342 |
ret = data->mtu;
|
sl@0
|
343 |
}
|
sl@0
|
344 |
break;
|
sl@0
|
345 |
case BIO_CTRL_DGRAM_GET_MTU:
|
sl@0
|
346 |
return data->mtu;
|
sl@0
|
347 |
break;
|
sl@0
|
348 |
case BIO_CTRL_DGRAM_SET_MTU:
|
sl@0
|
349 |
data->mtu = num;
|
sl@0
|
350 |
ret = num;
|
sl@0
|
351 |
break;
|
sl@0
|
352 |
case BIO_CTRL_DGRAM_SET_CONNECTED:
|
sl@0
|
353 |
to = (struct sockaddr *)ptr;
|
sl@0
|
354 |
|
sl@0
|
355 |
if ( to != NULL)
|
sl@0
|
356 |
{
|
sl@0
|
357 |
data->connected = 1;
|
sl@0
|
358 |
memcpy(&(data->peer),to, sizeof(struct sockaddr));
|
sl@0
|
359 |
}
|
sl@0
|
360 |
else
|
sl@0
|
361 |
{
|
sl@0
|
362 |
data->connected = 0;
|
sl@0
|
363 |
memset(&(data->peer), 0x00, sizeof(struct sockaddr));
|
sl@0
|
364 |
}
|
sl@0
|
365 |
break;
|
sl@0
|
366 |
case BIO_CTRL_DGRAM_SET_PEER:
|
sl@0
|
367 |
to = (struct sockaddr *) ptr;
|
sl@0
|
368 |
|
sl@0
|
369 |
memcpy(&(data->peer), to, sizeof(struct sockaddr));
|
sl@0
|
370 |
break;
|
sl@0
|
371 |
case BIO_CTRL_DGRAM_SET_RECV_TIMEOUT:
|
sl@0
|
372 |
if ( setsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO, ptr,
|
sl@0
|
373 |
sizeof(struct timeval)) < 0)
|
sl@0
|
374 |
{ perror("setsockopt"); ret = -1; }
|
sl@0
|
375 |
break;
|
sl@0
|
376 |
case BIO_CTRL_DGRAM_GET_RECV_TIMEOUT:
|
sl@0
|
377 |
if ( getsockopt(b->num, SOL_SOCKET, SO_RCVTIMEO,
|
sl@0
|
378 |
ptr, (void *)&ret) < 0)
|
sl@0
|
379 |
{ perror("getsockopt"); ret = -1; }
|
sl@0
|
380 |
break;
|
sl@0
|
381 |
case BIO_CTRL_DGRAM_SET_SEND_TIMEOUT:
|
sl@0
|
382 |
if ( setsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO, ptr,
|
sl@0
|
383 |
sizeof(struct timeval)) < 0)
|
sl@0
|
384 |
{ perror("setsockopt"); ret = -1; }
|
sl@0
|
385 |
break;
|
sl@0
|
386 |
case BIO_CTRL_DGRAM_GET_SEND_TIMEOUT:
|
sl@0
|
387 |
if ( getsockopt(b->num, SOL_SOCKET, SO_SNDTIMEO,
|
sl@0
|
388 |
ptr, (void *)&ret) < 0)
|
sl@0
|
389 |
{ perror("getsockopt"); ret = -1; }
|
sl@0
|
390 |
break;
|
sl@0
|
391 |
case BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP:
|
sl@0
|
392 |
/* fall-through */
|
sl@0
|
393 |
case BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP:
|
sl@0
|
394 |
if ( data->_errno == EAGAIN)
|
sl@0
|
395 |
{
|
sl@0
|
396 |
ret = 1;
|
sl@0
|
397 |
data->_errno = 0;
|
sl@0
|
398 |
}
|
sl@0
|
399 |
else
|
sl@0
|
400 |
ret = 0;
|
sl@0
|
401 |
break;
|
sl@0
|
402 |
#ifdef EMSGSIZE
|
sl@0
|
403 |
case BIO_CTRL_DGRAM_MTU_EXCEEDED:
|
sl@0
|
404 |
if ( data->_errno == EMSGSIZE)
|
sl@0
|
405 |
{
|
sl@0
|
406 |
ret = 1;
|
sl@0
|
407 |
data->_errno = 0;
|
sl@0
|
408 |
}
|
sl@0
|
409 |
else
|
sl@0
|
410 |
ret = 0;
|
sl@0
|
411 |
break;
|
sl@0
|
412 |
#endif
|
sl@0
|
413 |
default:
|
sl@0
|
414 |
ret=0;
|
sl@0
|
415 |
break;
|
sl@0
|
416 |
}
|
sl@0
|
417 |
return(ret);
|
sl@0
|
418 |
}
|
sl@0
|
419 |
|
sl@0
|
420 |
static int dgram_puts(BIO *bp, const char *str)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
int n,ret;
|
sl@0
|
423 |
|
sl@0
|
424 |
n=strlen(str);
|
sl@0
|
425 |
ret=dgram_write(bp,str,n);
|
sl@0
|
426 |
return(ret);
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
int BIO_dgram_should_retry(int i)
|
sl@0
|
430 |
{
|
sl@0
|
431 |
int err;
|
sl@0
|
432 |
|
sl@0
|
433 |
if ((i == 0) || (i == -1))
|
sl@0
|
434 |
{
|
sl@0
|
435 |
err=get_last_socket_error();
|
sl@0
|
436 |
|
sl@0
|
437 |
#if defined(OPENSSL_SYS_WINDOWS) && 0 /* more microsoft stupidity? perhaps not? Ben 4/1/99 */
|
sl@0
|
438 |
if ((i == -1) && (err == 0))
|
sl@0
|
439 |
return(1);
|
sl@0
|
440 |
#endif
|
sl@0
|
441 |
|
sl@0
|
442 |
return(BIO_dgram_non_fatal_error(err));
|
sl@0
|
443 |
}
|
sl@0
|
444 |
return(0);
|
sl@0
|
445 |
}
|
sl@0
|
446 |
|
sl@0
|
447 |
EXPORT_C int BIO_dgram_non_fatal_error(int err)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
switch (err)
|
sl@0
|
450 |
{
|
sl@0
|
451 |
#if defined(OPENSSL_SYS_WINDOWS)
|
sl@0
|
452 |
# if defined(WSAEWOULDBLOCK)
|
sl@0
|
453 |
case WSAEWOULDBLOCK:
|
sl@0
|
454 |
# endif
|
sl@0
|
455 |
|
sl@0
|
456 |
# if 0 /* This appears to always be an error */
|
sl@0
|
457 |
# if defined(WSAENOTCONN)
|
sl@0
|
458 |
case WSAENOTCONN:
|
sl@0
|
459 |
# endif
|
sl@0
|
460 |
# endif
|
sl@0
|
461 |
#endif
|
sl@0
|
462 |
|
sl@0
|
463 |
#ifdef EWOULDBLOCK
|
sl@0
|
464 |
# ifdef WSAEWOULDBLOCK
|
sl@0
|
465 |
# if WSAEWOULDBLOCK != EWOULDBLOCK
|
sl@0
|
466 |
case EWOULDBLOCK:
|
sl@0
|
467 |
# endif
|
sl@0
|
468 |
# else
|
sl@0
|
469 |
case EWOULDBLOCK:
|
sl@0
|
470 |
# endif
|
sl@0
|
471 |
#endif
|
sl@0
|
472 |
|
sl@0
|
473 |
#if defined(ENOTCONN)
|
sl@0
|
474 |
case ENOTCONN:
|
sl@0
|
475 |
#endif
|
sl@0
|
476 |
|
sl@0
|
477 |
#ifdef EINTR
|
sl@0
|
478 |
case EINTR:
|
sl@0
|
479 |
#endif
|
sl@0
|
480 |
|
sl@0
|
481 |
#ifdef EAGAIN
|
sl@0
|
482 |
#if EWOULDBLOCK != EAGAIN
|
sl@0
|
483 |
case EAGAIN:
|
sl@0
|
484 |
# endif
|
sl@0
|
485 |
#endif
|
sl@0
|
486 |
|
sl@0
|
487 |
#ifdef EPROTO
|
sl@0
|
488 |
case EPROTO:
|
sl@0
|
489 |
#endif
|
sl@0
|
490 |
|
sl@0
|
491 |
#ifdef EINPROGRESS
|
sl@0
|
492 |
case EINPROGRESS:
|
sl@0
|
493 |
#endif
|
sl@0
|
494 |
|
sl@0
|
495 |
#ifdef EALREADY
|
sl@0
|
496 |
case EALREADY:
|
sl@0
|
497 |
#endif
|
sl@0
|
498 |
|
sl@0
|
499 |
/* DF bit set, and packet larger than MTU */
|
sl@0
|
500 |
#ifdef EMSGSIZE
|
sl@0
|
501 |
case EMSGSIZE:
|
sl@0
|
502 |
#endif
|
sl@0
|
503 |
|
sl@0
|
504 |
return(1);
|
sl@0
|
505 |
/* break; */
|
sl@0
|
506 |
default:
|
sl@0
|
507 |
break;
|
sl@0
|
508 |
}
|
sl@0
|
509 |
return(0);
|
sl@0
|
510 |
}
|
sl@0
|
511 |
#endif
|