-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.c
More file actions
54 lines (45 loc) · 1.3 KB
/
Copy pathServer.c
File metadata and controls
54 lines (45 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
// Server.c
// Server
//
// Created by פנחס מנחם אפרים on 02/12/2022.
//
#include "Server.h"
#include <stdio.h>
#include <stdlib.h>
Server_t server_constructor(int domain,
int service,
int protocol,
u_long interfase,
int port,
int backlog,
void (*launch)(Server_t* server))
{
Server_t server;
server.domain = domain;
server.service = service;
server.interfase = interfase;
server.port = port;
server.backlog = backlog;
server.address.sin_family = domain;
server.address.sin_port = htons(port);
server.address.sin_addr.s_addr = htonl(interfase);
server.socket = socket(domain, service, protocol);
if (server.socket == 0)
{
perror("Faild to conect with socket;\n");
exit(1);
}
if (bind(server.socket, (struct sockaddr *)&server.address, sizeof(server.address)) < 0)
{
perror("Faild to blind socket;\n");
exit(2);
}
if (listen(server.socket, server.backlog) < 0)
{
perror("Faild to start listening;\n");
exit(3);
}
server.launch = launch;
return server;
}