Bonsoir
Je viens poster ce message parce qu'il me semble que j'ai fait une erreur mais laquelle je ne sais pas.
j'obtiens le message suivant
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
Erreur Bind: Address family not supported by protocol
et même après plusieurs choix de configuration IPv4 ou IPv6 rien à faire je vous poste mon code en espérant que des experts puissent m'aider merci d'avance
à bientôt

Code c : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
#define D_NULL	0
#define D_ERROR -1
#define D_LOG	50
#define D_PORT	7410
 
 
int i_Status;
int f_Ipv4(struct sockaddr_in sin);
int f_Ipv6(struct sockaddr_in6 sin);
int f_InitSrv(struct sockaddr_in sin, struct sockaddr_in6 sin6,int i_choix);
 
void f_Start_Srv(void);
void f_Client(int i_SockClient);
Code c : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
 
 
// variable globale i_Status
 
/***
*       Fonction configuration
*       & préparation de la
*       socket IPv4 elle renvoie
*       (-1) en cas d'erreur
*       (1) si tout vas bien 
***/
int f_IPv4( struct sockaddr_in sin ){
 
	int i_Sock = D_NULL;
	i_Sock = socket( AF_INET, SOCK_STREAM, D_NULL );
	if( i_Sock <= D_ERROR )
		return ( D_ERROR ); 
 
	/*	Config Sin	*/
	bzero( &sin, sizeof( sin ) );
	sin.sin_family = AF_INET;
	sin.sin_port = htons( D_PORT );
	sin.sin_addr.s_addr = ntohs( INADDR_ANY );
 
	return ( i_Sock );
}
 
/***
*       Fonction configuration
*       & préparation de la
*       socket IPv6 elle renvoie
*       (-1) en cas d'erreur
*       (1) si tout vas bien 
***/
int f_IPv6(struct sockaddr_in6 sin6){
 
	int i_Sock6 = D_NULL;
	i_Sock6 = socket( AF_INET6, SOCK_STREAM, D_NULL );
	if( i_Sock6 <= D_ERROR )
		return ( D_ERROR );
 
	/*	Config Sin6	*/
	bzero(&sin6, sizeof( sin6) );
	sin6.sin6_family = AF_INET6;
	sin6.sin6_port = htons( D_PORT );
	sin6.sin6_addr = in6addr_any;
 
	return ( i_Sock6 );
}
 
int f_InitSrv(struct sockaddr_in sin, struct sockaddr_in6 sin6,int i_Choix){
 
	int ret = 0;
	/*	Cas IPv4	*/
	if( i_Choix <= D_NULL){
		ret = f_IPv4( sin );
		if( ret <= D_ERROR )
			return ( D_ERROR );
		else{
			i_Status = 0;
			return ( ret );
		}
	}
	/*	Cas IPv6	*/
	else{
 
		ret = f_IPv6( sin6 );
		if( ret <= D_ERROR )
			return ( D_ERROR );
		else{
			i_Status = 1;
			return ( ret );
		}
	}		
}
 
void f_Client( int i_SockClient ){
 
	printf("Client Connecter\n");
}
 
/***
*       Fonction Start du serveur
*       Finie la configuration
*       et ce met en attente de 
*       connexion sur le port
*       écoute
***/
void f_Start_Srv( void ){
 
	int i_Pid = D_NULL;
 
	int i_NewSock = D_NULL;
 
	socklen_t size_Sock;
	struct sockaddr_in sin;
	struct sockaddr_in6 sin6;
 
 
 
	/***    
        *       Vérification config 
        *       Socket IPv4 / IPv6      
        ***/
	int ret = f_InitSrv( sin, sin6, 1 );
	if ( ret <= D_ERROR ){
		perror("Imposside d'initialiser le serveur");
		exit( 1 );
	}
 
	switch( i_Status ){
 
		case 0:
			printf("Configuration IPv4\n");
 
			int i_Bind = D_NULL;			
			i_Bind = bind( ret, (struct sockaddr *)&sin, sizeof( sin ) );
			if( i_Bind <= D_ERROR ){
				perror("Erreur Bind");
				exit( 2 );
			}
 
			int i_Listen = D_NULL;
			i_Listen = listen( ret, D_LOG );
			if( i_Listen <= D_ERROR ){
				perror("Erreur Listen");
				exit( 4 );
			}
 
			printf("Attente de connexion ...\n");
			for(;;){
				size_Sock = sizeof( struct sockaddr_in* );
				i_NewSock = accept( ret, ( struct sockaddr* )&sin, &size_Sock );
				if( i_NewSock <= D_ERROR ){
					perror("Erreur accept connexion");
					exit( 5 );
				}
 
				/*	Création du processus client	*/
				i_Pid = fork();
				if( i_Pid <= D_ERROR ){
					perror("Erreur creation processus");
					exit( 6 );
				}
				f_Client( i_NewSock );
			}
		break;
 
		case 1:
			printf("Configuration IPv6\n");
 
			i_Bind = D_NULL;
			i_Bind = bind( ret, (struct sockaddr *)&sin6, sizeof(sin6) );
			if( i_Bind <= D_ERROR ){
				perror("Erreur Bind");
				exit( 2 );
			}
 
			i_Listen = D_NULL;
			i_Listen = listen( ret, D_LOG );
			if( i_Listen <= D_ERROR ){
				perror("Erreur Listen");
				exit( 4 );
			}
 
			printf("Attente de connexion ...\n");
			for(;;){
				size_Sock = sizeof( struct sockaddr_in6* );
				i_NewSock = accept( ret, ( struct sockaddr* )&sin, &size_Sock );
				if( i_NewSock <= D_ERROR ){
					perror("Erreur accept connexion");
					exit( 5 );
				}
 
				/*	Création du processus client	*/
				i_Pid = fork();
				if( i_Pid <= D_ERROR ){
					perror("Erreur creation processus");
					exit( 6 );
				}
				f_Client( i_NewSock );
			}
		break;
 
		default :
			//Aucun cas définit
			break;
	}
 
}