Added clarifying comments
This commit is contained in:
parent
a2c745fdce
commit
36b884e0ba
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user