Fossil SCM
Fix the -P option on "fossil server" so that it once again accepts IPv4 notation while continuing to accept IPv6 notation. [forum:/forumpost/fe4abea393|Forum post fe4abea393].
Commit
77250c94b0197c25af68d6a3722c02f4a16722d60b2c6bf7810c49691faaacf5
Parent
c6754849bbd23be…
1 file changed
+21
-2
+21
-2
| --- src/cgi.c | ||
| +++ src/cgi.c | ||
| @@ -2592,16 +2592,35 @@ | ||
| 2592 | 2592 | }else{ |
| 2593 | 2593 | /* Initialize a TCP/IP socket on port iPort */ |
| 2594 | 2594 | memset(&inaddr, 0, sizeof(inaddr)); |
| 2595 | 2595 | inaddr.sin6_family = AF_INET6; |
| 2596 | 2596 | if( zIpAddr ){ |
| 2597 | - if( inet_pton(AF_INET6, zIpAddr, &inaddr.sin6_addr)==0 ){ | |
| 2598 | - fossil_fatal("not a valid IP address: %s", zIpAddr); | |
| 2597 | + /* Bind to the specific IP address given by zIpAddr[] */ | |
| 2598 | + size_t nAddr = strlen(zIpAddr); | |
| 2599 | + char z4to6[30]; | |
| 2600 | + | |
| 2601 | + if( nAddr<16 ){ | |
| 2602 | + /* The specified IP address might be in IPv4 notation (ex: 1.2.3.4) | |
| 2603 | + ** which inet_pton() does not understand. Convert in into a IPv6 | |
| 2604 | + ** mapping of an IPv4 address: (::FFFF:1.2.3.4) */ | |
| 2605 | + memcpy(z4to6,"::ffff:", 7); | |
| 2606 | + memcpy(z4to6+7, zIpAddr, nAddr+2); | |
| 2607 | + }else{ | |
| 2608 | + z4to6[0] = 0; | |
| 2609 | + } | |
| 2610 | + | |
| 2611 | + /* Convert the zIpAddr text string into an actual IPv6 address */ | |
| 2612 | + if( inet_pton(AF_INET6, zIpAddr, &inaddr.sin6_addr)==0 | |
| 2613 | + && (z4to6[0]==0 || inet_pton(AF_INET6, z4to6, &inaddr.sin6_addr)==0) | |
| 2614 | + ){ | |
| 2615 | + fossil_fatal("not a valid IP address: %s", z4to6); | |
| 2599 | 2616 | } |
| 2600 | 2617 | }else if( flags & HTTP_SERVER_LOCALHOST ){ |
| 2618 | + /* Bind to the loop-back IP address */ | |
| 2601 | 2619 | inaddr.sin6_addr = in6addr_loopback; |
| 2602 | 2620 | }else{ |
| 2621 | + /* Bind to any and all available IP addresses */ | |
| 2603 | 2622 | inaddr.sin6_addr = in6addr_any; |
| 2604 | 2623 | } |
| 2605 | 2624 | inaddr.sin6_port = htons(iPort); |
| 2606 | 2625 | listener = socket(AF_INET6, SOCK_STREAM, 0); |
| 2607 | 2626 | if( listener<0 ){ |
| 2608 | 2627 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -2592,16 +2592,35 @@ | |
| 2592 | }else{ |
| 2593 | /* Initialize a TCP/IP socket on port iPort */ |
| 2594 | memset(&inaddr, 0, sizeof(inaddr)); |
| 2595 | inaddr.sin6_family = AF_INET6; |
| 2596 | if( zIpAddr ){ |
| 2597 | if( inet_pton(AF_INET6, zIpAddr, &inaddr.sin6_addr)==0 ){ |
| 2598 | fossil_fatal("not a valid IP address: %s", zIpAddr); |
| 2599 | } |
| 2600 | }else if( flags & HTTP_SERVER_LOCALHOST ){ |
| 2601 | inaddr.sin6_addr = in6addr_loopback; |
| 2602 | }else{ |
| 2603 | inaddr.sin6_addr = in6addr_any; |
| 2604 | } |
| 2605 | inaddr.sin6_port = htons(iPort); |
| 2606 | listener = socket(AF_INET6, SOCK_STREAM, 0); |
| 2607 | if( listener<0 ){ |
| 2608 |
| --- src/cgi.c | |
| +++ src/cgi.c | |
| @@ -2592,16 +2592,35 @@ | |
| 2592 | }else{ |
| 2593 | /* Initialize a TCP/IP socket on port iPort */ |
| 2594 | memset(&inaddr, 0, sizeof(inaddr)); |
| 2595 | inaddr.sin6_family = AF_INET6; |
| 2596 | if( zIpAddr ){ |
| 2597 | /* Bind to the specific IP address given by zIpAddr[] */ |
| 2598 | size_t nAddr = strlen(zIpAddr); |
| 2599 | char z4to6[30]; |
| 2600 | |
| 2601 | if( nAddr<16 ){ |
| 2602 | /* The specified IP address might be in IPv4 notation (ex: 1.2.3.4) |
| 2603 | ** which inet_pton() does not understand. Convert in into a IPv6 |
| 2604 | ** mapping of an IPv4 address: (::FFFF:1.2.3.4) */ |
| 2605 | memcpy(z4to6,"::ffff:", 7); |
| 2606 | memcpy(z4to6+7, zIpAddr, nAddr+2); |
| 2607 | }else{ |
| 2608 | z4to6[0] = 0; |
| 2609 | } |
| 2610 | |
| 2611 | /* Convert the zIpAddr text string into an actual IPv6 address */ |
| 2612 | if( inet_pton(AF_INET6, zIpAddr, &inaddr.sin6_addr)==0 |
| 2613 | && (z4to6[0]==0 || inet_pton(AF_INET6, z4to6, &inaddr.sin6_addr)==0) |
| 2614 | ){ |
| 2615 | fossil_fatal("not a valid IP address: %s", z4to6); |
| 2616 | } |
| 2617 | }else if( flags & HTTP_SERVER_LOCALHOST ){ |
| 2618 | /* Bind to the loop-back IP address */ |
| 2619 | inaddr.sin6_addr = in6addr_loopback; |
| 2620 | }else{ |
| 2621 | /* Bind to any and all available IP addresses */ |
| 2622 | inaddr.sin6_addr = in6addr_any; |
| 2623 | } |
| 2624 | inaddr.sin6_port = htons(iPort); |
| 2625 | listener = socket(AF_INET6, SOCK_STREAM, 0); |
| 2626 | if( listener<0 ){ |
| 2627 |