+bool CONFIGPROTO::Bind()
+{
+ const hostent * he = gethostbyname(m_bindAddress.c_str());
+ if (he == NULL)
+ {
+ m_errorStr = "Failed to resolve name '" + m_bindAddress + "': '" + hstrerror(h_errno) + "'.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
+ m_logger(m_errorStr);
+ return false;
+ }
+
+ char ** ptr = he->h_addr_list;
+ while (*ptr != NULL)
+ {
+ struct sockaddr_in listenAddr;
+ listenAddr.sin_family = PF_INET;
+ listenAddr.sin_port = htons(m_port);
+ listenAddr.sin_addr.s_addr = *reinterpret_cast<in_addr_t *>(*ptr);
+
+ printfd(__FILE__, "Trying to bind to %s:%d\n", inet_ntostring(listenAddr.sin_addr.s_addr).c_str(), m_port);
+
+ if (bind(m_listenSocket, reinterpret_cast<sockaddr *>(&listenAddr), sizeof(listenAddr)) == 0)
+ return true;
+
+ m_errorStr = std::string("Cannot bind listen socket: '") + strerror(errno) + "'.";
+ printfd(__FILE__, "%s\n", m_errorStr.c_str());
+ m_logger(m_errorStr);
+
+ ++ptr;
+ }
+
+ return false;
+}
+