mirror of
https://github.com/yoboujon/tsock.git
synced 2025-06-08 14:00:50 +02:00
passage creation socket en fonction
This commit is contained in:
parent
ca448f9e0f
commit
4b7f6b1103
1 changed files with 18 additions and 9 deletions
25
puit.c
25
puit.c
|
@ -9,9 +9,10 @@
|
|||
#include <errno.h>
|
||||
|
||||
#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();
|
||||
|
||||
|
||||
|
@ -58,3 +53,17 @@ void initSocket()
|
|||
}
|
||||
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));
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue