diff --git a/src/connection.c b/src/connection.c index 247d428..7fafeb8 100644 --- a/src/connection.c +++ b/src/connection.c @@ -44,8 +44,8 @@ int NeoComm_bind(const unsigned short port) { else { char error_msg[128]; - snprintf(error_msg, 128, "Failed to initiate socket with errno `%d'", - errno); + snprintf(error_msg, 128, + "Failed to initiate socket with errno `%d'", errno); NeoComm_error(error_msg); } return 0; @@ -56,7 +56,27 @@ int NeoComm_bind(const unsigned short port) { serv_addr.sin_addr.s_addr = INADDR_ANY; if(bind(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0) { - // TODO: Handle all these errors and shit, I'm too lazy right now + if(errno == EADDRINUSE) + NeoComm_error("Address in use"); + else if(errno == EADDRNOTAVAIL) + NeoComm_error("Address unavailable on system"); + else if(errno == EAFNOSUPPORT) + NeoComm_error("Unsupported address family for socket"); + else if(errno == EALREADY) + NeoComm_error("Assignment request already exists for socket"); + else if(errno == EINVAL) + NeoComm_error("Socket already bound"); + else if(errno == ENOBUFS) + NeoComm_error("Insufficient resources"); + else if(errno == EACCES) + NeoComm_error("Insufficient priviliges"); + else + { + char error_msg[128]; + snprintf(error_msg, 128, + "Failed to bind to socket with errno `%d'", errno); + NeoComm_error(error_msg); + } return 0; }