|
|
@@ -653,9 +653,9 @@ int open_telnet(const char *ip, port_t port, bool proxy, int identd)
|
|
|
* 'addr' is ignored if af_def is AF_INET6 -poptix (02/03/03)
|
|
|
*/
|
|
|
#ifdef USE_IPV6
|
|
|
-int open_address_listen(in_addr_t addr, int af_def, port_t *port)
|
|
|
+int open_address_listen(const char* ip, int af_def, port_t *port)
|
|
|
#else
|
|
|
-int open_address_listen(in_addr_t addr, port_t *port)
|
|
|
+int open_address_listen(const char* ip, port_t *port)
|
|
|
#endif /* USE_IPV6 */
|
|
|
{
|
|
|
// if (firewall[0]) {
|
|
|
@@ -666,7 +666,7 @@ int open_address_listen(in_addr_t addr, port_t *port)
|
|
|
|
|
|
int sock = 0;
|
|
|
socklen_t addrlen;
|
|
|
- struct sockaddr_in name;
|
|
|
+ union sockaddr_union name;
|
|
|
|
|
|
#ifdef USE_IPV6
|
|
|
if (af_def == AF_INET6) {
|
|
|
@@ -703,7 +703,7 @@ int open_address_listen(in_addr_t addr, port_t *port)
|
|
|
return -1;
|
|
|
}
|
|
|
} else {
|
|
|
- sock = getsock(SOCK_LISTEN, AF_INET);
|
|
|
+ sock = getsock(SOCK_LISTEN, af_def);
|
|
|
#else
|
|
|
sock = getsock(SOCK_LISTEN);
|
|
|
#endif /* USE_IPV6 */
|
|
|
@@ -711,28 +711,48 @@ int open_address_listen(in_addr_t addr, port_t *port)
|
|
|
if (sock < 0)
|
|
|
return -1;
|
|
|
|
|
|
- debug2("Opening listen socket on port %d with AF_INET, sock: %d", *port, sock);
|
|
|
- bzero((char *) &name, sizeof(struct sockaddr_in));
|
|
|
- name.sin_family = AF_INET;
|
|
|
- name.sin_port = htons(*port); /* 0 = just assign us a port */
|
|
|
- name.sin_addr.s_addr = addr;
|
|
|
- if (bind(sock, (struct sockaddr *) &name, sizeof(name)) < 0) {
|
|
|
- if (!(identd_hack && *port == 113))
|
|
|
- putlog(LOG_DEBUG, "*", "Failed to bind to socket %d for listen on port %d: %s", sock, *port, strerror(errno));
|
|
|
- killsock(sock);
|
|
|
- return -1;
|
|
|
+ if (af_def == AF_UNIX)
|
|
|
+ debug2("Opening listen socket on %s, sock: %d", ip, sock);
|
|
|
+ else
|
|
|
+ debug3("Opening listen socket on %s:%d with AF_INET, sock: %d", ip, *port, sock);
|
|
|
+
|
|
|
+ bzero((char *) &name, sizeof(struct sockaddr *));
|
|
|
+ if (af_def == AF_UNIX) {
|
|
|
+ name.sun.sun_family = AF_UNIX;
|
|
|
+ strcpy(name.sun.sun_path, ip);
|
|
|
+ unlink(name.sun.sun_path);
|
|
|
+ addrlen = strlen(name.sun.sun_path) + sizeof(name.sun.sun_family);
|
|
|
+ } else {
|
|
|
+ name.sin.sin_family = af_def;
|
|
|
+ name.sin.sin_port = htons(*port); /* 0 = just assign us a port */
|
|
|
+ name.sin.sin_addr.s_addr = inet_addr(ip);
|
|
|
+ addrlen = sizeof(struct sockaddr_in*);
|
|
|
}
|
|
|
- /* what port are we on? */
|
|
|
- addrlen = sizeof(name);
|
|
|
- if (getsockname(sock, (struct sockaddr *) &name, &addrlen) < 0) {
|
|
|
- if (!(identd_hack && *port == 113))
|
|
|
- putlog(LOG_DEBUG, "*", "Failed to getsockname on socket %d for listen on port %d: %s", sock, *port, strerror(errno));
|
|
|
+
|
|
|
+ if (bind(sock, (struct sockaddr *) &name, addrlen) < 0) {
|
|
|
+ if (!(identd_hack && *port == 113)) {
|
|
|
+ if (af_def == AF_UNIX)
|
|
|
+ putlog(LOG_DEBUG, "*", "Failed to bind to socket %d for listen on %s: %s", sock, ip, strerror(errno));
|
|
|
+ else
|
|
|
+ putlog(LOG_DEBUG, "*", "Failed to bind to socket %d for listen on %s:%d: %s", sock, ip, *port, strerror(errno));
|
|
|
+ }
|
|
|
killsock(sock);
|
|
|
return -1;
|
|
|
}
|
|
|
- *port = ntohs(name.sin_port);
|
|
|
+
|
|
|
+ if (af_def != AF_UNIX) {
|
|
|
+ /* what port are we on? */
|
|
|
+ if (getsockname(sock, (struct sockaddr *) &name, &addrlen) < 0) {
|
|
|
+ if (!(identd_hack && *port == 113))
|
|
|
+ putlog(LOG_DEBUG, "*", "Failed to getsockname on socket %d for listen on port %d: %s", sock, *port, strerror(errno));
|
|
|
+ killsock(sock);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ *port = ntohs(name.sin.sin_port);
|
|
|
+ }
|
|
|
+
|
|
|
if (listen(sock, 1) < 0) {
|
|
|
- if (!(identd_hack && *port == 113))
|
|
|
+ if (!(identd_hack && *port == 113) && af_def != AF_UNIX)
|
|
|
putlog(LOG_DEBUG, "*", "Failed to listen on socket %d for on port %d: %s", sock, *port, strerror(errno));
|
|
|
killsock(sock);
|
|
|
return -1;
|
|
|
@@ -741,7 +761,10 @@ int open_address_listen(in_addr_t addr, port_t *port)
|
|
|
}
|
|
|
#endif /* USE_IPV6 */
|
|
|
|
|
|
- debug2("Opened listen socket on port %d with AF_INET, sock: %d", *port, sock);
|
|
|
+ if (af_def == AF_UNIX)
|
|
|
+ debug2("Opened listen socket on %s, sock: %d", ip, sock);
|
|
|
+ else
|
|
|
+ debug3("Opened listen socket on %s:%d with AF_INET, sock: %d", ip, *port, sock);
|
|
|
|
|
|
return sock;
|
|
|
}
|
|
|
@@ -752,9 +775,9 @@ int open_address_listen(in_addr_t addr, port_t *port)
|
|
|
int open_listen(port_t *port)
|
|
|
{
|
|
|
#ifdef USE_IPV6
|
|
|
- return open_address_listen(getmyip(), AF_INET, port);
|
|
|
+ return open_address_listen(iptostr(getmyip()), AF_INET, port);
|
|
|
#else
|
|
|
- return open_address_listen(getmyip(), port);
|
|
|
+ return open_address_listen(iptostr(getmyip()), port);
|
|
|
#endif /* USE_IPV6 */
|
|
|
}
|
|
|
|
|
|
@@ -765,7 +788,18 @@ int open_listen(port_t *port)
|
|
|
int open_listen_by_af(port_t *port, int af_def)
|
|
|
{
|
|
|
#ifdef USE_IPV6
|
|
|
- return open_address_listen(getmyip(), af_def, port);
|
|
|
+ return open_address_listen(iptostr(getmyip()), af_def, port);
|
|
|
+#else
|
|
|
+ return -1;
|
|
|
+#endif /* USE_IPV6 */
|
|
|
+}
|
|
|
+
|
|
|
+int open_listen_addr_by_af(const char *ip, port_t *port, int af_def)
|
|
|
+{
|
|
|
+ if (!ip)
|
|
|
+ ip = iptostr(getmyip());
|
|
|
+#ifdef USE_IPV6
|
|
|
+ return open_address_listen(ip, af_def, port);
|
|
|
#else
|
|
|
return -1;
|
|
|
#endif /* USE_IPV6 */
|