/*
     SCOL sockets - Unix  . Magma 1.0 . 1996 . Sylvain HUET

     socket.h : definitions des routines sockets bas-niveau
*/
// Modification history:
//
//$ FA(02/07/2001): Define SOCKET are related constants here
//

#ifndef _SOCKET_H_
#define _SOCKET_H_

#undef EXT
#ifndef SCOL_SOCKET_C
  #define EXT extern
#else
  #define EXT
#endif

extern int socklife;
extern int STDPORT;
extern int localscolIP;
extern int proxyIp;
extern int proxyPort;
extern int proxyMask;

EXT int socklife;
EXT int sockudp;
EXT int SCOLport;

EXT char *http_proxy_host;
EXT int http_proxy_port;


#include "vscol.h"

#ifdef VERSION_WIN
  #include <windows.h>
  #define WSA_ASYNC WM_USER+1
  #define WSA_GETHOST WM_USER+2
  #define WSA_LOOP WM_USER+3
	
EXT int SCKstarthostname(HWND h);
EXT int SCKendhostname(LONG lParam);
#endif

#if defined(VERSION_X11) || defined(VERSION_NOX)
//$ FA(02/07/2001)
#define SOCKET int
#define SOCKADDR_IN struct sockaddr_in
#define INVALID_SOCKET -1
#define HANDLE FILE*
#define INVALID_HANDLE_VALUE NULL
#define closesocket close
//

#define FD_ACCEPT   1
#define FD_READ     2
#define FD_WRITE    3
#define FD_CLOSE    4
#define FD_CONNECT  5

#define SC_NONE      (-1)
#define SC_TYPCHN      0
#define SC_TYPSRV      1
#define SC_TYPUDP      2
#define SC_TYPHTTP     3
#define SC_TYPHTTPSRV  4
#define SC_TYPTELNET   5
#define SC_TYPINET     6
#endif

EXT int  SCKaddsock(int s,int typ);
EXT int  SCKdelsock(int s);
EXT int  SCKclrwrite(int s);
EXT int  SCKsetwrite(int s);
EXT int  SCKinit(void* x);
EXT int  SCKend();
EXT int  SCKsetproxy(char *ip, char *port,char *mask);
EXT int  SCKloopbackIP();
EXT int  SCKgethostIP();
EXT int  SCKgetnbIP();
EXT int  SCKgetnthIP(char *buf,int i);
EXT char *SCKhostname(char *buf);
EXT char *SCKhostIP(char *buf);
EXT char *SCKgetstringbyip(char *buf,int ip,int port);
EXT char *SCKgetstringbyip2(char *buf,int ip);
EXT char *SCKgethostbyname(char *buf,char *name);
EXT char *SCKgetnamebyIP(char *buf,char *IP);
EXT int  SCKstartserver(int port);
EXT int  SCKaccept(int s,int *ip,int *port);
EXT int  SCKconnect(char *addr,int *ip,int *port, int *proxy);
EXT int  SCKstartudpserver(int port);
EXT int  SCKsendudp(char *addr,char *txt, int len);
EXT int  SCKsendudpchn(int sock,char *addr,char *txt, int len);
EXT int  SCKclose(int s);
EXT int  SCKcloseserver(int s);
EXT int  SCKsend(int s,char *buf, int len);
EXT int  SCKrecv(int s,char *buf, int len,int *ip,int *port);
EXT int  SCKpostclose(int s);

#ifndef INADDR_NONE
#define INADDR_NONE ((uint32_t) 0xffffffff)
#endif
extern char forcedIP[64];
int SCKbindadress();
int SCKlocalconnection();

#endif // socket.h
