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
27
puit.c
27
puit.c
|
@ -9,9 +9,10 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#define _OE_SOCKETS
|
#define _OE_SOCKETS
|
||||||
#define PORT_NUM 8000
|
#define PORT_NUM 9000
|
||||||
|
|
||||||
void initSocket();
|
void initSocket();
|
||||||
|
void creationSocket(int *socketTemp);
|
||||||
|
|
||||||
int sock;
|
int sock;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
@ -20,14 +21,8 @@ struct sockaddr_in socketClient,socketServer;
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
if((sock=socket(AF_INET,SOCK_DGRAM,0)) == -1)
|
|
||||||
{
|
creationSocket(&sock);
|
||||||
printf("échec création du socket\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
memset(&socketClient, 0, sizeof(socketClient));
|
|
||||||
memset(&socketServer, 0, sizeof(socketServer));
|
|
||||||
|
|
||||||
initSocket();
|
initSocket();
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,4 +52,18 @@ void initSocket()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
memcpy((char*)&(socketServer.sin_addr.s_addr),hp->h_addr_list[0],hp->h_length);
|
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