/* FotonSoft socket function for FotonCom II under __LINUX__ , __WIN32__ */

#ifndef FOTONSOFT_SOCKETS
#define FOTONSOFT_SOCKETS


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "thread.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>


#define INVALID_SOCKET		-1
#define SOCKET_ERROR		-1

typedef int		SOCKET;
typedef struct hostent		HOSTENT;
typedef struct sockaddr		SOCKADDR;
typedef SOCKADDR *		LPSOCKADDR;
typedef struct sockaddr_in	SOCKADDR_IN;
typedef SOCKADDR_IN *		LPSOCKADDR_IN;


int gethostname( char *name , size_t len);	/* miert kell nekem az unistd-s mokat feluldeklaralni, hogy pedans legyen???? */
/*int snprintf( char *str, size_t size, const char *format, ...);	*/

#define closesocket(a)		close(a)

typedef struct _fcii_socket {
	SOCKET socket;
} FCII_SOCKET;

BOOL FSSOCKET_InsertSocket( SOCKET socket );
BOOL FSSOCKET_DeleteSocket( SOCKET socket );

void FSSOCKET_GetLocalIPAddress( char *ipaddress );
void FSSOCKET_GetIPAddress( struct in_addr sockaddr, char *ipaddress );
void FSSOCKET_GetExactSocketError( char *errormessage , DWORD length );
BOOL FSSOCKET_Initialize( void );
BOOL FSSOCKET_Deinitialize( void );
BOOL FSSOCKET_IsStringIpAddress( char *string );
DWORD FSSOCKET_ResolveIPFromHostname( char *hostname );
DWORD FSSOCKET_ResolveIPFromIPString( char *ipstring );
SOCKET FSSOCKET_Listen( char *ipaddress , WORD port , char *parameters );
SOCKET FSSOCKET_Accept( SOCKET listensocket , SOCKADDR *client_address , char *parameters);
SOCKET FSSOCKET_Connect( char *ipaddress , WORD port , char *parameters);
int FSSOCKET_HardClose( SOCKET socket , char *parameters );
int FSSOCKET_LightClose( SOCKET socket , char *parameters );
int FSSOCKET_Close( SOCKET socket , char *parameters );

BOOL FSSOCKET_SendStreamSimple( SOCKET socket , UCHAR *message , DWORD messagesize , char *parameters );
BOOL FSSOCKET_ReceiveStreamSimple( SOCKET socket , UCHAR *message , DWORD messagesize , char *parameters );
char *FSSOCKET_ReceiveStringSimple( SOCKET socket );

BOOL FSSOCKET_SendStream( SOCKET socket , UCHAR *message , DWORD messagesize , char *parameters );
BOOL FSSOCKET_ReceiveStream( SOCKET socket , UCHAR *message , DWORD messagesize , char *parameters );


#endif
