* Remove IPv4 server code from WebCit in trunk. Client code has not yet been convert...
authorArt Cancro <ajc@citadel.org>
Thu, 22 Jul 2010 20:55:46 +0000 (20:55 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 22 Jul 2010 20:55:46 +0000 (20:55 +0000)
webcit/locate_host.c
webcit/tcp_sockets.c

index ecfc4d3da5ce962b63e3ff295caaa4ac6bb47ed9..488a472a92dab7efebbf11e7bdb15a7ff1ceedce 100644 (file)
@@ -22,9 +22,8 @@
 
 #include "webcit.h"
 
-
 /*
- * IPv6 enabled locate_host()
+ * IPv4/IPv6 locate_host()
  */
 void locate_host(StrBuf *tbuf, int client_socket)
 {
@@ -42,35 +41,3 @@ void locate_host(StrBuf *tbuf, int client_socket)
 
         StrBufAppendBufPlain(tbuf, clienthost, -1, 0);
 }
-
-
-#if 0
-/*
- * IPv4-only locate_host()
- */
-void locate_host(StrBuf *tbuf, int client_socket)
-{
-       struct sockaddr_in cs;
-       struct hostent *ch;
-       socklen_t len;
-       char *i;
-       int a1, a2, a3, a4;
-
-       len = sizeof(cs);
-       if (getpeername(client_socket, (struct sockaddr *) &cs, &len) < 0) {
-               StrBufAppendBufPlain(tbuf, HKEY("<unknown>"), 0);
-               return;
-       }
-       if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
-                               AF_INET)) == NULL) {
-               i = (char *) &cs.sin_addr;
-               a1 = ((*i++) & 0xff);
-               a2 = ((*i++) & 0xff);
-               a3 = ((*i++) & 0xff);
-               a4 = ((*i++) & 0xff);
-               StrBufPrintf(tbuf, "%d.%d.%d.%d", a1, a2, a3, a4);
-               return;
-       }
-       StrBufAppendBufPlain(tbuf, ch->h_name, -1, 0);
-}
-#endif
index 689ad00df76e4b7aa56016b46b73ae93484d0ded..a32285b7d959b08b501d3dcfdb0bc1db8d210e03 100644 (file)
@@ -69,7 +69,7 @@ int uds_connectsock(char *sockpath)
 
 
 /*
- * TCP client - connect to a host/port
+ * TCP client - connect to a host/port (FIXME this needs to be IPv6 enabled)
  */
 int tcp_connectsock(char *host, int port)
 {
@@ -490,6 +490,7 @@ int ClientGetLine(ParsedHttpHdrs *Hdr, StrBuf *Target)
                                                         &Error);
 }
 
+
 /* 
  * This is a generic function to set up a master socket for listening on
  * a TCP port.  The server shuts down if the bind fails.  (IPv4/IPv6 version)
@@ -507,15 +508,19 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
        memset(&sin, 0, sizeof(sin));
        sin.sin6_family = AF_INET6;
 
-       if ((ip_addr == NULL) || (IsEmptyStr(ip_addr)) || (!strcmp(ip_addr, "0.0.0.0"))) {
+       if (    (ip_addr == NULL)                                                       /* any address */
+               || (IsEmptyStr(ip_addr))
+               || (!strcmp(ip_addr, "0.0.0.0"))
+               || (!strcmp(ip_addr, "*"))
+       ) {
                sin.sin6_addr = in6addr_any;
        } else {
                char bind_to[256];
-               if ((strchr(ip_addr, '.')) && (!strchr(ip_addr, ':'))) {
+               if ((strchr(ip_addr, '.')) && (!strchr(ip_addr, ':'))) {                /* specific IPv4 */
                        snprintf(bind_to, sizeof bind_to, "::ffff:%s", ip_addr);
                }
                else {
-                       safestrncpy(bind_to, ip_addr, sizeof bind_to);
+                       safestrncpy(bind_to, ip_addr, sizeof bind_to);                  /* specific IPv6 */
                }
                if (inet_pton(AF_INET6, bind_to, &sin.sin6_addr) <= 0) {
                        lprintf(1, "Error binding to [%s] : %s\n", ip_addr, strerror(errno));
@@ -551,62 +556,6 @@ int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
        return (s);
 }
 
-#if 0
-/* 
- * This is a generic function to set up a master socket for listening on
- * a TCP port.  The server shuts down if the bind fails.  (Old IPv4-only version)
- *
- * ip_addr     IP address to bind
- * port_number port number to bind
- * queue_len   number of incoming connections to allow in the queue
- */
-int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
-{
-       struct protoent *p;
-       struct sockaddr_in sin;
-       int s, i;
-
-       memset(&sin, 0, sizeof(sin));
-       sin.sin_family = AF_INET;
-       if (ip_addr == NULL) {
-               sin.sin_addr.s_addr = INADDR_ANY;
-       } else {
-               sin.sin_addr.s_addr = inet_addr(ip_addr);
-       }
-
-       if (sin.sin_addr.s_addr == INADDR_NONE) {
-               sin.sin_addr.s_addr = INADDR_ANY;
-       }
-
-       if (port_number == 0) {
-               lprintf(1, "Cannot start: no port number specified.\n");
-               return (-WC_EXIT_BIND);
-       }
-       sin.sin_port = htons((u_short) port_number);
-
-       p = getprotobyname("tcp");
-
-       s = socket(PF_INET, SOCK_STREAM, (p->p_proto));
-       if (s < 0) {
-               lprintf(1, "Can't create an IPv4 socket: %s\n", strerror(errno));
-               return (-WC_EXIT_BIND);
-       }
-       /* Set some socket options that make sense. */
-       i = 1;
-       setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
-
-       if (bind(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
-               lprintf(1, "Can't bind: %s\n", strerror(errno));
-               return (-WC_EXIT_BIND);
-       }
-       if (listen(s, queue_len) < 0) {
-               lprintf(1, "Can't listen: %s\n", strerror(errno));
-               return (-WC_EXIT_BIND);
-       }
-       return (s);
-}
-#endif
-
 
 /*
  * Create a Unix domain socket and listen on it