/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License.
 *
 *
 *                      ********************
 *
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **************************************************************************************/
#ifndef         __RESEAU
#define         __RESEAU

#ifndef         __WINDOWS_ENABLE
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/if_ether.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/sockios.h>
#include <linux/if_packet.h>
#include  <netdb.h>
#else
#include <windows.h>
#endif

#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <glib.h>
#include "Socket.h"



#define TRAME_IP	0x0800
#define IP_ADDR_LEN	4
#define IP_VERSION4	0x4
#define MAC_ADDR_LEN 6

#define TRAME_ARP	0x0806

#define UDP		0x11

#define TCP 	0x06

#define ICMP	0x01
#define DESTINATION_UNREACHABLE 3
#define PORT_UNREACHABLE 3
#define ECHO_PING_REPLY 0
#define TIMESTAMP_REPLY 14
#define ICMP_CODE_0 0

#define NETBIOS		0x89
#define REGISTRATION_GROUP 1
#define REGISTRATION_UNIQUE 2
#define NBNS		0x89
#define BROWSE		0x8a

#define MASTER_ANNONCE	0x0f
#define HOST_ANNONCE	0x01
#define PORT_FTP 21
#define PORT_HTTP 80
#define PORT_IMAP 143
#define PORT_SSH 22
#define PORT_SMTP 25
#define PORT_TELNET 23
#define PORT_NETBIOS 139

#ifdef         __WINDOWS_ENABLE
#define ETH_ALEN	6
#endif


#define  DONNEE_PRET 1
#define  ATTENDRE    2
#define  ERREUR_SOCK 3	

#define SOCK_BROKEN_PIPE 		-32
#define SOCK_ERROR						-1
#define SOCK_OK								1
#define SOCK_RESET_BY_PEER		104

#define SOCKET_NON_BLOQUANT 1
#define SOCKET_BLOQUANT 0

unsigned char Mon_Adresse_MAC[MAC_ADDR_LEN + 1];
unsigned char Mon_Adresse_Ip[IP_ADDR_LEN + 1];

struct struct_Cle_Privee *Log_Send;
struct struct_Cle_Privee *Log_Recv;

struct struct_trame {
	unsigned char Dest_MAC[6];
	unsigned char Source_MAC[6];
	unsigned short Proto;
	unsigned char Datagramme[10000];
	int       Taille_Trame;
};

#include "Liste_Equipement.h" 

int       Creation_Socket_TCP (void);
unsigned char *resoudre_DNS (char *serveur,unsigned char *Adresse_Ip);
gboolean  connection_Serveur (unsigned char *Ip, int Port, int sock);
void      Get_My_MAC (void);
void      Get_My_Ip (void);
unsigned short ckecksum (char *donnee, int longueur, int valeur);
int  attendre_Donnee_Lecture (int sock, int temp);
gboolean  attendre_Sock (int sock);
void      set_NonBlock (int sock,int block);
void ckecksum_r (struct Struct_Liste_Equipement *Equip,char *donnee, int longueur, int valeur);
int       Connection_Equipement (unsigned char *Ip, char *Serveur, int Port, int Tentative,int NbmilliSecondeAttente, gboolean Block);
gint      create_tcp_server (int port, int Nb_Max_Client);
#ifdef         __WINDOWS_ENABLE
int inet_aton(const char *cp, struct in_addr *addr);
#endif

#endif
