diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-01 15:07:52 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-01 15:07:52 +0000 |
commit | b47228902d585dd16953b7f9bc395553890fc56e (patch) | |
tree | ffc4ed1d4177c2e2f0d10ea01f17c4ea8ee0409a /src/socket.cpp | |
parent | 77d5c9f765702a06a1ad77f239d1cbe2d9b11662 (diff) |
Move IP<->sockaddr conversions into irc::sockets:: namespace
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11580 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 53 |
1 files changed, 8 insertions, 45 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index 7d44b7e37..4d3509836 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -25,40 +25,18 @@ using irc::sockets::sockaddrs; bool InspIRCd::BindSocket(int sockfd, int port, const char* addr, bool dolisten) { sockaddrs servaddr; - memset(&servaddr, 0, sizeof(servaddr)); - - int ret, size; + int ret; if (*addr == '*') addr = ""; -#ifdef IPV6 if (*addr) { - /* There is an address here. Is it ipv6? */ - if (strchr(addr,':')) - { - if (inet_pton(AF_INET6, addr, &servaddr.in6.sin6_addr) < 1) - { - return false; - } - servaddr.in6.sin6_family = AF_INET6; - servaddr.in6.sin6_port = htons(port); - size = sizeof(sockaddr_in6); - } - else - { - if (inet_pton(AF_INET, addr, &servaddr.in4.sin_addr) < 1) - { - return false; - } - servaddr.in4.sin_family = AF_INET; - servaddr.in4.sin_port = htons(port); - size = sizeof(sockaddr_in); - } + irc::sockets::aptosa(addr, port, &servaddr); } else { +#ifdef IPV6 if (port == -1) { /* Port -1: Means UDP IPV4 port binding - Special case @@ -67,37 +45,22 @@ bool InspIRCd::BindSocket(int sockfd, int port, const char* addr, bool dolisten) servaddr.in4.sin_family = AF_INET; servaddr.in4.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.in4.sin_port = 0; - size = sizeof(sockaddr_in); } else { /* There's no address here, default to ipv6 bind to all */ servaddr.in6.sin6_family = AF_INET6; servaddr.in6.sin6_port = htons(port); - size = sizeof(sockaddr_in6); + memset(&servaddr.in6.sin6_addr, 0, sizeof(servaddr.in6.sin6_addr)); } - } #else - /* If we aren't built with ipv6, the choice becomes simple */ - servaddr.in4.sin_family = AF_INET; - if (*addr) - { - /* There is an address here. */ - if (inet_pton(AF_INET, addr, &servaddr.in4.sin_addr) < 1) - { - return false; - } - } - else - { /* Bind ipv4 to all */ + servaddr.in4.sin_family = AF_INET; servaddr.in4.sin_addr.s_addr = htonl(INADDR_ANY); - } - /* Bind ipv4 port number */ - servaddr.in4.sin_port = htons(port); - size = sizeof(sockaddr_in); + servaddr.in4.sin_port = htons(port); #endif - ret = SE->Bind(sockfd, &servaddr.sa, size); + } + ret = SE->Bind(sockfd, &servaddr.sa, sizeof(servaddr)); if (ret < 0) { |