From 36b884e0ba1b8abcd441b6b1f2e7cde34e52a9c9 Mon Sep 17 00:00:00 2001 From: Christopher Ramey Date: Wed, 4 Feb 2015 00:30:24 +0000 Subject: [PATCH] Added clarifying comments --- src/wstationd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wstationd.c b/src/wstationd.c index 7eb9f53..7aef42f 100644 --- a/src/wstationd.c +++ b/src/wstationd.c @@ -82,6 +82,7 @@ int main(int argc, char *argv[]) } } + // Establish the socket sockfd = socket(AF_INET, SOCK_STREAM, 0); if(sockfd == -1){ fprintf(stderr, "%s: cannot open socket - %s\n", @@ -90,6 +91,8 @@ int main(int argc, char *argv[]) goto shutdown_error; } + // This sets REUSE on the socket so it's easily reallocated if + // this program dies setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)); memset(&sock, 0, sizeof(sock)); @@ -97,13 +100,15 @@ int main(int argc, char *argv[]) sock.sin_addr.s_addr = addr; sock.sin_port = htons(port); + // Bind our socket to the specified address and port if(bind(sockfd, (struct sockaddr*)&sock, sizeof(sock)) < 0){ - fprintf(stderr, "%s: cannot bind to port - %s\n", + fprintf(stderr, "%s: cannot bind - %s\n", exec_name, strerror(errno) ); goto shutdown_error; } + // Listen on port if(listen(sockfd, 5) != 0){ fprintf(stderr, "%s: cannot listen - %s\n", exec_name, strerror(errno)