summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index 99bda09..c978256 100644
--- a/src/main.c
+++ b/src/main.c
@@ -10,19 +10,21 @@ int establish_connection(struct sockaddr_in addr) {
int sfd = socket(AF_INET, SOCK_STREAM, 0);
if (sfd == -1) {
perror("could not open socket");
- return 1;
+ return -1;
}
- int opt = 1;
+ int opt = -1;
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
int bind_addr = bind(sfd, (struct sockaddr *)&addr, sizeof(addr));
if (bind_addr == -1) {
perror("could not bind socket");
- return 1;
+ close(sfd);
+ return -1;
}
int listen_addr = listen(sfd, 100);
if (listen_addr == -1) {
perror("could not listen");
- return 1;
+ close(sfd);
+ return -1;
}
return sfd;
}