113571821Stholo /**************************************************************** 213571821Stholo * 313571821Stholo * TCPIP.H - Portable TCP/IP header file 413571821Stholo * 513571821Stholo * TCP/IP on OS/2 is an add-on and thus is not fully integrated 613571821Stholo * with the operating system. To ensure portability, follow 713571821Stholo * these rules: 813571821Stholo * 913571821Stholo * * Always call SockInit() at the beginning of your program 1013571821Stholo * and check that it returns TRUE. 1113571821Stholo * 1213571821Stholo * * Use SockSend() & SockRecv() instead of read(), write(), 1313571821Stholo * send(), or recv() when working with sockets. 1413571821Stholo * 1513571821Stholo * * Use SockClose() instead of close() with sockets. 1613571821Stholo * 1713571821Stholo * * Use SOCK_ERRNO when using functions that use or return 1813571821Stholo * sockets, such as SockSend() or accept(). 1913571821Stholo * 2013571821Stholo * * Use HOST_ERRNO when using gethostbyname() or gethostbyaddr() 2113571821Stholo * functions. 2213571821Stholo * 2313571821Stholo * * As far as I can tell, getservbyname() and related functions 2413571821Stholo * never set any error variable. 2513571821Stholo * 2613571821Stholo * * Use SockStrError() & HostStrError() to convert SOCK_ERRNO 2713571821Stholo * and HOST_ERRNO to error strings. 2813571821Stholo * 2913571821Stholo * * In .MAK files, include $(TCPIP_MAK) & use $(TCPIPLIB) 3013571821Stholo * when linking applications using TCP/IP. 3113571821Stholo * 3213571821Stholo ****************************************************************/ 3313571821Stholo 3413571821Stholo #if !defined( IN_TCPIP_H ) 3513571821Stholo #define IN_TCPIP_H 3613571821Stholo 3713571821Stholo #include <sys/types.h> 3813571821Stholo #include <sys/stat.h> 3913571821Stholo #include <sys/socket.h> 4013571821Stholo #include <sys/ioctl.h> 4113571821Stholo #include <netinet/in.h> 4213571821Stholo #include <netdb.h> 4313571821Stholo #include <errno.h> 4413571821Stholo 4513571821Stholo #if defined( TCPIP_IBM ) 46*461cc63eStholo /* Here comes some ugly stuff: The watcom compiler and the IBM TCPIP 47*461cc63eStholo * toolkit do not work together very well. The return codes for the 48*461cc63eStholo * socket calls are not integrated into the usual error codes, there 49*461cc63eStholo * are separate values instead. This results in a crash for two values. 50*461cc63eStholo * Since these values are not needed for socket access as far as I can 51*461cc63eStholo * see, I will save those values and redefine them after including 52*461cc63eStholo * nerrno.h (types.h will include nerrno.h, so this is needed here). 53*461cc63eStholo */ 54*461cc63eStholo # ifdef __WATCOMC__ 55*461cc63eStholo /* First check the numeric values */ 56*461cc63eStholo # if ENAMETOOLONG != 35 57*461cc63eStholo # error "ENAMETOOLONG: value unknown" 58*461cc63eStholo # endif 59*461cc63eStholo # if ENOTEMPTY != 39 60*461cc63eStholo # error "ENOTEMPTY: value unknown" 61*461cc63eStholo # endif 62*461cc63eStholo # undef ENAMETOOLONG 63*461cc63eStholo # undef ENOTEMPTY 64*461cc63eStholo # include <nerrno.h> 65*461cc63eStholo # undef ENAMETOOLONG 66*461cc63eStholo # undef ENOTEMPTY 67*461cc63eStholo # define ENAMETOOLONG 35 68*461cc63eStholo # define ENOTEMPTY 39 69*461cc63eStholo # endif 7013571821Stholo # include <types.h> 7113571821Stholo # if !defined( TCPIP_IBM_NOHIDE ) 7213571821Stholo # define send IbmSockSend 7313571821Stholo # define recv IbmSockRecv 7413571821Stholo # endif 7513571821Stholo #endif 7613571821Stholo 7713571821Stholo #if defined( TCPIP_IBM ) 7813571821Stholo # define BSD_SELECT 7913571821Stholo # include <sys/select.h> 8013571821Stholo # include <sys/time.h> 8113571821Stholo # include <nerrno.h> 8213571821Stholo # include <utils.h> 8313571821Stholo # if defined( MICROSOFT ) 8413571821Stholo # define SOCK_ERRNO (tcperrno()) 8513571821Stholo # else 8613571821Stholo # define SOCK_ERRNO (sock_errno()) 8713571821Stholo # endif 8813571821Stholo # define HOST_ERRNO (h_errno) 8913571821Stholo # define SockClose(S) soclose(S) 9013571821Stholo # define SockInit() (!sock_init()) 9113571821Stholo # define SockSend IbmSockSend 9213571821Stholo # define SockRecv IbmSockRecv 9313571821Stholo 9413571821Stholo const char *HostStrError(int HostErrno); 9513571821Stholo const char *SockStrError(int SockErrno); 9613571821Stholo 9713571821Stholo int IbmSockSend (int Socket, const void *Buffer, int Len, int Flags); 9813571821Stholo int IbmSockRecv (int Socket, const void *Buffer, int Len, int Flags); 9913571821Stholo 10013571821Stholo #if !defined( h_errno ) 10113571821Stholo extern int h_errno; /* IBM forgot to declare this in current header files */ 10213571821Stholo #endif 10313571821Stholo 10413571821Stholo #elif defined( __unix ) 10513571821Stholo # if defined( sgi ) /* SGI incorrectly defines FD_ZERO in sys/select.h */ 10613571821Stholo # include <bstring.h> 10713571821Stholo # endif 10813571821Stholo # if defined( sunos ) 10913571821Stholo extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *); 11013571821Stholo # else 11113571821Stholo # include <sys/select.h> 11213571821Stholo # endif 11313571821Stholo # include <sys/time.h> 11413571821Stholo # include <errno.h> 11513571821Stholo # include <arpa/inet.h> 11613571821Stholo # define SOCK_ERRNO errno 11713571821Stholo # define HOST_ERRNO h_errno 11813571821Stholo # define SockClose(S) close(S) 11913571821Stholo # define SockInit() TRUE 12013571821Stholo # define SockSend send 12113571821Stholo # define SockRecv recv 12213571821Stholo # define SockStrError(E) strerror(E) 12313571821Stholo 12413571821Stholo const char *HostStrError( int HostErrno ); 12513571821Stholo 12613571821Stholo #else 12713571821Stholo # error Undefined version of TCP/IP specified 12813571821Stholo 12913571821Stholo #endif 13013571821Stholo 13113571821Stholo #endif 132