Blame view

bin/test.c 1.56 KB
32c9271a   skhinach   modif
1
2
  #include <stdlib.h>
  #include <stdio.h>
c9ce1fd2   skhinach   modifs
3
  <<<<<<< HEAD
fff6f037   skhinach   modifs
4
  #include <unistd.h>
32c9271a   skhinach   modif
5
6
  #include <getopt.h>
  #include <string.h>
fff6f037   skhinach   modifs
7
  #include <signal.h>
32c9271a   skhinach   modif
8
9
10
  #include "libnet.h"
  
  
fff6f037   skhinach   modifs
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  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);
  	}
  }
  
  
c9ce1fd2   skhinach   modifs
26
27
28
29
30
31
32
  =======
  #include <getopt.h>
  #include <string.h>
  #include "libnet.h"
  
  
  >>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d
32c9271a   skhinach   modif
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  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);
  	
c9ce1fd2   skhinach   modifs
58
  <<<<<<< HEAD
fff6f037   skhinach   modifs
59
60
  	action.sa_handler=&handler;
  	sigaction(SIGINT, &action, NULL);
32c9271a   skhinach   modif
61
62
63
64
65
66
67
68
  
  	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);
c9ce1fd2   skhinach   modifs
69
  =======
c35daaf6   Souheib Khinache   Organisation, cré...
70
71
72
73
74
75
76
77
78
79
80
  
  	int sock_fd=initialisationServeur(port);
  
  	if( sock_fd==-1 ) { fprintf(stderr, "Initialisation du serveur impossible\n"); return -1; }
  
  
  	boucleServeur(sock_fd, (void*)&reponseConnexion);
  
  
  	sendUDPBroadcast("BroadWesh", 2020);
  
c9ce1fd2   skhinach   modifs
81
  >>>>>>> 52d8a1eaf954b611aaf0861144b440a15f7c517d
32c9271a   skhinach   modif
82
83
  	return 0;
  }