Fossil

Check-in [dae37f0e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enable the use of IPv6 for "fossil ui" and "fossil server" on unix.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | ipv6-server
Files: files | file ages | folders
SHA1: dae37f0e358368017ebea223f604b379ab7055d3
User & Date: drh 2015-04-09 21:36:47
Context
2015-04-09
23:16
Fix indentation and remove all strcpy() and strcat() calls (as OpenBSD hates those). check-in: b1cb81eb user: drh tags: ipv6-server
21:36
Enable the use of IPv6 for "fossil ui" and "fossil server" on unix. check-in: dae37f0e user: drh tags: ipv6-server
2015-04-08
17:05
Improve some comments. No changes to code. check-in: 5a12e8c3 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/cgi.c.

1716
1717
1718
1719
1720
1721
1722
1723
1724

1725


1726
1727
1728
1729
1730
1731
1732







1733
1734

1735
1736

1737
1738

1739
1740
1741
1742
1743
1744
1745
1746
1747
1748


1749
1750
1751
1752
1753
1754
1755
  int listener = -1;           /* The server socket */
  int connection;              /* A socket for each individual connection */
  fd_set readfds;              /* Set of file descriptors for select() */
  socklen_t lenaddr;           /* Length of the inaddr structure */
  int child;                   /* PID of the child process */
  int nchildren = 0;           /* Number of child processes */
  struct timeval delay;        /* How long to wait inside select() */
  struct sockaddr_in inaddr;   /* The socket address */
  int opt = 1;                 /* setsockopt flag */

  int iPort = mnPort;



  while( iPort<=mxPort ){
    memset(&inaddr, 0, sizeof(inaddr));
    inaddr.sin_family = AF_INET;
    if( zIpAddr ){
      inaddr.sin_addr.s_addr = inet_addr(zIpAddr);
      if( inaddr.sin_addr.s_addr == (-1) ){







        fossil_fatal("not a valid IP address: %s", zIpAddr);
      }

    }else if( flags & HTTP_SERVER_LOCALHOST ){
      inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

    }else{
      inaddr.sin_addr.s_addr = htonl(INADDR_ANY);

    }
    inaddr.sin_port = htons(iPort);
    listener = socket(AF_INET, SOCK_STREAM, 0);
    if( listener<0 ){
      iPort++;
      continue;
    }

    /* if we can't terminate nicely, at least allow the socket to be reused */
    setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));



    if( bind(listener, (struct sockaddr*)&inaddr, sizeof(inaddr))<0 ){
      close(listener);
      iPort++;
      continue;
    }
    break;







|
|
>

>
>



|

|
|
>
>
>
>
>
>
>
|
|
>

<
>

<
>

|
|






|
>
>







1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746

1747
1748

1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
  int listener = -1;           /* The server socket */
  int connection;              /* A socket for each individual connection */
  fd_set readfds;              /* Set of file descriptors for select() */
  socklen_t lenaddr;           /* Length of the inaddr structure */
  int child;                   /* PID of the child process */
  int nchildren = 0;           /* Number of child processes */
  struct timeval delay;        /* How long to wait inside select() */
  struct sockaddr_in6 inaddr;   /* The socket address */
  int optyes = 1;                 /* setsockopt flag */
  int optno = 0;                 /* setsockopt flag */
  int iPort = mnPort;
  char ip[INET6_ADDRSTRLEN];
  

  while( iPort<=mxPort ){
    memset(&inaddr, 0, sizeof(inaddr));
    inaddr.sin6_family = AF_INET6;
    if( zIpAddr ){
        printf("zIpAddr: %s", zIpAddr);
        printf("iPort: %d", iPort);
        /* check valid ipv6 address */
      if (inet_pton(AF_INET6, zIpAddr, &(inaddr.sin6_addr)) < 1) {
          /* maybe ipv4 string so try mixed ipv4 notation*/
          strcpy(ip, "::FFFF:");
          strcat(ip, zIpAddr);
          printf("zIpAddr: %s", ip);
          if (inet_pton(AF_INET6, ip, &(inaddr.sin6_addr)) == -1){
            fossil_fatal("not a valid IP address: %s", zIpAddr);
          }
      }
    }else if( flags & HTTP_SERVER_LOCALHOST ){

      inaddr.sin6_addr = in6addr_loopback;
    }else{

      inaddr.sin6_addr = in6addr_any;
    }
    inaddr.sin6_port = htons(iPort);
    listener = socket(AF_INET6, SOCK_STREAM, 0);
    if( listener<0 ){
      iPort++;
      continue;
    }

    /* if we can't terminate nicely, at least allow the socket to be reused */
    setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, &optyes, sizeof(optyes));
    /* explicitly disable IPV6ONLY option for dualstack usage */
    setsockopt(listener, IPPROTO_IPV6, IPV6_V6ONLY, &optno, sizeof(optno));

    if( bind(listener, (struct sockaddr*)&inaddr, sizeof(inaddr))<0 ){
      close(listener);
      iPort++;
      continue;
    }
    break;

Changes to src/main.c.

2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
    }
#else
    zBrowser = db_get("web-browser", "open");
#endif
    if( zIpAddr ){
      zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
    }else{
      zBrowserCmd = mprintf("%s http://localhost:%%d/ &", zBrowser);
    }
    if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
    if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  }
  db_close(1);
  if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
    fossil_fatal("unable to listen on TCP socket %d", iPort);







|







2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
    }
#else
    zBrowser = db_get("web-browser", "open");
#endif
    if( zIpAddr ){
      zBrowserCmd = mprintf("%s http://%s:%%d/ &", zBrowser, zIpAddr);
    }else{
      zBrowserCmd = mprintf("%s http://[::1]:%%d/ &", zBrowser);
    }
    if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
    if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
  }
  db_close(1);
  if( cgi_http_server(iPort, mxPort, zBrowserCmd, zIpAddr, flags) ){
    fossil_fatal("unable to listen on TCP socket %d", iPort);