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
|
/****************************************************************
**
** PORTTCP.C - Support for portable TCP/IP
**
****************************************************************/
#define TCPIP_IBM_NOHIDE
#include <stdio.h>
#include "tcpip.h"
/*
* Common unknown error buffer
*/
static char ErrUnknownBuf[36];
#ifndef SockStrError
/****************************************************************
* Routine: SockStrError
* Returns: Pointer to static buffer
* Action : Convert SOCK_ERRNO into error text
****************************************************************/
const char *
SockStrError(int SockErrno)
{
#if defined (TCPIP_IBM) && defined (IBM_CPP)
switch (SockErrno)
{
case SOCEPERM: return "Not owner";
case SOCESRCH: return "No such process";
case SOCEINTR: return "Interrupted system call";
case SOCENXIO: return "No such device or address";
case SOCEBADF: return "Bad file number";
case SOCEACCES: return "Permission denied";
case SOCEFAULT: return "Bad address";
case SOCEINVAL: return "Invalid argument";
case SOCEMFILE: return "Too many open files";
case SOCEPIPE: return "Broken pipe";
case SOCEOS2ERR: return "OS/2 Error";
case SOCEWOULDBLOCK: return "Operation would block";
case SOCEINPROGRESS: return "Operation now in progress";
case SOCEALREADY: return "Operation already in progress";
case SOCENOTSOCK: return "Socket operation on non-socket";
case SOCEDESTADDRREQ: return "Destination address required";
case SOCEMSGSIZE: return "Message too long";
case SOCEPROTOTYPE: return "Protocol wrong type for socket";
case SOCENOPROTOOPT: return "Protocol not available";
case SOCEPROTONOSUPPORT: return "Protocol not supported";
case SOCESOCKTNOSUPPORT: return "Socket type not supported";
case SOCEOPNOTSUPP: return "Operation not supported on socket";
case SOCEPFNOSUPPORT: return "Protocol family not supported";
case SOCEAFNOSUPPORT:
return "Address family not supported by protocol family";
case SOCEADDRINUSE: return "Address already in use";
case SOCEADDRNOTAVAIL: return "Can't assign requested address";
case SOCENETDOWN: return "Network is down";
case SOCENETUNREACH: return "Network is unreachable";
case SOCENETRESET: return "Network dropped connection on reset";
case SOCECONNABORTED: return "Software caused connection abort";
case SOCECONNRESET: return "Connection reset by peer";
case SOCENOBUFS: return "No buffer space available";
case SOCEISCONN: return "Socket is already connected";
case SOCENOTCONN: return "Socket is not connected";
case SOCESHUTDOWN: return "Can't send after socket shutdown";
case SOCETOOMANYREFS: return "Too many references: can't splice";
case SOCETIMEDOUT: return "Connection timed out";
case SOCECONNREFUSED: return "Connection refused";
case SOCELOOP: return "Too many levels of symbolic links";
case SOCENAMETOOLONG: return "File name too long";
case SOCEHOSTDOWN: return "Host is down";
case SOCEHOSTUNREACH: return "No route to host";
case SOCENOTEMPTY: return "Directory not empty";
default:
sprintf( ErrUnknownBuf, "SockStrErrno( %d ) unknown", SockErrno );
return ErrUnknownBuf;
}
#else
#error SockStrError not supported for this OS
#endif
}
#endif /* SockStrError */
/****************************************************************
* Routine: HostStrError
* Returns: Pointer to static buffer
* Action : Convert HOST_ERRNO into error text
****************************************************************/
const char *
HostStrError(int HostErrno)
{
switch (HostErrno)
{
case HOST_NOT_FOUND:
return "Host not found";
case TRY_AGAIN:
return "Host not found (suggest try again)";
case NO_RECOVERY:
return "Non-recoverable error: FORMERR, REFUSED, NOTIMP";
case NO_DATA:
return "No Data (valid name, but no record of requested type)";
default:
sprintf( ErrUnknownBuf, "HostStrErrno( %d ) unknown", HostErrno );
return ErrUnknownBuf;
}
}
#if defined( TCPIP_IBM )
/****************************************************************
* Routine: IbmSockSend
* Returns: same as send
* Action : Do the right thing for IBM TCP/IP which includes
* the following two stupidities:
* 1) Never try to send more than 32K
* 2) Never pass a buffer that crosses a 64K boundary
* If Flags is non-zero, this function only attempts
* to deal with condition (1) above.
****************************************************************/
int
IbmSockSend (int Socket, const void *Buffer, int Len, int Flags)
{
int Sent, ToSend, TotalSent = 0;
const char *Tmp = Buffer;
/*
* If Flags have been passed in, the 64K boundary optimization
* can not be performed. For example, MSG_PEEK would not work
* correctly.
*/
if (Flags)
return send (Socket, (char *) Buffer, min (0x7FFF, Len), Flags);
do
{
/* Never send across a 64K boundary */
ToSend = min (Len, (int) (0x10000 - (0xFFFF & (long) Tmp)));
/* Never send more than 32K */
if (ToSend > 0x7FFF)
ToSend = 0x7FFF;
Sent = send (Socket, (char *) Tmp, ToSend, 0);
if (Sent < 0)
{
if ((TotalSent > 0) && (SOCK_ERRNO == EWOULDBLOCK))
return TotalSent;
if (SOCK_ERRNO == EINTR)
continue;
return Sent;
}
if (Sent < ToSend)
return TotalSent + Sent;
Tmp += Sent;
TotalSent += Sent;
Len -= Sent;
} while (Len > 0);
return TotalSent;
}
/****************************************************************
* Routine: IbmSockRecv
* Returns: same as recv
* Action : Do the right thing for IBM TCP/IP which includes
* the following two stupidities:
* 1) Never try to recv more than 32K
* 2) Never pass a buffer that crosses a 64K boundary
* If Flags is non-zero, this function only attempts
* to deal with condition (1) above.
****************************************************************/
int
IbmSockRecv (int Socket, const void *Buffer, int Len, int Flags)
{
int Recvd, ToRecv, TotalRecvd = 0;
char *Tmp = Buffer;
/* If Flags have been passed in, the 64K boundary optimization
probably can not be performed. */
if (Flags)
return recv (Socket, Buffer, min (0x7FFF, Len), Flags);
do
{
/* Never send across a 64K boundary */
ToRecv = min( Len, (int)( 0x10000 - ( 0xFFFF & (long)Tmp )));
/* Never send more than 32K */
if( ToRecv > 0x7FFF )
ToRecv = 0x7FFF;
Recvd = recv (Socket, Tmp, ToRecv, 0);
if (Recvd <= 0)
{
if ((TotalRecvd > 0)
&& (Recvd == 0 || (SOCK_ERRNO == EWOULDBLOCK )))
return TotalRecvd;
if (SOCK_ERRNO == EINTR)
continue;
return Recvd;
}
if (Recvd < ToRecv)
return TotalRecvd + Recvd;
Tmp += Recvd;
TotalRecvd += Recvd;
Len -= Recvd;
} while (Len > 0);
return TotalRecvd;
}
#endif /* defined( TCPIP_IBM ) */
|