/* ***********************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         __SCAN_PORT
#define         __SCAN_PORT

#include <glib.h>
#include <time.h>
#include "Liste_Equipement.h"
#ifdef         __WINDOWS_ENABLE
#include <pcap.h>
#include <remote-ext.h>
#endif


enum enum_Notification_Port {
	NOTIFICATION_STANDARD = 0,
	NOTIFICATION_PORT_SERVEUR,
	NOTIFICATION_PORT_CRITIQUE
};

enum enum_Etat_Port {
	FIREWALLED = 0,	
	OUVERT,
	FERMER,
	UNKOWN, 
	UNKOWN_UDP,
	FERMER_UDP
};

struct Struct_Port {
	gint      Num_Port;
	gboolean  Notification;
	gint      Compteur_Notification;
	gint      Niveau_Notification;
	gint      Etat_Port;
	unsigned char Flags;
	time_t64  Derniere_Modification_Etat_Port;
	gboolean  Alerte_Port_Active;

	unsigned short Port_Scan;
	unsigned int MonNumSeq_Scan;
};

struct struct_Liste_Port {
	gint      Num_Port;
	gboolean  Serveur;
};

GList    *GList_Port;

struct Struct_Port *Recupere_Pointeur_Port_Glist (struct Struct_Liste_Equipement *Equipement, gint Num_Port);
gint      Nombre_De_Port_Scanner (struct Struct_Liste_Equipement *Equipement);
gint      Nombre_De_Port_Avec_Etat (struct Struct_Liste_Equipement *Equipement, gint Etat);
void      Cherche_Un_Port_Avec_Etat (struct Struct_Liste_Equipement *Equipement, gint Etat, gint *resultat);
void  Cherche_Si_Port_Ouvert (struct Struct_Liste_Equipement *Equipement, gint Num_Port);
void      Modifie_Etat_Port_Equipement (struct Struct_Liste_Equipement *Equipement, gint Num_Port,gint Num_Port_D, gint Nouvelle_Etat,unsigned int Ip_MonNum,unsigned char Flags);
void      Creer_Liste_Port_Equipement (struct Struct_Liste_Equipement *Equipement);
#ifndef         __WINDOWS_ENABLE
void      Envoie_Trame_Scan_Port (struct Struct_Liste_Equipement *Equipement, gint Num_Port, gint Socket, struct sockaddr *sock,struct Struct_Port *Port_Equipement);
#else
void Envoie_Trame_Scan_Port (struct Struct_Liste_Equipement *Equipement, gint Num_Port, pcap_t * captureHandle,struct Struct_Port *Port_Equipement);
#endif
void      Scanne_Toutes_Les_Ports_TCP (struct Struct_Liste_Equipement *Equipement);
void 	  Scanne_Toutes_Les_Ports_UDP (struct Struct_Liste_Equipement *Equip);
void      Ajout_Un_Port (gpointer * Donnee);
void      Initialisation_Liste_port (void);
gboolean Traitement_Port_UDP_Fermer (struct Struct_Liste_Equipement *Equipement, struct struct_trame *Packet, unsigned char Taille_Trame, unsigned short Taille_Ip, unsigned char Type_ICMP, unsigned char Code_ICMP);
#endif
