feat(puit): v1 sans boucle

This commit is contained in:
Clement Lacau 2024-03-01 16:29:29 +01:00
parent 98bfb60ffc
commit 10a15c0c43

View file

@ -113,11 +113,11 @@ int main (int argc, char **argv)
}
if (udp==1){
// Creation du socket local
int sock= socket(AF_INET,SOCK_DGRAM,0);
if (source==1) {
// Creation du socket local
int sock= socket(AF_INET,SOCK_DGRAM,0);
// Creation de l'adresse du socket distant
@ -155,6 +155,34 @@ int main (int argc, char **argv)
else {
// Creation de l'adresse du socket distant
struct sockaddr_in adr_locale;
int longueur_adr_locale = sizeof(adr_locale);
int longueur_message = BASE_SIZE;
memset((char *)& adr_locale, 0, sizeof(adr_locale)) ;
adr_locale.sin_family=AF_INET;
adr_locale.sin_port=port;
adr_locale.sin_addr.s_addr = INADDR_ANY;
// Bind the local socket to any local address (ie any available interface)
if (bind(sock, (struct sockaddr *) &adr_locale, longueur_adr_locale) == -1) {
printf("failed to bind\n");
exit(1);
}
// Receive a single message because we are lazy
recvfrom(sock, message, longueur_message, 0, NULL, NULL);
// Afficher notre seule et unique triste message
afficher_message(message, longueur_message);
exit(0);
}
}
}