471 |
do { \ |
do { \ |
472 |
int __value; \ |
int __value; \ |
473 |
\ |
\ |
474 |
|
bytesAvailable=0; \ |
475 |
|
\ |
476 |
result=(ioctl(socketDescriptor,FIONREAD,&__value)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
result=(ioctl(socketDescriptor,FIONREAD,&__value)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \ |
477 |
if (result==TARGET_NATIVE_OK) \ |
if (result==TARGET_NATIVE_OK) \ |
478 |
{ \ |
{ \ |
487 |
* Input : socketDescriptor - socket descriptor |
* Input : socketDescriptor - socket descriptor |
488 |
* maxLength - max. size of bfufer |
* maxLength - max. size of bfufer |
489 |
* Output : buffer - received data |
* Output : buffer - received data |
490 |
|
* bytesReceive - length of received data |
491 |
|
* Return : - |
492 |
|
* Side-effect: unknown |
493 |
|
* Notes : - |
494 |
|
\***********************************************************************/ |
495 |
|
|
496 |
|
#ifndef TARGET_NATIVE_NETWORK_SOCKET_RECEIVE |
497 |
|
#include <sys/types.h> |
498 |
|
#include <sys/socket.h> |
499 |
|
#include <netinet/in.h> |
500 |
|
#define TARGET_NATIVE_NETWORK_SOCKET_RECEIVE(socketDescriptor,buffer,maxLength,bytesReceived) \ |
501 |
|
do { \ |
502 |
|
struct sockaddr_in __socketAddress; \ |
503 |
|
socklen_t __socketAddressLength; \ |
504 |
|
\ |
505 |
|
memset(&__socketAddress,0,sizeof(__socketAddress)); \ |
506 |
|
__socketAddressLength=sizeof(__socketAddress); \ |
507 |
|
bytesReceived=recv(socketDescriptor,buffer,maxLength,0); \ |
508 |
|
} while (0) |
509 |
|
#endif |
510 |
|
|
511 |
|
/***********************************************************************\ |
512 |
|
* Name : TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT |
513 |
|
* Purpose : receive data from socket |
514 |
|
* Input : socketDescriptor - socket descriptor |
515 |
|
* maxLength - max. size of bfufer |
516 |
|
* Output : buffer - received data |
517 |
* address - from address (NOT in network byte order!) |
* address - from address (NOT in network byte order!) |
518 |
* port - from port (NOT in network byte order!) |
* port - from port (NOT in network byte order!) |
519 |
* bytesReceive - length of received data |
* bytesReceive - length of received data |
522 |
* Notes : - |
* Notes : - |
523 |
\***********************************************************************/ |
\***********************************************************************/ |
524 |
|
|
525 |
#ifndef TARGET_NATIVE_NETWORK_SOCKET_RECEIVE |
#ifndef TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT |
526 |
#include <sys/types.h> |
#include <sys/types.h> |
527 |
#include <sys/socket.h> |
#include <sys/socket.h> |
528 |
#include <netinet/in.h> |
#include <netinet/in.h> |
529 |
#define TARGET_NATIVE_NETWORK_SOCKET_RECEIVE(socketDescriptor,buffer,maxLength,address,port,bytesReceived) \ |
#define TARGET_NATIVE_NETWORK_SOCKET_RECEIVE_WITH_ADDRESS_PORT(socketDescriptor,buffer,maxLength,address,port,bytesReceived) \ |
530 |
do { \ |
do { \ |
531 |
struct sockaddr_in __socketAddress; \ |
struct sockaddr_in __socketAddress; \ |
532 |
socklen_t __socketAddressLength; \ |
socklen_t __socketAddressLength; \ |
533 |
\ |
\ |
534 |
address=0; \ |
port=0; \ |
|
port =0; \ |
|
535 |
\ |
\ |
536 |
memset(&__socketAddress,0,sizeof(__socketAddress)); \ |
memset(&__socketAddress,0,sizeof(__socketAddress)); \ |
537 |
__socketAddressLength=sizeof(__socketAddress); \ |
__socketAddressLength=sizeof(__socketAddress); \ |
538 |
bytesReceived=recvfrom(socketDescriptor,buffer,maxLength,0,(struct sockaddr*)&__socketAddress,&__socketAddressLength); \ |
bytesReceived=recvfrom(socketDescriptor,buffer,maxLength,0,(struct sockaddr*)&__socketAddress,&__socketAddressLength); \ |
539 |
if (bytesReceived>=0) \ |
if (__socketAddressLength==sizeof(__socketAddress)) \ |
540 |
{ \ |
{ \ |
|
assert(__socketAddressLength>=sizeof(__socketAddress)); \ |
|
541 |
address=ntohl(__socketAddress.sin_addr.s_addr); \ |
address=ntohl(__socketAddress.sin_addr.s_addr); \ |
542 |
port =ntohs(__socketAddress.sin_port); \ |
port =ntohs(__socketAddress.sin_port); \ |
543 |
} \ |
} \ |
550 |
* Input : socketDescriptor - socket descriptor |
* Input : socketDescriptor - socket descriptor |
551 |
* : buffer - data to send |
* : buffer - data to send |
552 |
* length - length of data to send |
* length - length of data to send |
553 |
|
* Output : bytesSent - number of bytes sent, -1 otherwise |
554 |
|
* Side-effect: unknown |
555 |
|
* Notes : - |
556 |
|
\***********************************************************************/ |
557 |
|
|
558 |
|
#ifndef TARGET_NATIVE_NETWORK_SOCKET_SEND |
559 |
|
#include <sys/types.h> |
560 |
|
#include <sys/socket.h> |
561 |
|
#include <netinet/in.h> |
562 |
|
#define TARGET_NATIVE_NETWORK_SOCKET_SEND(socketDescriptor,buffer,length,bytesSent) \ |
563 |
|
do { \ |
564 |
|
bytesSent=send(socketDescriptor,buffer,length,0); \ |
565 |
|
} while (0) |
566 |
|
#endif |
567 |
|
|
568 |
|
/***********************************************************************\ |
569 |
|
* Name : TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT |
570 |
|
* Purpose : send data to socket |
571 |
|
* Input : socketDescriptor - socket descriptor |
572 |
|
* : buffer - data to send |
573 |
|
* length - length of data to send |
574 |
* Address - to address (NOT in network byte order!) |
* Address - to address (NOT in network byte order!) |
575 |
* Port - to port (NOT in network byte order!) |
* Port - to port (NOT in network byte order!) |
576 |
* Output : bytesSent - number of bytes sent, -1 otherwise |
* Output : bytesSent - number of bytes sent, -1 otherwise |
578 |
* Notes : - |
* Notes : - |
579 |
\***********************************************************************/ |
\***********************************************************************/ |
580 |
|
|
581 |
#ifndef TARGET_NATIVE_NETWORK_SOCKET_SEND |
#ifndef TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT |
582 |
#include <sys/types.h> |
#include <sys/types.h> |
583 |
#include <sys/socket.h> |
#include <sys/socket.h> |
584 |
#include <netinet/in.h> |
#include <netinet/in.h> |
585 |
#define TARGET_NATIVE_NETWORK_SOCKET_SEND(socketDescriptor,buffer,length,address,port,bytesSent) \ |
#define TARGET_NATIVE_NETWORK_SOCKET_SEND_WITH_ADDRESS_PORT(socketDescriptor,buffer,length,address,port,bytesSent) \ |
586 |
do { \ |
do { \ |
587 |
struct sockaddr_in __socketAddress; \ |
struct sockaddr_in __socketAddress; \ |
588 |
\ |
\ |
589 |
if (address!=0) \ |
memset(&__socketAddress,0,sizeof(__socketAddress)); \ |
590 |
{ \ |
__socketAddress.sin_family = AF_INET; \ |
591 |
memset(&__socketAddress,0,sizeof(__socketAddress)); \ |
__socketAddress.sin_addr.s_addr = htonl(address); \ |
592 |
__socketAddress.sin_family = AF_INET; \ |
__socketAddress.sin_port = htons((short)port); \ |
593 |
__socketAddress.sin_addr.s_addr = htonl(address); \ |
bytesSent=sendto(socketDescriptor,buffer,length,0,(struct sockaddr*)&__socketAddress,sizeof(__socketAddress)); \ |
|
__socketAddress.sin_port = htons((short)port); \ |
|
|
bytesSent=sendto(socketDescriptor,buffer,length,0,(struct sockaddr*)&__socketAddress,sizeof(__socketAddress)); \ |
|
|
} \ |
|
|
else \ |
|
|
{ \ |
|
|
bytesSent=sendto(socketDescriptor,buffer,length,0,NULL,0); \ |
|
|
} \ |
|
594 |
} while (0) |
} while (0) |
595 |
#endif |
#endif |
596 |
|
|
1214 |
#endif /* __TARGET_GENERIC_NETWORK__ */ |
#endif /* __TARGET_GENERIC_NETWORK__ */ |
1215 |
|
|
1216 |
/* end of file */ |
/* end of file */ |
1217 |
|
|