c - WSAGetLastError() : 10057 when using sendto() -


i've written following code. sorry, comments , printf written in french. if hard me that, let me know , i'll translate:

// ping.cpp : définit le point d'entrée pour l'application console. //  #include "stdafx.h" #include "stdio.h" #include "winsock2.h" #include "conio.h" #include "stdint.h" #include "ping.h" #pragma comment(lib,"ws2_32") //ligne nécessaire pour le compilateur visual studio afin de lier le programme à la librairie ws2_32.lib  int main(int argc, char *argv[]) {     word versionprotocolesocket;     socket pingsocket;     struct sockaddr_in destination;     char *message;     int err, longueurmessage;      //intialisation du protocole windows socket     printf("initialisation du protocole de socket 2.2...\n");     versionprotocolesocket = makeword(2, 2);     err = initialisersocket(versionprotocolesocket);     if (err != 0) {         errsocket(err);         printf("le programme va s'arreter\n");         _getch();         return exit_failure;     }     else         printf("initialisation reussi\n\n");      //création du socket     printf("creation du socket...\n");     if ((pingsocket = socket(af_inet, sock_stream, 0)) == socket_error) {         printf("impossible de creer un socket\nle programme va s'arreter\n");         _getch();         return exit_failure;     }     else         printf("creation reussi\n\n");      //préparation des variables pour l'utilisation de la fonction sendto()     destination.sin_family = af_inet;     destination.sin_addr.s_addr = inet_addr("216.58.206.227");     message = "bonjour";     longueurmessage = sizeof(message);      //debut du ping     (int = 0; < 5; i++)     {         if (sendto(pingsocket, message, longueurmessage, 0, (struct sockaddr *)&destination, sizeof(destination)) == socket_error) {             printf("erreur lors de l'envoie du message : %d\n", wsagetlasterror());         }         else             printf("message %d envoye", i);     }       _getch();     return exit_success; }  int initialisersocket(word version) {     wsadata wsadata;     int err = wsastartup(version, &wsadata);     return err; }  void errsocket(int err) {     switch (err) {     case wsasysnotready:         printf("le systeme reseau n'est pas pret pour la communication\n");         break;     case wsavernotsupported:         printf("la version du protocole windows socket demande n'est pas supporte\n");         break;     case wsaeinprogress:         printf("une operation windows socket est en cours\n");         break;     case wsaeproclim:         printf("le nombre de tache maximum pour le protocole windows socket ete atteint\n");         break;     case wsaefault:         printf("le pointeur lpwsadata n'est pas valide\n");         break;     default:         printf("une erreur inconnue ete rencontre\n");         break;     } } 

when run code error code 10057 wsagetlasterror() function. aim make program can ping ip adress , informations it.
first time use winsock2 library. advance,
léo

microsoft windows error codes::

wsaenotconn
10057 (0x2749)
request send or receive data disallowed because socket not connected , (when sending on datagram socket using sendto call) no address supplied.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -