[gnu.emacs] Fixes to open-network-stream to accept numeric addresses

drw@boole.mit.edu (Dale R. Worley) (02/23/90)

Having been unable to contact a particular machine because our
/etc/hosts file had an incorrect address, I finally hacked up the code
to allow Emacs to accept absolute addresses for network connections.
The following patch (for 18.54) allows open-network-stream to accept
numeric addresses, in the format "[18.87.0.12]", as well as proper
host names.

Dale			drw@math.mit.edu

*** /usr/local/emacs/src/process.c	Tue Apr 18 13:00:19 1989
--- process.c	Wed Feb 21 21:37:06 1990
***************
*** 1119,1124 ****
--- 1119,1126 ----
    int s, outch, inch;
    char errstring[80];
    int port;
+   struct hostent host_info_fixed;
+   char addr_fixed[4];
  
    CHECK_STRING (name, 0);
    CHECK_STRING (host, 0);
***************
*** 1133,1141 ****
        port = svc_info->s_port;
      }
  
!   host_info = gethostbyname (XSTRING (host)->data);
    if (host_info == 0)
!     error ("Unknown host \"%s\"", XSTRING(host)->data);
  
    bzero (&address, sizeof address);
    bcopy (host_info->h_addr, (char *) &address.sin_addr, host_info->h_length);
--- 1135,1169 ----
        port = svc_info->s_port;
      }
  
!   host_info = 0;
!   if (XSTRING (host)->data[0] != '[')
!     {
!       host_info = gethostbyname (XSTRING (host)->data);
!     }
!   else
!     {
!       int a1, a2, a3, a4;
!       char c;
! 
!       if (sscanf(XSTRING (host)->data, "[%d.%d.%d.%d%c",
! 	    &a1, &a2, &a3, &a4, &c) == 5 &&
! 	  c == ']')
! 	{
! 	  addr_fixed[0] = a1;
! 	  addr_fixed[1] = a2;
! 	  addr_fixed[2] = a3;
! 	  addr_fixed[3] = a4;
!           host_info = &host_info_fixed;
!           host_info->h_addr = addr_fixed;
!           host_info->h_length = 4;
!           host_info->h_addrtype = AF_INET;
! 	}
!     }
!   /* Report error. */
    if (host_info == 0)
!     {
!       error ("Unknown host \"%s\"", XSTRING(host)->data);
!     }
  
    bzero (&address, sizeof address);
    bcopy (host_info->h_addr, (char *) &address.sin_addr, host_info->h_length);