From 4b7f6b110320a8c4faa9b495d1629f4263e28fdb Mon Sep 17 00:00:00 2001 From: Simon Paris Date: Wed, 11 Jan 2023 16:17:04 +0100 Subject: [PATCH] passage creation socket en fonction --- puit.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/puit.c b/puit.c index 65db67e..b5b58f0 100644 --- a/puit.c +++ b/puit.c @@ -9,9 +9,10 @@ #include #define _OE_SOCKETS -#define PORT_NUM 8000 +#define PORT_NUM 9000 void initSocket(); +void creationSocket(int *socketTemp); int sock; char buffer[1024]; @@ -20,14 +21,8 @@ struct sockaddr_in socketClient,socketServer; int main(void) { - if((sock=socket(AF_INET,SOCK_DGRAM,0)) == -1) - { - printf("échec création du socket\n"); - exit(1); - } - memset(&socketClient, 0, sizeof(socketClient)); - memset(&socketServer, 0, sizeof(socketServer)); - + + creationSocket(&sock); initSocket(); @@ -57,4 +52,18 @@ void initSocket() exit(1); } memcpy((char*)&(socketServer.sin_addr.s_addr),hp->h_addr_list[0],hp->h_length); +} + +void creationSocket(int *socketTemp){ + +if((*socketTemp=socket(AF_INET,SOCK_DGRAM,0)) == -1) + { + printf("échec création du socket\n"); + exit(1); + } + memset(&socketClient, 0, sizeof(socketClient)); + memset(&socketServer, 0, sizeof(socketServer)); + + + } \ No newline at end of file