#ifndef INCLUDED_TCP
#define INCLUDED_TCP 1

#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif


#ifdef WIN32
#define WIN_SOCK TRUE
#endif
#ifdef WIN_SOCK
#define FD_SETSIZE 256
#include <winsock.h>
#define socket_close closesocket
#define socket_ioctl ioctlsocket
#define socket_read(s,b,l) recv(s,b,l,0)
#define socket_write(s,b,l) send(s,b,l,0)
#endif

#ifdef NETWARE
#define NEED_DTABLE TRUE
#endif

#ifdef __MWERKS__ /*RHP we will take this to mean we are making a Mac version*/
#include "Mac.h"
#include "sys/types.h"
#include "netinet/in.h"
#include "sys/socket.h"
#include "sys/ioctl.h"
#include "netdb.h"
#include "sys/time.h"
#include "socket.ext.h"
#include "MacSockDefs.h"
#endif

#ifdef isunix
#define SOCKET_DEF TRUE
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#ifdef SCO
#include "myhostdb.h"
#else
#include <netdb.h>
#endif /* SCO */
#include <sys/time.h>
#ifndef OS2
#include <unistd.h>
#endif /* os2 */

#ifdef LINUX
#include <netinet/in.h>
#else /* This one works for solaris , why the hell isn't it standardized */
#ifdef SCO
#include <sys/netinet/in.h>
#else
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif /* LINUX */
#endif /* SCO*/
#endif /* UNIX */


#ifdef SOCKET_DEF
#define socket_close close
#define socket_open open
#define socket_read read
#define socket_ioctl ioctl
#define socket_write write
#define NEED_BCOPY TRUE
#endif

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#ifdef NETWARE
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netdb.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#define socket_read(s,b,l) recv(s,b,l,0)
#define socket_write(s,b,l) send(s,b,l,0)
#define socket_close close
#define socket_ioctl ioctl
NETDB_DEFINE_CONTEXT
NETINET_DEFINE_CONTEXT
#endif

#ifdef WIN_SOCK
#else
#define SOCKET short
#endif


#ifdef DOCAST
#define ONCAST (char *)
#else
#define ONCAST
#endif



#include <stdarg.h>
int tcp_multicast_ttl(SOCKET fd, int ttl) ;

SOCKET tcp_openx(char *name, int port, char *bind);
void tcp_startup(void);
int tcp_read(SOCKET sk, char *bf, int len);
char *tcp_hostname(void);
char *tcperror(void);
void tcp_lasterror(void);
int  tcp_printf(SOCKET sk,char * arg_list, ...);
SOCKET tcp_listen(int port);
SOCKET tcp_accept(SOCKET xlisten);
int tcp_readln(SOCKET sk, char *bf, int maxlen);
int socket_read_timed(SOCKET sk, char *bf, int len, int msec);
int tcp_setlinger(SOCKET sk);
int tcp_write(SOCKET sk, char *bf, int maxlen);
SOCKET tcp_create_udp(char *lclname, int lport, char *rname, int rport);
int tcp_nextwait(int msec);

int socket_writebf(SOCKET sk, char *s, int len);
int xsocket_write(SOCKET sk, char *s, int len);
void socket_flush(SOCKET sk);
void tcp_setblockraw(SOCKET c, int t);
int tcp_waitlist(SOCKET list[], int nlist, int isready[], int msec);
int tcp_setdelay(SOCKET sk, int t);
void tcp_setsndbf_raw(SOCKET c, int sz);

int tcp_waitfor(SOCKET sk, int msec);
#ifndef INVALID_SOCKET
#define INVALID_SOCKET -1
#endif
#endif