Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Info604
col3-bibtp1
Commits
c336519e
Commit
c336519e
authored
Apr 02, 2020
by
Stephane Talbot
Committed by
pernelle
Apr 15, 2020
Browse files
ajout containte pour etre sur de recuperer les bonnes info (socket connectee, etc.)
# Conflicts: # communCOL3-TP1.c
parent
50192949
Changes
1
Hide whitespace changes
Inline
Side-by-side
communCOL3-TP1.c
View file @
c336519e
...
...
@@ -115,8 +115,31 @@ int connexionServeurCOL3(const char *adresse_serveur,int port, const char *token
int
sock
;
/* resolution adresse destination */
static
struct
addrinfo
addrHint
=
{.
ai_socktype
=
SOCK_STREAM
,
.
ai_protocol
=
0
,
.
ai_family
=
AF_UNSPEC
,
.
ai_flags
=
(
AI_ADDRCONFIG
|
AI_V4MAPPED
)};
struct
addrinfo
*
addrInfo
;
char
sport
[
10
];
int
e
;
sprintf
(
sport
,
"%d"
,
port
);
if
(
e
=
getaddrinfo
(
adresse_serveur
,
sport
,
&
addrHint
,
&
addrInfo
)){
if
(
errno
!=
0
)
perror
(
"Unable to resolve host"
);
else
fprintf
(
stderr
,
"getaddrinfo error : %s
\n
"
,
gai_strerror
(
e
));
exit
(
EXIT_FAILURE
);
}
if
(
addrInfo
==
NULL
){
fprintf
(
stderr
,
"Unable to resolve host: %s:%s
\n
"
,
adresse_serveur
,
sport
);
exit
(
EXIT_FAILURE
);
}
struct
sockaddr
addr
=
*
(
addrInfo
->
ai_addr
);
/* creation socket */
sock
=
socket
(
addrInfo
->
ai_family
,
addrInfo
->
ai_socktype
,
addrInfo
->
ai_protocol
);
/* nettoyage */
freeaddrinfo
(
addrInfo
);
/* creation socket en mode connecté */
sock
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
/*
sock = socket(AF_INET, SOCK_STREAM, 0);
*/
if
(
sock
==
INVALID_SOCKET
)
{
if
(
!
NCURSE
)
{
printf
(
"%s"
,
" --> creation de la socket [NOK]
\n
"
);
...
...
@@ -138,7 +161,7 @@ int connexionServeurCOL3(const char *adresse_serveur,int port, const char *token
}
/* lancement de la demande de connexion */
if
(
connect
(
sock
,
(
struct
sockaddr
*
)
&
sin
,
sizeof
(
struct
sockaddr
))
==
SOCKET_ERROR
){
if
(
connect
(
sock
,
&
addr
,
sizeof
(
struct
sockaddr
))
==
SOCKET_ERROR
){
printf
(
"%s"
,
" --> connection TCP au serveur COL3 [NOK]
\n
"
);
return
(
INVALID_SOCKET
);
}
else
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment