-// Open a TCP Socket
-int irc::sockets::OpenTCPSocket(const std::string& addr, int socktype)
-{
- int sockfd;
- int on = 1;
- struct linger linger = { 0, 0 };
- if (addr.empty())
- {
-#ifdef IPV6
- sockfd = socket (PF_INET6, socktype, 0);
- if (sockfd < 0)
-#endif
- sockfd = socket (PF_INET, socktype, 0);
- }
- else if (addr.find(':') != std::string::npos)
- sockfd = socket (PF_INET6, socktype, 0);
- else
- sockfd = socket (PF_INET, socktype, 0);
-
- if (sockfd < 0)
- {
- return ERROR;
- }
- else
- {
- setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof(on));
- /* This is BSD compatible, setting l_onoff to 0 is *NOT* http://web.irc.org/mla/ircd-dev/msg02259.html */
- linger.l_onoff = 1;
- linger.l_linger = 1;
- setsockopt(sockfd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));
- return (sockfd);
- }
-}
-