diff options
author | Determinant <tederminant@gmail.com> | 2019-06-12 19:14:40 -0400 |
---|---|---|
committer | Determinant <tederminant@gmail.com> | 2019-06-12 19:14:40 -0400 |
commit | e27e529e589ef89fbe010ebf7c5635ec2873f64f (patch) | |
tree | 76e7d20589d11f3aabd255ca70201f1288d1d1bc /include/salticidae/netaddr.h | |
parent | 9f6460c7ab774d900f391345bbf3fac8617a3aa3 (diff) |
WIP: error handling
Diffstat (limited to 'include/salticidae/netaddr.h')
-rw-r--r-- | include/salticidae/netaddr.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/include/salticidae/netaddr.h b/include/salticidae/netaddr.h index 909e092..a25bf6f 100644 --- a/include/salticidae/netaddr.h +++ b/include/salticidae/netaddr.h @@ -53,7 +53,7 @@ struct NetAddr { void set_by_ip_port(const std::string &_addr, uint16_t _port) { struct hostent *h; if ((h = gethostbyname(_addr.c_str())) == nullptr) - throw SalticidaeError("gethostbyname failed"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID, errno); memmove(&ip, h->h_addr_list[0], sizeof(in_addr_t)); port = htons(_port); } @@ -61,19 +61,19 @@ struct NetAddr { NetAddr(const std::string &ip_port_addr) { size_t pos = ip_port_addr.find(":"); if (pos == std::string::npos) - throw SalticidaeError("invalid port format"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); std::string ip_str = ip_port_addr.substr(0, pos); std::string port_str = ip_port_addr.substr(pos + 1); long port; try { port = std::stol(port_str.c_str()); } catch (std::logic_error &) { - throw SalticidaeError("invalid port format"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); } if (port < 0) - throw SalticidaeError("negative port number"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); if (port > 0xffff) - throw SalticidaeError("port number greater than 0xffff"); + throw SalticidaeError(SALTI_ERROR_NETADDR_INVALID); set_by_ip_port(ip_str, (uint16_t)port); } /* construct from unix socket format */ |