19 lines
480 B
C
19 lines
480 B
C
#include "libft.h"
|
|
|
|
int create_server(int port, int backlog, char *protoname)
|
|
{
|
|
int sock;
|
|
struct protoent *proto;
|
|
struct sockaddr_in sin;
|
|
|
|
if (!(proto = getprotobyname(protoname)))
|
|
return (-1);
|
|
sock = socket(PF_INET, SOCK_STREAM, proto->p_proto);
|
|
sin.sin_family = AF_INET;
|
|
sin.sin_port = htons(port);
|
|
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
if (bind(sock, (const struct sockaddr *)&sin, sizeof(sin)) < 0)
|
|
return (-1);
|
|
listen(sock, backlog);
|
|
return (sock);
|
|
}
|