void DNS::aierror(int code, const std::string& arg) { #if defined(POCO_HAVE_IPv6) switch (code) { case EAI_AGAIN: throw DNSException("Temporary DNS error while resolving", arg); case EAI_FAIL: throw DNSException("Non recoverable DNS error while resolving", arg); #if !defined(_WIN32) // EAI_NODATA and EAI_NONAME have the same value case EAI_NODATA: throw NoAddressFoundException(arg); #endif case EAI_NONAME: throw HostNotFoundException(arg); #if defined(EAI_SYSTEM) case EAI_SYSTEM: error(lastError(), arg); break; #endif #if defined(_WIN32) case WSANO_DATA: // may happen on XP throw HostNotFoundException(arg); #endif default: throw DNSException("EAI", NumberFormatter::format(code)); } #endif // POCO_HAVE_IPv6 }
void TCPSocket::connect(const char *name, unsigned short port) { if (this->_state != CREATED) { throw SocketStateException("Wrong state for operation"); } struct sockaddr_in remote_addr; const int GETHOSTBYNAME_R_BUFSIZE = 4096; char tmp_buf[GETHOSTBYNAME_R_BUFSIZE]; struct hostent *result; #if defined( linux ) || defined( __linux ) struct hostent ret; int h_errnop; if (gethostbyname_r(name, &ret, tmp_buf, GETHOSTBYNAME_R_BUFSIZE, &result, &h_errnop) == -1) { throw DNSException(h_errno); } if (result == NULL) { throw DNSException(h_errno); } #endif #if defined( sun ) || defined( __sun ) struct hostent entry; int h_errnop; if ((result = gethostbyname_r(name, &entry, tmp_buf, GETHOSTBYNAME_R_BUFSIZE, &h_errnop)) == NULL) { throw DNSException(h_errno); } #endif memset(&remote_addr, 0, sizeof (remote_addr)); remote_addr.sin_addr = *((in_addr *) result->h_addr_list[0]); remote_addr.sin_family = AF_INET; remote_addr.sin_port = htons(port); if (this->_nonblocking == false) { if (::connect(this->_b->_sock, (struct sockaddr*) & remote_addr, sizeof (remote_addr)) == -1) { if (errno == EAGAIN) throw EAGAINException(); else throw ConnectException(errno); } this->_state = CONNECTED; } if (this->_nonblocking == true) { ::connect(this->_b->_sock, (struct sockaddr*) & remote_addr, sizeof (remote_addr)); this->_state = CONNECTING; } #ifdef DEBUG fprintf(stderr, "connected to %s port %d\n", name, port); #endif }
void DNS::error(int code, const std::string& arg) { switch (code) { case POCO_ESYSNOTREADY: throw NetException("Net subsystem not ready"); case POCO_ENOTINIT: throw NetException("Net subsystem not initialized"); case POCO_HOST_NOT_FOUND: throw HostNotFoundException(arg); case POCO_TRY_AGAIN: throw DNSException("Temporary DNS error while resolving", arg); case POCO_NO_RECOVERY: throw DNSException("Non recoverable DNS error while resolving", arg); case POCO_NO_DATA: throw NoAddressFoundException(arg); default: throw IOException(NumberFormatter::format(code)); } }