Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / native / target / generic / target_generic_network.h
blob4488ea87635f297f93a1a0a2ee7e5a5b3c0bc123
1 /* target_generic_network.h - Native methods for network operations.
2 Copyright (C) 1998, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 Description: generic target defintions of network functions
40 Systems : all
43 #ifndef __TARGET_GENERIC_NETWORK__
44 #define __TARGET_GENERIC_NETWORK__
46 /* check if target_native_network.h included */
47 #ifndef __TARGET_NATIVE_NETWORK__
48 #error Do NOT INCLUDE generic target files! Include the corresponding native target files instead!
49 #endif
51 /****************************** Includes *******************************/
52 /* do not move; needed here because of some macro definitions */
53 #include "config.h"
55 #include <stdlib.h>
57 #include "target_native.h"
59 /****************** Conditional compilation switches *******************/
61 /***************************** Constants *******************************/
63 /***************************** Datatypes *******************************/
65 /***************************** Variables *******************************/
67 /****************************** Macros *********************************/
69 /***********************************************************************\
70 * Name : TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT
71 * Purpose : convert IP adddress (4 parts) into integer (host-format
72 * 32bit)
73 * Input : n0,n1,n2,n3 - IP address parts
74 * Output : i - integer with IP address in host-format
75 * Return : -
76 * Side-effect: unknown
77 * Notes : -
78 \***********************************************************************/
80 #ifndef TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT
81 #define TARGET_NATIVE_NETWORK_IPADDRESS_BYTES_TO_INT(n0,n1,n2,n3,i) \
82 do { \
83 i=(((unsigned char)n0) << 24) | \
84 (((unsigned char)n1) << 16) | \
85 (((unsigned char)n2) << 8) | \
86 (((unsigned char)n3) << 0); \
87 } while (0)
88 #endif
90 /***********************************************************************\
91 * Name : TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES
92 * Purpose : convert IP adddress (4 parts) into integer (host-format
93 * 32bit)
94 * Input : n0,n1,n2,n3 - IP address parts
95 * Output : i - integer with IP address in host-format
96 * Return : -
97 * Side-effect: unknown
98 * Notes : -
99 \***********************************************************************/
101 #ifndef TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES
102 #define TARGET_NATIVE_NETWORK_INT_TO_IPADDRESS_BYTES(i,n0,n1,n2,n3) \
103 do { \
104 n0=(i & 0xFF000000) >> 24; \
105 n1=(i & 0x00FF0000) >> 16; \
106 n2=(i & 0x0000FF00) >> 8; \
107 n3=(i & 0x000000FF) >> 0; \
108 } while (0)
109 #endif
111 /***********************************************************************\
112 * Name : TARGET_NATIVE_NETWORK_GET_HOSTNAME
113 * Purpose : get hostname
114 * Input : maxNameLen - max. length of name
115 * Output : name - name (NUL terminated)
116 * result - TARGET_NATIVE_OK if no error occurred,
117 * TARGET_NATIVE_ERROR otherwise
118 * Return : -
119 * Side-effect: unknown
120 * Notes : -
121 \***********************************************************************/
123 #ifndef TARGET_NATIVE_NETWORK_GET_HOSTNAME
124 #include <unistd.h>
125 #define TARGET_NATIVE_NETWORK_GET_HOSTNAME(name,maxNameLen,result) \
126 do { \
127 result=(gethostname(name,maxNameLen-1)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
128 name[maxNameLen-1]='\0'; \
129 } while (0)
130 #endif
132 /***********************************************************************\
133 * Name : TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_ADDRESS
134 * Purpose : get hostname by address
135 * Input : address - IP address (32bit, NOT network byte order!)
136 * maxNameLen - max. length of name
137 * Output : name - name (NUL terminated)
138 * result - TARGET_NATIVE_OK if no error occurred,
139 * TARGET_NATIVE_ERROR otherwise
140 * Return : -
141 * Side-effect: unknown
142 * Notes : -
143 \***********************************************************************/
145 /* XXX NYI??? reentrant? */
146 #ifndef TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_ADDRESS
147 #include <netdb.h>
148 #define TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_ADDRESS(address,name,maxNameLen,result) \
149 do { \
150 int __networkAddress; \
151 struct hostent *__hostEntry; \
153 __networkAddress=htonl(address); \
154 __hostEntry = gethostbyaddr((char*)&__networkAddress,sizeof(__networkAddress),AF_INET); \
155 if (__hostEntry!=NULL) \
157 strncpy(name,__hostEntry->h_name,maxNameLen-1); \
158 name[maxNameLen]='\0'; \
159 result=TARGET_NATIVE_OK; \
161 else \
163 result=TARGET_NATIVE_ERROR; \
165 } while (0)
166 #endif
168 /***********************************************************************\
169 * Name : TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_NAME
170 * Purpose : get hostname by name
171 * Input : name - hostname
172 * maxAddressSize - max. size of address array
173 * Output : addresses - host adddresses (array, NOT in network
174 * byte order!)
175 * addressCount - number of entries in address array
176 * result - TARGET_NATIVE_OK if no error occurred,
177 * TARGET_NATIVE_ERROR otherwise
178 * Return : -
179 * Side-effect: unknown
180 * Notes : -
181 \***********************************************************************/
183 /* XXX NYI??? reentrant? */
184 #ifndef TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_NAME
185 #include <netdb.h>
186 #define TARGET_NATIVE_NETWORK_GET_HOSTNAME_BY_NAME(name,addresses,maxAddressSize,addressCount,result) \
187 do { \
188 struct hostent *__hostEntry; \
190 addressCount=0; \
192 __hostEntry = gethostbyname(name); \
193 if (__hostEntry!=NULL) \
195 while ((addressCount<maxAddressSize) && (__hostEntry->h_addr_list[addressCount]!=NULL)) \
197 addresses[addressCount]=ntohl(*(int*)(__hostEntry->h_addr_list[addressCount])); \
198 addressCount++; \
200 result=TARGET_NATIVE_OK; \
202 else \
204 result=TARGET_NATIVE_ERROR; \
206 } while (0)
207 #endif
209 /***********************************************************************\
210 * Name : TARGET_NATIVE_NETWORK_SOCKET_OPEN_STREAM
211 * Purpose : open stream socket
212 * Input : -
213 * Output : socketDescriptor - socket descriptor
214 * result - TARGET_NATIVE_OK if no error occurred,
215 * TARGET_NATIVE_ERROR otherwise
216 * Return : -
217 * Side-effect: unknown
218 * Notes : -
219 \***********************************************************************/
221 #ifndef TARGET_NATIVE_NETWORK_SOCKET_OPEN_STREAM
222 #include <sys/types.h>
223 #include <sys/socket.h>
224 #include <fcntl.h>
225 #define TARGET_NATIVE_NETWORK_SOCKET_OPEN_STREAM(socketDescriptor,result) \
226 do { \
227 socketDescriptor=socket(AF_INET,SOCK_STREAM,0); \
228 fcntl(socketDescriptor,F_SETFD,FD_CLOEXEC); \
229 result=(socketDescriptor!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
230 } while (0)
231 #endif
233 /***********************************************************************\
234 * Name : TARGET_NATIVE_NETWORK_SOCKET_OPEN_DATAGRAM
235 * Purpose : open datagram socket
236 * Input : -
237 * Output : socketDescriptor - socket descriptor
238 * result - TARGET_NATIVE_OK if no error occurred,
239 * TARGET_NATIVE_ERROR otherwise
240 * Return : -
241 * Side-effect: unknown
242 * Notes : -
243 \***********************************************************************/
245 #ifndef TARGET_NATIVE_NETWORK_SOCKET_OPEN_DATAGRAM
246 #include <sys/types.h>
247 #include <sys/socket.h>
248 #include <fcntl.h>
249 #define TARGET_NATIVE_NETWORK_SOCKET_OPEN_DATAGRAM(socketDescriptor,result) \
250 do { \
251 socketDescriptor=socket(AF_INET,SOCK_DGRAM,0); \
252 fcntl(socketDescriptor,F_SETFD,FD_CLOEXEC); \
253 result=(socketDescriptor!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
254 } while (0)
255 #endif
257 /***********************************************************************\
258 * Name : TARGET_NATIVE_NETWORK_SOCKET_CLOSE
259 * Purpose : close socket
260 * Input : socketDescriptor - socket descriptor
261 * Output : result - TARGET_NATIVE_OK if no error occurred,
262 * TARGET_NATIVE_ERROR otherwise
263 * Return : -
264 * Side-effect: unknown
265 * Notes : -
266 \***********************************************************************/
268 #ifndef TARGET_NATIVE_NETWORK_SOCKET_CLOSE
269 #include <unistd.h>
270 #define TARGET_NATIVE_NETWORK_SOCKET_CLOSE(socketDescriptor,result) \
271 do { \
272 result=(close(socketDescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
273 } while (0)
274 #endif
276 /***********************************************************************\
277 * Name : TARGET_NATIVE_NETWORK_SOCKET_CONNECT
278 * Purpose : connect socket
279 * Input : socketDescriptor - socket descriptor
280 * address - address (network format???)
281 * port - port number (NOT in network byte order!)
282 * Output : result - TARGET_NATIVE_OK if no error occurred,
283 * TARGET_NATIVE_ERROR otherwise
284 * Return : -
285 * Side-effect: unknown
286 * Notes : -
287 \***********************************************************************/
289 #ifndef TARGET_NATIVE_NETWORK_SOCKET_CONNECT
290 #include <sys/types.h>
291 #include <sys/socket.h>
292 #include <netinet/in.h>
293 #define TARGET_NATIVE_NETWORK_SOCKET_CONNECT(socketDescriptor,address,port,result) \
294 do { \
295 struct sockaddr_in __socketAddress; \
297 memset(&__socketAddress,0,sizeof(__socketAddress)); \
298 __socketAddress.sin_family = AF_INET; \
299 __socketAddress.sin_addr.s_addr = htonl(address); \
300 __socketAddress.sin_port = htons(((short)port)); \
302 result=(connect(socketDescriptor,(struct sockaddr*)&__socketAddress,sizeof(__socketAddress))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
303 } while (0)
304 #endif
306 /***********************************************************************\
307 * Name : TARGET_NATIVE_NETWORK_SOCKET_BIND
308 * Purpose : bind socket
309 * Input : socketDescriptor - socket descriptor
310 * address - address (NOT ??? in network byte order!)
311 * port - port (NOT in network byte order!)
312 * Output : result - TARGET_NATIVE_OK if no error occurred,
313 * TARGET_NATIVE_ERROR otherwise
314 * Return : -
315 * Side-effect: unknown
316 * Notes : -
317 \***********************************************************************/
319 /* XXX ??? address in network byte order? */
320 #ifndef TARGET_NATIVE_NETWORK_SOCKET_BIND
321 #include <sys/types.h>
322 #include <sys/socket.h>
323 #include <netinet/in.h>
324 #define TARGET_NATIVE_NETWORK_SOCKET_BIND(socketDescriptor,address,port,result) \
325 do { \
326 struct sockaddr_in __socketAddress; \
328 memset(&__socketAddress,0,sizeof(__socketAddress)); \
329 __socketAddress.sin_family = AF_INET; \
330 __socketAddress.sin_addr.s_addr = htonl(address); \
331 __socketAddress.sin_port = htons(((short)port)); \
333 result=(bind(socketDescriptor,(struct sockaddr*)&__socketAddress,sizeof(__socketAddress))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
334 } while (0)
335 #endif
337 /***********************************************************************\
338 * Name : TARGET_NATIVE_NETWORK_SOCKET_LISTEN
339 * Purpose : listen socket
340 * Input : socketDescriptor - socket descriptor
341 * maxQueueLength - max. number of pending connections
342 * Output : result - TARGET_NATIVE_OK if no error occurred,
343 * TARGET_NATIVE_ERROR otherwise
344 * Return : -
345 * Side-effect: unknown
346 * Notes : -
347 \***********************************************************************/
349 /* XXX ??? address in network byte order? */
350 #ifndef TARGET_NATIVE_NETWORK_SOCKET_LISTEN
351 #include <sys/socket.h>
352 #define TARGET_NATIVE_NETWORK_SOCKET_LISTEN(socketDescriptor,maxQueueLength,result) \
353 do { \
354 result=(listen(socketDescriptor,maxQueueLength)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
355 } while (0)
356 #endif
358 /***********************************************************************\
359 * Name : TARGET_NATIVE_NETWORK_SOCKET_ACCEPT
360 * Purpose : accept socket
361 * Input : socketDescriptor - socket descriptor
362 * Output : result - TARGET_NATIVE_OK if no error occurred,
363 * TARGET_NATIVE_ERROR otherwise
364 * Return : -
365 * Side-effect: unknown
366 * Notes : -
367 \***********************************************************************/
369 /* XXX ??? address in network byte order? */
370 #ifndef TARGET_NATIVE_NETWORK_SOCKET_ACCEPT
371 #include <sys/types.h>
372 #include <sys/socket.h>
373 #include <netinet/in.h>
374 #define TARGET_NATIVE_NETWORK_SOCKET_ACCEPT(socketDescriptor,newSocketDescriptor,result) \
375 do { \
376 struct sockaddr_in __socketAddress; \
377 socklen_t __socketAddressLength; \
379 memset(&__socketAddress,0,sizeof(__socketAddress)); \
380 __socketAddressLength=sizeof(__socketAddress); \
381 newSocketDescriptor=accept(socketDescriptor,(struct sockaddr*)&__socketAddress,&__socketAddressLength); \
382 result=(newSocketDescriptor!=-1)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
383 } while (0)
384 #endif
386 /***********************************************************************\
387 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO
388 * Purpose : get local socket data info
389 * Input : socketDescriptor - socket descriptor
390 * Output : localAddress - local address (NOT in network byte order!)
391 * localPort - local port number (NOT in network byte order!)
392 * result - TARGET_NATIVE_OK if no error occurred,
393 * TARGET_NATIVE_ERROR otherwise
394 * Return : -
395 * Side-effect: unknown
396 * Notes : -
397 \***********************************************************************/
399 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO
400 #include <sys/socket.h>
401 #include <netinet/in.h>
402 #define TARGET_NATIVE_NETWORK_SOCKET_GET_LOCAL_INFO(socketDescriptor,localAddress,localPort,result) \
403 do { \
404 struct sockaddr_in __socketAddress; \
405 socklen_t __socketAddressLength; \
407 localAddress=0; \
408 localPort =0; \
410 __socketAddressLength=sizeof(__socketAddress); \
411 result=(getsockname(socketDescriptor,(struct sockaddr*)&__socketAddress,&__socketAddressLength)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
412 if (result==TARGET_NATIVE_OK) \
414 localAddress=ntohl(__socketAddress.sin_addr.s_addr); \
415 localPort =ntohs(__socketAddress.sin_port); \
417 } while (0)
418 #endif
420 /***********************************************************************\
421 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO
422 * Purpose : get remote socket data info
423 * Input : socketDescriptor - socket descriptor
424 * Output : remoteAddress - remote address (NOT in network byte order!)
425 * remotePort - remote port number (NOT in network byte order!)
426 * : result - TARGET_NATIVE_OK if no error occurred,
427 * TARGET_NATIVE_ERROR otherwise
428 * Return : -
429 * Side-effect: unknown
430 * Notes : -
431 \***********************************************************************/
433 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO
434 #include <sys/socket.h>
435 #include <netinet/in.h>
436 #define TARGET_NATIVE_NETWORK_SOCKET_GET_REMOTE_INFO(socketDescriptor,remoteAddress,remotePort,result) \
437 do { \
438 struct sockaddr_in __socketAddress; \
439 socklen_t __socketAddressLength; \
441 remoteAddress=0; \
442 remotePort =0; \
444 __socketAddressLength=sizeof(__socketAddress); \
445 result=(getpeername(socketDescriptor,(struct sockaddr*)&__socketAddress,&__socketAddressLength)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
446 if (result==TARGET_NATIVE_OK) \
448 remoteAddress=ntohl(__socketAddress.sin_addr.s_addr); \
449 remotePort =ntohs(__socketAddress.sin_port); \
451 } while (0)
452 #endif
454 /***********************************************************************\
455 * Name : TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE
456 * Purpose : get number of available bytes for receive
457 * Input : socketDescriptor - socket descriptor
458 * Output : bytesAvailable - available bytes for receive
459 * : result - TARGET_NATIVE_OK if no error occurred,
460 * TARGET_NATIVE_ERROR otherwise
461 * Return : -
462 * Side-effect: unknown
463 * Notes : -
464 \***********************************************************************/
466 #ifndef TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE
467 #include <sys/ioctl.h>
468 #define TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_AVAILABLE(socketDescriptor,bytesAvailable,result) \
469 do { \
470 int __value; \
472 bytesAvailable=0; \
474 result=(ioctl(socketDescriptor,FIONREAD,&__value)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
475 if (result==TARGET_NATIVE_OK) \
477 bytesAvailable=__value; \
479 } while (0)
480 #endif
482 /***********************************************************************\
483 * Name : TARGET_NATIVE_NETWORK_SOCKET_RECEIVE
484 * Purpose : receive data from socket
485 * Input : socketDescriptor - socket descriptor
486 * maxLength - max. size of bfufer
487 * Output : buffer - received data
488 * bytesReceive - length of received data
489 * Return : -
490 * Side-effect: unknown
491 * Notes : -
492 \***********************************************************************/
494 #ifndef TARGET_NATIVE_NETWORK_SOCKET_RECEIVE
495 #include <sys/types.h>
496 #include <sys/socket.h>
497 #include <netinet/in.h>
498 #define TARGET_NATIVE_NETWORK_SOCKET_RECEIVE(socketDescriptor,buffer,maxLength,bytesReceived) \
499 do { \
500 struct sockaddr_in __socketAddress; \
501 socklen_t __socketAddressLength; \
503 memset(&__socketAddress,0,sizeof(__socketAddress)); \
504 __socketAddressLength=sizeof(__socketAddress); \
505 bytesReceived=recv(socketDescriptor,buffer,maxLength,0); \
506 } while (0)
507 #endif
509 /***********************************************************************\
510 * Name : TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT
511 * Purpose : receive data from socket
512 * Input : socketDescriptor - socket descriptor
513 * maxLength - max. size of bfufer
514 * Output : buffer - received data
515 * address - from address (NOT in network byte order!)
516 * port - from port (NOT in network byte order!)
517 * bytesReceive - length of received data
518 * Return : -
519 * Side-effect: unknown
520 * Notes : -
521 \***********************************************************************/
523 #ifndef TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT
524 #include <sys/types.h>
525 #include <sys/socket.h>
526 #include <netinet/in.h>
527 #define TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT(socketDescriptor,buffer,maxLength,address,port,bytesReceived) \
528 do { \
529 struct sockaddr_in __socketAddress; \
530 socklen_t __socketAddressLength; \
532 port=0; \
534 memset(&__socketAddress,0,sizeof(__socketAddress)); \
535 __socketAddressLength=sizeof(__socketAddress); \
536 bytesReceived=recvfrom(socketDescriptor,buffer,maxLength,0,(struct sockaddr*)&__socketAddress,&__socketAddressLength); \
537 if (__socketAddressLength==sizeof(__socketAddress)) \
539 address=ntohl(__socketAddress.sin_addr.s_addr); \
540 port =ntohs(__socketAddress.sin_port); \
542 } while (0)
543 #endif
545 /***********************************************************************\
546 * Name : TARGET_NATIVE_NETWORK_SOCKET_SEND
547 * Purpose : send data to socket
548 * Input : socketDescriptor - socket descriptor
549 * : buffer - data to send
550 * length - length of data to send
551 * Output : bytesSent - number of bytes sent, -1 otherwise
552 * Side-effect: unknown
553 * Notes : -
554 \***********************************************************************/
556 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SEND
557 #include <sys/types.h>
558 #include <sys/socket.h>
559 #include <netinet/in.h>
560 #define TARGET_NATIVE_NETWORK_SOCKET_SEND(socketDescriptor,buffer,length,bytesSent) \
561 do { \
562 bytesSent=send(socketDescriptor,buffer,length,0); \
563 } while (0)
564 #endif
566 /***********************************************************************\
567 * Name : TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT
568 * Purpose : send data to socket
569 * Input : socketDescriptor - socket descriptor
570 * : buffer - data to send
571 * length - length of data to send
572 * Address - to address (NOT in network byte order!)
573 * Port - to port (NOT in network byte order!)
574 * Output : bytesSent - number of bytes sent, -1 otherwise
575 * Side-effect: unknown
576 * Notes : -
577 \***********************************************************************/
579 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT
580 #include <sys/types.h>
581 #include <sys/socket.h>
582 #include <netinet/in.h>
583 #define TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT(socketDescriptor,buffer,length,address,port,bytesSent) \
584 do { \
585 struct sockaddr_in __socketAddress; \
587 memset(&__socketAddress,0,sizeof(__socketAddress)); \
588 __socketAddress.sin_family = AF_INET; \
589 __socketAddress.sin_addr.s_addr = htonl(address); \
590 __socketAddress.sin_port = htons((short)port); \
591 bytesSent=sendto(socketDescriptor,buffer,length,0,(struct sockaddr*)&__socketAddress,sizeof(__socketAddress)); \
592 } while (0)
593 #endif
595 /***********************************************************************\
596 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_TCP_NODELAY
597 * Purpose : set socket option TCP_NODELAY
598 * Input : socketDescriptor - socket descriptor
599 * flag - 1 or 0
600 * Output : result - TARGET_NATIVE_OK if no error occurred,
601 * TARGET_NATIVE_ERROR otherwise
602 * Return : -
603 * Side-effect: unknown
604 * Notes : -
605 \***********************************************************************/
607 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_TCP_NODELAY
608 #include <sys/types.h>
609 #include <sys/socket.h>
610 #include <netinet/tcp.h>
611 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_TCP_NODELAY(socketDescriptor,flag,result) \
612 do { \
613 int __value; \
615 __value=flag; \
616 result=(setsockopt(socketDescriptor,IPPROTO_TCP,TCP_NODELAY,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
617 } while (0)
618 #endif
620 /***********************************************************************\
621 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER
622 * Purpose : set socket option SO_LINGER
623 * Input : socketDescriptor - socket descriptor
624 * flag - 1 or 0
625 * value - linger value
626 * Output : result - TARGET_NATIVE_OK if no error occurred,
627 * TARGET_NATIVE_ERROR otherwise
628 * Return : -
629 * Side-effect: unknown
630 * Notes : -
631 \***********************************************************************/
633 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER
634 #include <sys/types.h>
635 #include <sys/socket.h>
636 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_LINGER(socketDescriptor,flag,value,result) \
637 do { \
638 struct linger __linger; \
640 memset(&__linger,0,sizeof(__linger)); \
641 if (flag) \
643 __linger.l_onoff=0; \
645 else \
647 __linger.l_linger=value; \
648 __linger.l_onoff =1; \
650 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_LINGER,&__linger,sizeof(__linger))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
651 } while (0)
652 #endif
654 /***********************************************************************\
655 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT
656 * Purpose : set socket option SO_TIMEOUT
657 * Input : socketDescriptor - socket descriptor
658 * flag - 1 or 0
659 * Output : result - TARGET_NATIVE_OK if no error occurred,
660 * TARGET_NATIVE_ERROR otherwise
661 * Return : -
662 * Side-effect: unknown
663 * Notes : -
664 \***********************************************************************/
666 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT
667 #include <sys/types.h>
668 #include <sys/socket.h>
669 #if TIME_WITH_SYS_TIME
670 # include <sys/time.h>
671 # include <time.h>
672 #else
673 # if HAVE_SYS_TIME_H
674 # include <sys/time.h>
675 # else
676 # include <time.h>
677 # endif
678 #endif
679 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_TIMEOUT(socketDescriptor,flag,result) \
680 do { \
681 struct timeval __value; \
683 __value.tv_sec = flag / 1000; \
684 __value.tv_usec = (flag % 1000) * 1000; \
685 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_TIMEOUT,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
686 } while (0)
687 #endif
689 /***********************************************************************\
690 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_SNDBUF
691 * Purpose : set socket option SO_SNDBUF
692 * Input : socketDescriptor - socket descriptor
693 * size - size of send buffer
694 * Output : result - TARGET_NATIVE_OK if no error occurred,
695 * TARGET_NATIVE_ERROR otherwise
696 * Return : -
697 * Side-effect: unknown
698 * Notes : -
699 \***********************************************************************/
701 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_SNDBUF
702 #include <sys/types.h>
703 #include <sys/socket.h>
704 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_SNDBUF(socketDescriptor,size,result) \
705 do { \
706 int __value; \
708 __value=size; \
709 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_SNDBUF,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
710 } while (0)
711 #endif
713 /***********************************************************************\
714 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_RCDBUF
715 * Purpose : set socket option SO_RCDBUF
716 * Input : socketDescriptor - socket descriptor
717 * size - size of receive buffer
718 * Output : result - TARGET_NATIVE_OK if no error occurred,
719 * TARGET_NATIVE_ERROR otherwise
720 * Return : -
721 * Side-effect: unknown
722 * Notes : -
723 \***********************************************************************/
725 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_RCDBUF
726 #include <sys/types.h>
727 #include <sys/socket.h>
728 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_SO_RCDBUF(socketDescriptor,size,result) \
729 do { \
730 int __value; \
732 __value=size; \
733 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_RCVBUF,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
734 } while (0)
735 #endif
737 /***********************************************************************\
738 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_TTL
739 * Purpose : set socket option IP_TTL
740 * Input : socketDescriptor - socket descriptor
741 * value - value
742 * Output : result - TARGET_NATIVE_OK if no error occurred,
743 * TARGET_NATIVE_ERROR otherwise
744 * Return : -
745 * Side-effect: unknown
746 * Notes : -
747 \***********************************************************************/
749 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_TTL
750 #include <sys/types.h>
751 #include <sys/socket.h>
752 #include <netinet/in.h>
753 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_TTL(socketDescriptor,value,result) \
754 do { \
755 int __value; \
757 __value=value; \
758 result=(setsockopt(socketDescriptor,IPPROTO_IP,IP_TTL,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
759 } while (0)
760 #endif
762 /***********************************************************************\
763 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_MULTICAST_IF
764 * Purpose : set socket option IP_MULTICAST_IF
765 * Input : socketDescriptor - socket descriptor
766 * address - integer with IP address in host-format
767 * Output : result - TARGET_NATIVE_OK if no error occurred,
768 * TARGET_NATIVE_ERROR otherwise
769 * Return : -
770 * Side-effect: unknown
771 * Notes : -
772 \***********************************************************************/
774 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_MULTICAST_IF
775 #include <sys/types.h>
776 #include <sys/socket.h>
777 #include <netinet/in.h>
778 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_IP_MULTICAST_IF(socketDescriptor,address,result) \
779 do { \
780 struct sockaddr_in __socketAddress; \
782 memset(&__socketAddress,0,sizeof(__socketAddress)); \
783 __socketAddress.sin_family = AF_INET; \
784 __socketAddress.sin_addr.s_addr = htonl(address); \
785 result=(setsockopt(socketDescriptor,IPPROTO_IP,IP_MULTICAST_IF,&__socketAddress,sizeof(__socketAddress))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
786 } while (0)
787 #endif
789 /***********************************************************************\
790 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_REUSE_ADDRESS
791 * Purpose : set socket option REUSE_ADDRESS
792 * Input : socketDescriptor - socket descriptor
793 * flag - 1 or 0
794 * Output : result - TARGET_NATIVE_OK if no error occurred,
795 * TARGET_NATIVE_ERROR otherwise
796 * Return : -
797 * Side-effect: unknown
798 * Notes : -
799 \***********************************************************************/
801 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_REUSE_ADDRESS
802 #include <sys/types.h>
803 #include <sys/socket.h>
804 #include <netinet/in.h>
805 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_REUSE_ADDRESS(socketDescriptor,flag,result) \
806 do { \
807 int __value; \
809 __value=flag; \
810 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
811 } while (0)
812 #endif
814 /***********************************************************************\
815 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP
816 * Purpose : set socket option IP_ADD_MEMBERSHIP
817 * Input : socketDescriptor - socket descriptor
818 * address - network address (host-format)
819 * Output : result - TARGET_NATIVE_OK if no error occurred,
820 * TARGET_NATIVE_ERROR otherwise
821 * Return : -
822 * Side-effect: unknown
823 * Notes : -
824 \***********************************************************************/
826 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP
827 #include <sys/types.h>
828 #include <sys/socket.h>
829 #include <netinet/in.h>
830 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_ADD_MEMBERSHIP(socketDescriptor,address,result) \
831 do { \
832 struct ip_mreq __request; \
834 memset(&__request,0,sizeof(__request)); \
835 __request.imr_multiaddr.s_addr=htonl(address); \
836 __request.imr_interface.s_addr=INADDR_ANY; \
837 result=(setsockopt(socketDescriptor,IPPROTO_IP,IP_ADD_MEMBERSHIP,&__request,sizeof(__request))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
838 } while (0)
839 #endif
841 /***********************************************************************\
842 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP
843 * Purpose : set socket option IP_DROP_MEMBERSHIP
844 * Input : socketDescriptor - socket descriptor
845 * address - network address (host-format)
846 * Output : result - TARGET_NATIVE_OK if no error occurred,
847 * TARGET_NATIVE_ERROR otherwise
848 * Return : -
849 * Side-effect: unknown
850 * Notes : -
851 \***********************************************************************/
853 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP
854 #include <sys/types.h>
855 #include <sys/socket.h>
856 #include <netinet/in.h>
857 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_DROP_MEMBERSHIP(socketDescriptor,address,result) \
858 do { \
859 struct ip_mreq __request; \
861 memset(&__request,0,sizeof(__request)); \
862 __request.imr_multiaddr.s_addr=htonl(address); \
863 __request.imr_interface.s_addr=INADDR_ANY; \
864 result=(setsockopt(socketDescriptor,IPPROTO_IP,IP_DROP_MEMBERSHIP,&__request,sizeof(__request))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
865 } while (0)
866 #endif
868 /***********************************************************************\
869 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_KEEP_ALIVE
870 * Purpose : set socket option KEEP_ALIVE
871 * Input : socketDescriptor - socket descriptor
872 * flag - 1 or 0
873 * Output : result - TARGET_NATIVE_OK if no error occurred,
874 * TARGET_NATIVE_ERROR otherwise
875 * Return : -
876 * Side-effect: unknown
877 * Notes : -
878 \***********************************************************************/
880 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_KEEP_ALIVE
881 #include <sys/types.h>
882 #include <sys/socket.h>
883 #include <netinet/in.h>
884 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_KEEP_ALIVE(socketDescriptor,flag,result) \
885 do { \
886 int __value; \
888 __value=flag; \
889 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_KEEPALIVE,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
890 } while (0)
891 #endif
893 /***********************************************************************\
894 * Name : TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_BROADCAST
895 * Purpose : set socket option SO_BROADCAST
896 * Input : socketDescriptor - socket descriptor
897 * flag - 1 or 0
898 * Output : result - TARGET_NATIVE_OK if no error occurred,
899 * TARGET_NATIVE_ERROR otherwise
900 * Return : -
901 * Side-effect: unknown
902 * Notes : -
903 \***********************************************************************/
905 #ifndef TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_BROADCAST
906 #include <sys/types.h>
907 #include <sys/socket.h>
908 #include <netinet/tcp.h>
909 #define TARGET_NATIVE_NETWORK_SOCKET_SET_OPTION_BROADCAST(socketDescriptor,flag,result) \
910 do { \
911 int __value; \
913 __value=flag; \
914 result=(setsockopt(socketDescriptor,SOL_SOCKET,SO_BROADCAST,&__value,sizeof(__value))==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
915 } while (0)
916 #endif
918 /*---------------------------------------------------------------------*/
920 /***********************************************************************\
921 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_TCP_NODELAY
922 * Purpose : get socket option TCP_NODELAY
923 * Input : socketDescriptor - socket descriptor
924 * Output : flag - 1 or 0
925 * result - TARGET_NATIVE_OK if no error occurred,
926 * TARGET_NATIVE_ERROR otherwise
927 * Return : -
928 * Side-effect: unknown
929 * Notes : -
930 \***********************************************************************/
932 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_TCP_NODELAY
933 #include <sys/types.h>
934 #include <sys/socket.h>
935 #include <netinet/tcp.h>
936 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_TCP_NODELAY(socketDescriptor,flag,result) \
937 do { \
938 int __value; \
939 socklen_t __len; \
941 flag=0; \
943 __len=sizeof(__value); \
944 result=(getsockopt(socketDescriptor,IPPROTO_TCP,TCP_NODELAY,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
945 if (result==TARGET_NATIVE_OK) \
947 flag=__value; \
949 } while (0)
950 #endif
952 /***********************************************************************\
953 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_LINGER
954 * Purpose : get socket option SO_LINGER
955 * Input : socketDescriptor - socket descriptor
956 * Output : flag - 1 or 0
957 * value - linger value
958 * result - TARGET_NATIVE_OK if no error occurred,
959 * TARGET_NATIVE_ERROR otherwise
960 * Return : -
961 * Side-effect: unknown
962 * Notes : -
963 \***********************************************************************/
965 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_LINGER
966 #include <sys/types.h>
967 #include <sys/socket.h>
968 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_LINGER(socketDescriptor,flag,value,result) \
969 do { \
970 struct linger __linger; \
971 socklen_t __len; \
973 flag =0; \
974 value=0; \
976 __len=sizeof(__linger); \
977 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_LINGER,&__linger,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
978 if (result==TARGET_NATIVE_OK) \
980 flag =__linger.l_onoff; \
981 value=__linger.l_linger; \
983 } while (0)
984 #endif
986 /***********************************************************************\
987 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_TIMEOUT
988 * Purpose : get socket option SO_TIMEOUT
989 * Input : socketDescriptor - socket descriptor
990 * Output : flag - 1 or 0
991 * result - TARGET_NATIVE_OK if no error occurred,
992 * TARGET_NATIVE_ERROR otherwise
993 * Return : -
994 * Side-effect: unknown
995 * Notes : -
996 \***********************************************************************/
998 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_TIMEOUT
999 #include <sys/types.h>
1000 #include <sys/socket.h>
1001 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_TIMEOUT(socketDescriptor,flag,result) \
1002 do { \
1003 struct timeval __value; \
1004 socklen_t __len; \
1006 flag=0; \
1008 __len=sizeof(__value); \
1009 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_TIMEOUT,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1010 if (result==TARGET_NATIVE_OK) \
1012 flag = (__value.tv_sec * 1000LL) + (__value.tv_usec / 1000LL); \
1014 } while (0)
1015 #endif
1017 /***********************************************************************\
1018 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_SNDBUF
1019 * Purpose : get socket option SO_SNDBUF
1020 * Input : socketDescriptor - socket descriptor
1021 * Output : size - size of send buffer
1022 * result - TARGET_NATIVE_OK if no error occurred,
1023 * TARGET_NATIVE_ERROR otherwise
1024 * Return : -
1025 * Side-effect: unknown
1026 * Notes : -
1027 \***********************************************************************/
1029 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_SNDBUF
1030 #include <sys/types.h>
1031 #include <sys/socket.h>
1032 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_SNDBUF(socketDescriptor,size,result) \
1033 do { \
1034 int __value; \
1035 socklen_t __len; \
1037 size=0; \
1039 __len=sizeof(__value); \
1040 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_SNDBUF,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1041 if (result==TARGET_NATIVE_OK) \
1043 size=__value; \
1045 } while (0)
1046 #endif
1048 /***********************************************************************\
1049 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_RCDBUF
1050 * Purpose : get socket option SO_RCDBUF
1051 * Input : socketDescriptor - socket descriptor
1052 * Output : size - size of receive buffer
1053 * result - TARGET_NATIVE_OK if no error occurred,
1054 * TARGET_NATIVE_ERROR otherwise
1055 * Return : -
1056 * Side-effect: unknown
1057 * Notes : -
1058 \***********************************************************************/
1060 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_RCDBUF
1061 #include <sys/types.h>
1062 #include <sys/socket.h>
1063 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_SO_RCDBUF(socketDescriptor,size,result) \
1064 do { \
1065 int __value; \
1066 socklen_t __len; \
1068 size=0; \
1070 __len=sizeof(__value); \
1071 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_RCVBUF,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1072 if (result==TARGET_NATIVE_OK) \
1074 size=__value; \
1076 } while (0)
1077 #endif
1079 /***********************************************************************\
1080 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_TTL
1081 * Purpose : get socket option IP_TTL
1082 * Input : socketDescriptor - socket descriptor
1083 * Output : flag - 1 or 0
1084 * result - TARGET_NATIVE_OK if no error occurred,
1085 * TARGET_NATIVE_ERROR otherwise
1086 * Return : -
1087 * Side-effect: unknown
1088 * Notes : -
1089 \***********************************************************************/
1091 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_TTL
1092 #include <sys/types.h>
1093 #include <sys/socket.h>
1094 #include <netinet/in.h>
1095 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_TTL(socketDescriptor,flag,result) \
1096 do { \
1097 int __value; \
1098 socklen_t __len; \
1100 flag=0; \
1102 __len=sizeof(__value); \
1103 result=(getsockopt(socketDescriptor,IPPROTO_IP,IP_TTL,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1104 if (result==TARGET_NATIVE_OK) \
1106 flag=__value; \
1108 } while (0)
1109 #endif
1111 /***********************************************************************\
1112 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_MULTICAST_IF
1113 * Purpose : get socket option IP_MULTICAST_IF
1114 * Input : socketDescriptor - socket descriptor
1115 * Output : address - integer with IP address in host-format
1116 * result - TARGET_NATIVE_OK if no error occurred,
1117 * TARGET_NATIVE_ERROR otherwise
1118 * Return : -
1119 * Side-effect: unknown
1120 * Notes : -
1121 \***********************************************************************/
1123 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_MULTICAST_IF
1124 #include <sys/types.h>
1125 #include <sys/socket.h>
1126 #include <netinet/in.h>
1127 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_IP_MULTICAST_IF(socketDescriptor,address,result) \
1128 do { \
1129 struct sockaddr_in __socketAddress; \
1130 socklen_t __socketAddressLength; \
1132 address=0;\
1134 memset(&__socketAddress,0,sizeof(__socketAddress)); \
1135 __socketAddress.sin_family = AF_INET; \
1136 __socketAddress.sin_addr.s_addr = htonl(address); \
1137 __socketAddressLength=sizeof(__socketAddress); \
1138 result=(getsockopt(socketDescriptor,IPPROTO_IP,IP_MULTICAST_IF,&__socketAddress,&__socketAddressLength)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1139 if (result==TARGET_NATIVE_OK) \
1141 address=ntohl(__socketAddress.sin_addr.s_addr); \
1143 } while (0)
1144 #endif
1146 /***********************************************************************\
1147 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BIND_ADDRESS
1148 * Purpose : get socket option SOCKOPT_SO_BINDADDR
1149 * Input : socketDescriptor - socket descriptor
1150 * Output : address - integer with IP address in host-format
1151 * result - TARGET_NATIVE_OK if no error occurred,
1152 * TARGET_NATIVE_ERROR otherwise
1153 * Return : -
1154 * Side-effect: unknown
1155 * Notes : -
1156 \***********************************************************************/
1158 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BIND_ADDRESS
1159 #include <sys/types.h>
1160 #include <sys/socket.h>
1161 #include <netinet/in.h>
1162 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BIND_ADDRESS(socketDescriptor,address,result) \
1163 do { \
1164 struct sockaddr_in __socketAddress; \
1165 socklen_t __socketAddressLength; \
1167 address=0;\
1169 memset(&__socketAddress,0,sizeof(__socketAddress)); \
1170 __socketAddressLength=sizeof(__socketAddress); \
1171 result=(getsockname(socketDescriptor,(struct sockaddr*)&__socketAddress,&__socketAddressLength)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1172 if (result==TARGET_NATIVE_OK) \
1174 address=ntohl(__socketAddress.sin_addr.s_addr); \
1176 } while (0)
1177 #endif
1179 /***********************************************************************\
1180 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_REUSE_ADDRESS
1181 * Purpose : get socket option REUSE_ADDRESS
1182 * Input : socketDescriptor - socket descriptor
1183 * Output : flag - 1 or 0
1184 * result - TARGET_NATIVE_OK if no error occurred,
1185 * TARGET_NATIVE_ERROR otherwise
1186 * Return : -
1187 * Side-effect: unknown
1188 * Notes : -
1189 \***********************************************************************/
1191 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_REUSE_ADDRESS
1192 #include <sys/types.h>
1193 #include <sys/socket.h>
1194 #include <netinet/in.h>
1195 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_REUSE_ADDRESS(socketDescriptor,flag,result) \
1196 do { \
1197 int __value; \
1198 socklen_t __len; \
1200 flag=0; \
1202 __len=sizeof(__value); \
1203 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1204 if (result==TARGET_NATIVE_OK) \
1206 flag=__value; \
1208 } while (0)
1209 #endif
1211 /***********************************************************************\
1212 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_KEEP_ALIVE
1213 * Purpose : get socket option KEEP_ALIVE
1214 * Input : socketDescriptor - socket descriptor
1215 * Output : flag - 1 or 0
1216 * result - TARGET_NATIVE_OK if no error occurred,
1217 * TARGET_NATIVE_ERROR otherwise
1218 * Return : -
1219 * Side-effect: unknown
1220 * Notes : -
1221 \***********************************************************************/
1223 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_KEEP_ALIVE
1224 #include <sys/types.h>
1225 #include <sys/socket.h>
1226 #include <netinet/in.h>
1227 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_KEEP_ALIVE(socketDescriptor,flag,result) \
1228 do { \
1229 int __value; \
1230 socklen_t __len; \
1232 flag=0; \
1234 __len=sizeof(__value); \
1235 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_KEEPALIVE,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1236 if (result==TARGET_NATIVE_OK) \
1238 flag=__value; \
1240 } while (0)
1241 #endif
1243 /***********************************************************************\
1244 * Name : TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BROADCAST
1245 * Purpose : get socket option SO_BROADCAST
1246 * Input : socketDescriptor - socket descriptor
1247 * Output : flag - 1 or 0
1248 * result - TARGET_NATIVE_OK if no error occurred,
1249 * TARGET_NATIVE_ERROR otherwise
1250 * Return : -
1251 * Side-effect: unknown
1252 * Notes : -
1253 \***********************************************************************/
1255 #ifndef TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BROADCAST
1256 #include <sys/types.h>
1257 #include <sys/socket.h>
1258 #include <netinet/tcp.h>
1259 #define TARGET_NATIVE_NETWORK_SOCKET_GET_OPTION_BROADCAST(socketDescriptor,flag,result) \
1260 do { \
1261 int __value; \
1262 socklen_t __len; \
1264 flag=0; \
1266 __len=sizeof(__value); \
1267 result=(getsockopt(socketDescriptor,SOL_SOCKET,SO_BROADCAST,&__value,&__len)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
1268 if (result==TARGET_NATIVE_OK) \
1270 flag=__value; \
1272 } while (0)
1273 #endif
1275 /***************************** Functions *******************************/
1277 #ifdef __cplusplus
1278 extern "C" {
1279 #endif
1281 #ifdef __cplusplus
1283 #endif
1285 #endif /* __TARGET_GENERIC_NETWORK__ */
1287 /* end of file */