| | @@ -80,11 +80,11 @@ |
| 80 | 80 | # include <sys/time.h> |
| 81 | 81 | # include <sys/wait.h> |
| 82 | 82 | # include <sys/select.h> |
| 83 | 83 | # include <errno.h> |
| 84 | 84 | #endif |
| 85 | | -#ifdef __EMX__ |
| 85 | +#if defined(__EMX__) || defined(__morphos__) |
| 86 | 86 | typedef int socklen_t; |
| 87 | 87 | #endif |
| 88 | 88 | #include <time.h> |
| 89 | 89 | #include <stdio.h> |
| 90 | 90 | #include <stdlib.h> |
| | @@ -2083,12 +2083,14 @@ |
| 2083 | 2083 | ** aliasing rules. |
| 2084 | 2084 | */ |
| 2085 | 2085 | typedef union { |
| 2086 | 2086 | struct sockaddr sa; /* Abstract superclass */ |
| 2087 | 2087 | struct sockaddr_in sa4; /* IPv4 */ |
| 2088 | +#ifdef AF_INET6 |
| 2088 | 2089 | struct sockaddr_in6 sa6; /* IPv6 */ |
| 2089 | 2090 | struct sockaddr_storage sas; /* Should be the maximum of the above 3 */ |
| 2091 | +#endif |
| 2090 | 2092 | } address; |
| 2091 | 2093 | |
| 2092 | 2094 | /* |
| 2093 | 2095 | ** Determine the IP address on the other side of a connection. |
| 2094 | 2096 | ** Return a pointer to a string. Or return 0 if unable. |
| | @@ -2097,19 +2099,25 @@ |
| 2097 | 2099 | ** each call. |
| 2098 | 2100 | */ |
| 2099 | 2101 | char *cgi_remote_ip(int fd){ |
| 2100 | 2102 | address remoteAddr; |
| 2101 | 2103 | socklen_t size = sizeof(remoteAddr); |
| 2104 | +#ifdef AF_INET6 |
| 2102 | 2105 | static char zHost[NI_MAXHOST]; |
| 2106 | +#endif |
| 2103 | 2107 | if( getpeername(0, &remoteAddr.sa, &size) ){ |
| 2104 | 2108 | return 0; |
| 2105 | 2109 | } |
| 2110 | +#ifdef AF_INET6 |
| 2106 | 2111 | if( getnameinfo(&remoteAddr.sa, size, zHost, sizeof(zHost), 0, 0, |
| 2107 | 2112 | NI_NUMERICHOST) ){ |
| 2108 | 2113 | return 0; |
| 2109 | 2114 | } |
| 2110 | 2115 | return zHost; |
| 2116 | +#else |
| 2117 | + return inet_ntoa(((struct sockaddr_in *)&remoteAddr.sa)->sin_addr); |
| 2118 | +#endif |
| 2111 | 2119 | } |
| 2112 | 2120 | |
| 2113 | 2121 | /* |
| 2114 | 2122 | ** This routine handles a single HTTP request which is coming in on |
| 2115 | 2123 | ** g.httpIn and which replies on g.httpOut |
| | @@ -2550,11 +2558,13 @@ |
| 2550 | 2558 | fd_set readfds; /* Set of file descriptors for select() */ |
| 2551 | 2559 | socklen_t lenaddr; /* Length of the inaddr structure */ |
| 2552 | 2560 | int child; /* PID of the child process */ |
| 2553 | 2561 | int nchildren = 0; /* Number of child processes */ |
| 2554 | 2562 | struct timeval delay; /* How long to wait inside select() */ |
| 2563 | +#ifdef AF_INET6 |
| 2555 | 2564 | struct sockaddr_in6 inaddr6; /* Address for IPv6 */ |
| 2565 | +#endif |
| 2556 | 2566 | struct sockaddr_in inaddr4; /* Address for IPv4 */ |
| 2557 | 2567 | struct sockaddr_un uxaddr; /* The address for unix-domain sockets */ |
| 2558 | 2568 | int opt = 1; /* setsockopt flag */ |
| 2559 | 2569 | int rc; /* Result code from system calls */ |
| 2560 | 2570 | int iPort = mnPort; /* Port to try to use */ |
| | @@ -2615,10 +2625,11 @@ |
| 2615 | 2625 | file_set_owner(g.zSockName, listen4, g.zSockOwner); |
| 2616 | 2626 | } |
| 2617 | 2627 | fossil_print("Listening for %s requests on unix socket %s\n", |
| 2618 | 2628 | zRequestType, g.zSockName); |
| 2619 | 2629 | fflush(stdout); |
| 2630 | +#ifdef AF_INET6 |
| 2620 | 2631 | }else if( zIpAddr && strchr(zIpAddr,':')!=0 ){ |
| 2621 | 2632 | /* CASE 2: TCP on IPv6 IP address specified by zIpAddr and on port iPort. |
| 2622 | 2633 | */ |
| 2623 | 2634 | assert( mnPort==mxPort ); |
| 2624 | 2635 | memset(&inaddr6, 0, sizeof(inaddr6)); |
| | @@ -2644,10 +2655,11 @@ |
| 2644 | 2655 | mxListen = listen6; |
| 2645 | 2656 | listen4 = -1; |
| 2646 | 2657 | fossil_print("Listening for %s requests on [%s]:%d\n", |
| 2647 | 2658 | zRequestType, zIpAddr, iPort); |
| 2648 | 2659 | fflush(stdout); |
| 2660 | +#endif |
| 2649 | 2661 | }else if( zIpAddr && zIpAddr[0] ){ |
| 2650 | 2662 | /* CASE 3: TCP on IPv4 IP address specified by zIpAddr and on port iPort. |
| 2651 | 2663 | */ |
| 2652 | 2664 | assert( mnPort==mxPort ); |
| 2653 | 2665 | memset(&inaddr4, 0, sizeof(inaddr4)); |
| | @@ -2706,10 +2718,11 @@ |
| 2706 | 2718 | iPort++; |
| 2707 | 2719 | continue; |
| 2708 | 2720 | } |
| 2709 | 2721 | mxListen = listen4; |
| 2710 | 2722 | |
| 2723 | +#ifdef AF_INET6 |
| 2711 | 2724 | /* If we get here, that means we found an open TCP port at iPort for |
| 2712 | 2725 | ** IPv4. Try to set up a corresponding IPv6 socket on the same port. |
| 2713 | 2726 | */ |
| 2714 | 2727 | memset(&inaddr6, 0, sizeof(inaddr6)); |
| 2715 | 2728 | inaddr6.sin6_family = AF_INET6; |
| | @@ -2733,10 +2746,13 @@ |
| 2733 | 2746 | zProto = "IPv4 only"; |
| 2734 | 2747 | }else{ |
| 2735 | 2748 | zProto = "IPv4 and IPv6"; |
| 2736 | 2749 | if( listen6>listen4 ) mxListen = listen6; |
| 2737 | 2750 | } |
| 2751 | +#else |
| 2752 | + zProto = "IPv4 only"; |
| 2753 | +#endif |
| 2738 | 2754 | |
| 2739 | 2755 | fossil_print("Listening for %s requests on TCP port %s%d, %s\n", |
| 2740 | 2756 | zRequestType, |
| 2741 | 2757 | (flags & HTTP_SERVER_LOCALHOST)!=0 ? "localhost:" : "", |
| 2742 | 2758 | iPort, zProto); |
| | @@ -2790,22 +2806,28 @@ |
| 2790 | 2806 | if( listen6>0 ) FD_SET( listen6, &readfds); |
| 2791 | 2807 | select( mxListen+1, &readfds, 0, 0, &delay); |
| 2792 | 2808 | if( listen4>0 && FD_ISSET(listen4, &readfds) ){ |
| 2793 | 2809 | lenaddr = sizeof(inaddr4); |
| 2794 | 2810 | connection = accept(listen4, (struct sockaddr*)&inaddr4, &lenaddr); |
| 2811 | +#ifdef AF_INET6 |
| 2795 | 2812 | }else if( listen6>0 && FD_ISSET(listen6, &readfds) ){ |
| 2796 | 2813 | lenaddr = sizeof(inaddr6); |
| 2797 | 2814 | connection = accept(listen6, (struct sockaddr*)&inaddr6, &lenaddr); |
| 2815 | +#endif |
| 2798 | 2816 | }else{ |
| 2799 | 2817 | connection = -1; |
| 2800 | 2818 | } |
| 2801 | 2819 | if( connection>=0 ){ |
| 2820 | +#ifndef __morphos__ |
| 2802 | 2821 | if( flags & HTTP_SERVER_NOFORK ){ |
| 2803 | 2822 | child = 0; |
| 2804 | 2823 | }else{ |
| 2805 | 2824 | child = fork(); |
| 2806 | 2825 | } |
| 2826 | +#else |
| 2827 | + child = 0; |
| 2828 | +#endif |
| 2807 | 2829 | if( child!=0 ){ |
| 2808 | 2830 | if( child>0 ){ |
| 2809 | 2831 | nchildren++; |
| 2810 | 2832 | nRequest++; |
| 2811 | 2833 | } |
| 2812 | 2834 | |