RSA BSAFE Micro Edition Suite

Streamlined security for mobile and embedded devices

Search  Print

r_sock.h

Go to the documentation of this file.
00001 /* $Id: r_sock.h,v 1.21.6.1 2005/10/13 06:44:37 gsingh Exp $ */
00002 /*
00003  * Copyright (C) 1998-2003 RSA Security Inc. All rights reserved.
00004  *
00005  * This work contains proprietary information of RSA Security.
00006  * Distribution is limited to authorized licensees of RSA
00007  * Security. Any unauthorized reproduction, distribution or
00008  * modification of this work is strictly prohibited.
00009  */
00015 #ifndef HEADER_COMMON_R_SOCK_H
00016 #define HEADER_COMMON_R_SOCK_H
00017 
00018 
00019 #ifdef  __cplusplus
00020 extern "C" {
00021 #endif
00022 
00023 #include "r_platf.h"
00024 
00025 #if defined(WINDOWS) || defined(WIN32)
00026 
00027 #define get_last_socket_error()       WSAGetLastError()
00028 #define clear_socket_error()          WSASetLastError(0)
00029 #define readsocket(s,b,n)             recv((s),(b),(n),0)
00030 #define writesocket(s,b,n)            send((s),(b),(n),0)
00031 #define EADDRINUSE                    WSAEADDRINUSE
00032 
00033 #else /* !WINDOWS */
00034 
00035 #define get_last_socket_error()       errno
00036 #define clear_socket_error()          errno=0
00037 #ifdef VXWORKS
00038 /*
00039  * Vxworks ioctl prototype expects an int
00040  */
00041 #define ioctlsocket(a,b,c)            ioctl(a,b,(int)c)
00042 #else /* !VXWORKS */
00043 #define ioctlsocket(a,b,c)            ioctl(a,b,c)
00044 #endif /* VXWORKS */
00045 #ifndef closesocket
00046 #define closesocket(s)                close(s)
00047 #endif /*closesocket*/
00048 
00049 
00050 /*
00051  * Epoc read function waits for passed in buffer to
00052  * fill completely before returning so use recv instead
00053  */
00054 #if  defined (PLATFORM_EPOC) || (R_OS == R_OS_NUCLEUS)
00055 #define readsocket(s,b,n)             recv((s),(b),(n),0)
00056 #define writesocket(s,b,n)            send((s),(b),(n),0)
00057 #else  /* !PLATFORM_EPOC */
00058 
00059 #define readsocket(s,b,n)             read((s),(b),(n))
00060 #define writesocket(s,b,n)            write((s),(b),(n))
00061 
00062 #endif /* PLATFORM_EPOC */
00063 
00064 #endif /* WINDOWS || WIN32 */
00065 
00066 /* the return type from lseek varies across platforms - the R_LSEEK_RET_CAST
00067  * macro is used to allow for this difference without adding platform
00068  * testing logic in the code that uses lseek
00069  */
00070 #if ((defined (WINDOWS) || defined(MSDOS) || defined(WIN32)) && \
00071     !defined(UNDER_CE)) || (R_OS == R_OS_NUCLEUS)
00072 #define R_LSEEK_RET_CAST(offset) ((long)(offset))
00073 #else  /* !WINDOWS || MSDOS ||WIN32 && !UNDER_CE */
00074 #define R_LSEEK_RET_CAST(offset) ((off_t)(offset))
00075 #endif  /* !WINDOWS || MSDOS ||WIN32 && !UNDER_CE */
00076 
00077 #if defined(WINDOWS) || defined(MSDOS) || defined(WIN32)
00078 
00079 #ifdef NO_SOCK
00080 #define SHUTDOWN(fd)            close(fd)
00081 #define SHUTDOWN2(fd)           close(fd)
00082 #else /* !NO_SOCK */
00083 #ifdef SPEC
00084 #include <winsock2.h>
00085 #else
00086 #include <winsock.h>
00087 #endif
00088 #define SHUTDOWN(fd)            { shutdown((fd),0); closesocket(fd); }
00089 #define SHUTDOWN2(fd)           { shutdown((fd),2); closesocket(fd); }
00090 #endif /* NO_SOCK */
00091 
00092 #else /* !(WINDOWS || MSDOS || WIN32) */
00093 
00094 #if !defined(VMS)
00095 
00096 /* Unix or Unix-like platforms */
00097 #ifndef NO_GETHOSTBYNAME
00098 
00099 #if (R_OS != R_OS_NUCLEUS)
00100 
00101 #include <netdb.h>
00102 
00103 #else /* R_OS_NUCLEUS */
00104 
00105 #include <r_nucleus.h>
00106 
00107 #endif /* !R_OS_NUCLEUS */
00108 
00109 
00110 
00111 #else /* !NO_GETHOSTBYNAME */
00112 #define NO_NETDB_H
00113 #endif /* !NO_GETHOSTBYNAME */
00114 
00115 #ifdef UNDER_PALMOS
00116 
00117 #include <sys_types.h>
00118 #include <sys_socket.h>
00119 
00120 #ifndef FIONBIO
00121 #define FIONBIO FNDELAY
00122 #endif /* FIONBIO */
00123 
00124 #else /* !UNDER_PALMOS */
00125 
00126 #if (R_OS != R_OS_NUCLEUS)
00127 
00128 #include <sys/types.h>
00129 #include <sys/socket.h>
00130 
00131 #endif /* !R_OS_NUCLEUS */
00132 
00133 #endif /* !UNDER_PALMOS */
00134 
00135 #ifdef __EPOC32__
00136 /*
00137  * EPOC uses bzero() in the FD_ZERO macro.
00138  * We don't want to use this function (NON-ANSI),
00139  * so we redefie the FD_ZERO macro
00140  */
00141 #ifdef FD_ZERO
00142 #undef FD_ZERO
00143 #define FD_ZERO(p)      Memset( (caddr_t)(p), 0, sizeof (*(p)) )
00144 #endif
00145 #endif /* __EPOC32__ */
00146 
00147 #ifdef FILIO_H
00148 #include <sys/filio.h>        /* Added for FIONBIO under unixware */
00149 #endif /* FILIO_H */
00150 
00151 #if !defined(VXWORKS) && !defined(R_PLATFORM_PSOS) && !defined(R_OS_NUCLEUS)
00152 #ifdef UNDER_PALMOS
00153 #include <sys_time.h>         /* for FD_XXX macros */
00154 #else /* !UNDER_PALMOS */
00155 #ifndef MACOS
00156 #include <sys/param.h>
00157 #endif /* !MACOS */
00158 #include <sys/time.h>         /* for FD_XXX macros */
00159 #endif /* !UNDER_PALMOS */
00160 #endif /* !VXWORKS */
00161 
00162 #ifdef UNDER_PALMOS
00163 #include <netinet_in.h>
00164 #else /* !UNDER_PALMOS */
00165 
00166 #if (R_OS != R_OS_NUCLEUS)
00167 #include <netinet/in.h>
00168 #endif /* !R_OS_NUCLEUS */
00169 
00170 #endif /* !UNDER_PALMOS */
00171 
00172 #endif /* !VMS */
00173 
00174 #if defined(NeXT) || defined(_NEXT_SOURCE)
00175 #include <sys/fcntl.h>
00176 #include <sys/types.h>
00177 #endif /* NeXT || _NEXT_SOURCE */
00178 
00179 #ifdef VXWORKS
00180 #include <ioLib.h>     /* Includes the ioctl command values */
00181 #include <sockLib.h>
00182 #include <selectLib.h>
00183 #endif /* VXWORKS */
00184 
00185 #if defined(AIX) || defined(QNX)
00186 #include <sys/select.h>
00187 #endif /* AIX || QNX */
00188 
00189 #if defined(sun) || defined(linux)
00190 #include <netinet/tcp.h>
00191 #endif /* sun || linux */
00192 
00193 #if defined(sun)
00194 #include <sys/filio.h>
00195 #else /* !sun */
00196 #if !defined(UNDER_PALMOS) && !defined(R_PLATFORM_PSOS) && \
00197     (R_OS != R_OS_NUCLEUS)
00198 #include <sys/ioctl.h>
00199 #endif /* !UNDER_PALMOS && !R_PLATFORM_PSOS && !R_OS_NUCLEUS */
00200 #endif /* !sun */
00201 
00202 #ifdef VMS
00203 #include <unixio.h>
00204 #endif /* VMS */
00205 
00206 #define SHUTDOWN(fd)    { shutdown((fd),0); close((fd)); }
00207 #define SHUTDOWN2(fd)   { shutdown((fd),2); close((fd)); }
00208 
00209 #if (R_OS != R_OS_NUCLEUS)
00210 #define INVALID_SOCKET    (-1)
00211 #endif /* !R_OS_NUCLEUS */
00212 
00213 #endif /* !(WINDOWS || MSDOS || WIN32) */
00214 
00215 #ifdef  __cplusplus
00216 }
00217 #endif
00218 
00219 #endif /* HEADER_COMMON_R_SOCK_H */
00220 
00221 

Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 072-001001-2100-001-000 - 2.1