Implemented error handling for `bind()'

This commit is contained in:
Nicolás A. Ortega 2017-07-24 16:25:15 -05:00
parent 2dcdf5b74e
commit b1004f5617
No known key found for this signature in database
GPG Key ID: 3D786FB3123FF1DD

View File

@ -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;
}