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].

drh 2025-04-15 14:13 trunk
Commit 77250c94b0197c25af68d6a3722c02f4a16722d60b2c6bf7810c49691faaacf5
1 file changed +21 -2
+21 -2
--- src/cgi.c
+++ src/cgi.c
@@ -2592,16 +2592,35 @@
25922592
}else{
25932593
/* Initialize a TCP/IP socket on port iPort */
25942594
memset(&inaddr, 0, sizeof(inaddr));
25952595
inaddr.sin6_family = AF_INET6;
25962596
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);
25992616
}
26002617
}else if( flags & HTTP_SERVER_LOCALHOST ){
2618
+ /* Bind to the loop-back IP address */
26012619
inaddr.sin6_addr = in6addr_loopback;
26022620
}else{
2621
+ /* Bind to any and all available IP addresses */
26032622
inaddr.sin6_addr = in6addr_any;
26042623
}
26052624
inaddr.sin6_port = htons(iPort);
26062625
listener = socket(AF_INET6, SOCK_STREAM, 0);
26072626
if( listener<0 ){
26082627
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button