sonde.c 1.35 KB
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <signal.h>
#include "libnet.h"
#include <time.h>

int sock_fd;

struct sigaction action;

void handler(int sig)
{
	if(sig==SIGINT)
	{
		printf("\nINTERRUPTION SOCKET : %d\n\n", sock_fd);
		close(sock_fd);
		exit(1);
	}
}


void argPortParsing(int argc, char* argv[], char* port)
{
	struct option port_arg={"port", 1, NULL, 'p'}; // 
	char opt;
	int longindex;

	while( (opt=getopt_long(argc, argv, "p:", &port_arg, &longindex)) !='p' && opt!=-1) {}

	if(opt=='p') 
	{
		strcpy(port, optarg);
		printf("%s\n", optarg);
	}
	else
	{
		printf("La syntaxe doit être de la forme %s -p <port> ou %s --port <port>\n\n", argv[0], argv[0]);
	}
}


int main(int argc, char* argv[])
{
/*
	char port[10]="80";
	argPortParsing(argc, argv, port);
	
	action.sa_handler=&handler;
	sigaction(SIGINT, &action, NULL);

	if( (sock_fd=initialisationServeur(port)) ==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; }

	boucleServeur(sock_fd, (void*)&reponseConnexion);

	
	sendUDPBroadcast("BroadWesh", 2020);
	sendUDPUnicast("192.168.0.37", "Coucou", 2020);
	*/

	char msg[2] = {0x40,0x01};
	
	while(1)
	{
		if(ecouteReseau(argc, argv)!=0){ return -1;}
		if(sendUDPBroadcast(msg, 2020)){ return -1;}
		//sendUDPUnicast("172.26.145.205",msg, 2020);
	}
	return 0;
}