Implemented error handling for `bind()'
This commit is contained in:
parent
2dcdf5b74e
commit
b1004f5617
@ -44,8 +44,8 @@ int NeoComm_bind(const unsigned short port) {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
char error_msg[128];
|
char error_msg[128];
|
||||||
snprintf(error_msg, 128, "Failed to initiate socket with errno `%d'",
|
snprintf(error_msg, 128,
|
||||||
errno);
|
"Failed to initiate socket with errno `%d'", errno);
|
||||||
NeoComm_error(error_msg);
|
NeoComm_error(error_msg);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -56,7 +56,27 @@ int NeoComm_bind(const unsigned short port) {
|
|||||||
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
if(bind(sockfd, (struct sockaddr*) &serv_addr, sizeof(serv_addr)) < 0)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user