aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-03-07 18:54:25 -0800
committerPaul Eggert2016-03-07 18:55:20 -0800
commit59c7a5d71145d88933a535e222bdf30105e7d382 (patch)
tree04724485be6c619e6257873f7d05c2ae51bcbb64
parent6bc8689c042830ae8c13e34af993e8f923e47c9d (diff)
downloademacs-59c7a5d71145d88933a535e222bdf30105e7d382.tar.gz
emacs-59c7a5d71145d88933a535e222bdf30105e7d382.zip
Assume getaddrinfo in C code
* admin/CPP-DEFINES, configure.ac: Remove HAVE_GETADDRINFO, HAVE_H_ERRNO. All uses removed. * doc/lispref/processes.texi (Network, Network Processes), etc/NEWS: Say that port numbers can be integer strings. * lib-src/pop.c (h_errno) [!WINDOWSNT && !HAVE_H_ERRNO]: Remove decl. (socket_connection): Assume HAVE_GETADDRINFO. * lisp/mpc.el (mpc--proc-connect): * lisp/net/network-stream.el (open-network-stream): It’s now OK to use integer strings as port numbers. * src/process.c (conv_numerical_to_lisp) [!HAVE_GETADDRINFO]: Remove. (Fmake_network_process): Assume HAVE_GETADDRINFO.
-rw-r--r--admin/CPP-DEFINES2
-rw-r--r--configure.ac16
-rw-r--r--doc/lispref/processes.texi8
-rw-r--r--etc/NEWS9
-rw-r--r--lib-src/pop.c39
-rw-r--r--lisp/mpc.el5
-rw-r--r--lisp/net/network-stream.el4
-rw-r--r--src/process.c68
8 files changed, 17 insertions, 134 deletions
diff --git a/admin/CPP-DEFINES b/admin/CPP-DEFINES
index 9064053934b..d9df152bff5 100644
--- a/admin/CPP-DEFINES
+++ b/admin/CPP-DEFINES
@@ -147,7 +147,6 @@ HAVE_FUTIMES
147HAVE_FUTIMESAT 147HAVE_FUTIMESAT
148HAVE_GAI_STRERROR 148HAVE_GAI_STRERROR
149HAVE_GCONF 149HAVE_GCONF
150HAVE_GETADDRINFO
151HAVE_GETDELIM 150HAVE_GETDELIM
152HAVE_GETGRENT 151HAVE_GETGRENT
153HAVE_GETHOSTNAME 152HAVE_GETHOSTNAME
@@ -184,7 +183,6 @@ HAVE_GTK_WIDGET_GET_WINDOW
184HAVE_GTK_WIDGET_SET_HAS_WINDOW 183HAVE_GTK_WIDGET_SET_HAS_WINDOW
185HAVE_GTK_WINDOW_SET_HAS_RESIZE_GRIP 184HAVE_GTK_WINDOW_SET_HAS_RESIZE_GRIP
186HAVE_G_TYPE_INIT 185HAVE_G_TYPE_INIT
187HAVE_H_ERRNO
188HAVE_IFADDRS_H 186HAVE_IFADDRS_H
189HAVE_IMAGEMAGICK 187HAVE_IMAGEMAGICK
190HAVE_INET_SOCKETS 188HAVE_INET_SOCKETS
diff --git a/configure.ac b/configure.ac
index 61287d74cab..940a1e23b3c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3701,20 +3701,6 @@ fi
3701AC_SUBST(LIBXML2_LIBS) 3701AC_SUBST(LIBXML2_LIBS)
3702AC_SUBST(LIBXML2_CFLAGS) 3702AC_SUBST(LIBXML2_CFLAGS)
3703 3703
3704# If netdb.h doesn't declare h_errno, we must declare it by hand.
3705# On MinGW, that is provided by nt/inc/sys/socket.h and w32.c.
3706if test "${opsys}" = "mingw32"; then
3707 emacs_cv_netdb_declares_h_errno=yes
3708fi
3709AC_CACHE_CHECK(whether netdb declares h_errno,
3710 emacs_cv_netdb_declares_h_errno,
3711[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <netdb.h>]],
3712 [[return h_errno;]])],
3713 emacs_cv_netdb_declares_h_errno=yes, emacs_cv_netdb_declares_h_errno=no)])
3714if test $emacs_cv_netdb_declares_h_errno = yes; then
3715 AC_DEFINE(HAVE_H_ERRNO, 1, [Define to 1 if netdb.h declares h_errno.])
3716fi
3717
3718# Check for mail-locking functions in a "mail" library. Probably this should 3704# Check for mail-locking functions in a "mail" library. Probably this should
3719# have the same check as for liblockfile below. 3705# have the same check as for liblockfile below.
3720AC_CHECK_LIB(mail, maillock, have_mail=yes, have_mail=no) 3706AC_CHECK_LIB(mail, maillock, have_mail=yes, have_mail=no)
@@ -3803,7 +3789,7 @@ AC_CHECK_FUNCS(accept4 fchdir gethostname \
3803getrusage get_current_dir_name \ 3789getrusage get_current_dir_name \
3804lrand48 random rint \ 3790lrand48 random rint \
3805select getpagesize setlocale newlocale \ 3791select getpagesize setlocale newlocale \
3806getrlimit setrlimit shutdown getaddrinfo \ 3792getrlimit setrlimit shutdown \
3807pthread_sigmask strsignal setitimer \ 3793pthread_sigmask strsignal setitimer \
3808sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \ 3794sendto recvfrom getsockname getpeername getifaddrs freeifaddrs \
3809gai_strerror sync \ 3795gai_strerror sync \
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index 79cebaa79fa..8d3df55cba9 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -2128,7 +2128,8 @@ associated with any buffer.
2128 2128
2129The arguments @var{host} and @var{service} specify where to connect to; 2129The arguments @var{host} and @var{service} specify where to connect to;
2130@var{host} is the host name (a string), and @var{service} is the name of 2130@var{host} is the host name (a string), and @var{service} is the name of
2131a defined network service (a string) or a port number (an integer). 2131a defined network service (a string) or a port number (an integer like
2132@code{80} or an integer string like @code{"80"}).
2132 2133
2133The remaining arguments @var{parameters} are keyword/argument pairs 2134The remaining arguments @var{parameters} are keyword/argument pairs
2134that are mainly relevant to encrypted connections: 2135that are mainly relevant to encrypted connections:
@@ -2352,8 +2353,9 @@ connecting to that address will be accepted.
2352 2353
2353@item :service @var{service} 2354@item :service @var{service}
2354@var{service} specifies a port number to connect to; or, for a server, 2355@var{service} specifies a port number to connect to; or, for a server,
2355the port number to listen on. It should be a service name that 2356the port number to listen on. It should be a service name like
2356translates to a port number, or an integer specifying the port number 2357@samp{"http"} that translates to a port number, or an integer like @samp{80}
2358or an integer string like @samp{"80"} that specifies the port number
2357directly. For a server, it can also be @code{t}, which means to let 2359directly. For a server, it can also be @code{t}, which means to let
2358the system select an unused port number. 2360the system select an unused port number.
2359 2361
diff --git a/etc/NEWS b/etc/NEWS
index 4328761cf36..b651b9eb880 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -74,11 +74,10 @@ to deal with asynchronous sockets is to avoid interacting with them
74until they have changed status to "run". This is most easily done 74until they have changed status to "run". This is most easily done
75from a process sentinel. 75from a process sentinel.
76 76
77** `make-network-stream' has always allowed :service to be specified 77** ‘make-network-process’ and ‘open-network-stream’ sometimes allowed
78as a "number string" (i.e., :service "993") when using gethostbyname, 78:service to be an integer string (e.g., :service "993") and sometimes
79but has required using a real number (i.e., :service 993) on systems 79required an integer (e.g., :service 993). This difference has been
80without gethostbyname. This difference has now been eliminated, and 80eliminated, and integer strings work everywhere.
81you can use "number strings" on all systems.
82 81
83** It is possible to disable attempted recovery on fatal signals 82** It is possible to disable attempted recovery on fatal signals
84 83
diff --git a/lib-src/pop.c b/lib-src/pop.c
index 21d721546b7..983993461b5 100644
--- a/lib-src/pop.c
+++ b/lib-src/pop.c
@@ -102,12 +102,6 @@ extern char *krb_realmofhost (/* char * */);
102#endif /* ! KERBEROS5 */ 102#endif /* ! KERBEROS5 */
103#endif /* KERBEROS */ 103#endif /* KERBEROS */
104 104
105#ifndef WINDOWSNT
106#ifndef HAVE_H_ERRNO
107extern int h_errno;
108#endif
109#endif
110
111static int socket_connection (char *, int); 105static int socket_connection (char *, int);
112static int pop_getline (popserver, char **); 106static int pop_getline (popserver, char **);
113static int sendline (popserver, const char *); 107static int sendline (popserver, const char *);
@@ -972,13 +966,9 @@ static int have_winsock = 0;
972static int 966static int
973socket_connection (char *host, int flags) 967socket_connection (char *host, int flags)
974{ 968{
975#ifdef HAVE_GETADDRINFO
976 struct addrinfo *res, *it; 969 struct addrinfo *res, *it;
977 struct addrinfo hints; 970 struct addrinfo hints;
978 int ret; 971 int ret;
979#else /* !HAVE_GETADDRINFO */
980 struct hostent *hostent;
981#endif
982 struct servent *servent; 972 struct servent *servent;
983 struct sockaddr_in addr; 973 struct sockaddr_in addr;
984 char found_port = 0; 974 char found_port = 0;
@@ -1065,7 +1055,6 @@ socket_connection (char *host, int flags)
1065 1055
1066 } 1056 }
1067 1057
1068#ifdef HAVE_GETADDRINFO
1069 memset (&hints, 0, sizeof (hints)); 1058 memset (&hints, 0, sizeof (hints));
1070 hints.ai_socktype = SOCK_STREAM; 1059 hints.ai_socktype = SOCK_STREAM;
1071 hints.ai_flags = AI_CANONNAME; 1060 hints.ai_flags = AI_CANONNAME;
@@ -1097,34 +1086,6 @@ socket_connection (char *host, int flags)
1097 } 1086 }
1098 freeaddrinfo (res); 1087 freeaddrinfo (res);
1099 1088
1100#else /* !HAVE_GETADDRINFO */
1101 do
1102 {
1103 hostent = gethostbyname (host);
1104 try_count++;
1105 if ((! hostent) && ((h_errno != TRY_AGAIN) || (try_count == 5)))
1106 {
1107 strcpy (pop_error, "Could not determine POP server's address");
1108 return (-1);
1109 }
1110 } while (! hostent);
1111
1112 while (*hostent->h_addr_list)
1113 {
1114 memcpy (&addr.sin_addr, *hostent->h_addr_list, hostent->h_length);
1115 if (! connect (sock, (struct sockaddr *) &addr, sizeof (addr)))
1116 break;
1117 hostent->h_addr_list++;
1118 }
1119 connect_ok = *hostent->h_addr_list != NULL;
1120 if (! connect_ok)
1121 {
1122 realhost = alloca (strlen (hostent->h_name) + 1);
1123 strcpy (realhost, hostent->h_name);
1124 }
1125
1126#endif /* !HAVE_GETADDRINFO */
1127
1128#define CONNECT_ERROR "Could not connect to POP server: " 1089#define CONNECT_ERROR "Could not connect to POP server: "
1129 1090
1130 if (! connect_ok) 1091 if (! connect_ok)
diff --git a/lisp/mpc.el b/lisp/mpc.el
index 20e4bc85d85..aa7fee6adb6 100644
--- a/lisp/mpc.el
+++ b/lisp/mpc.el
@@ -265,10 +265,7 @@ defaults to 6600 and HOST defaults to localhost."
265 (let ((v (match-string 3 host))) 265 (let ((v (match-string 3 host)))
266 (setq host (match-string 2 host)) 266 (setq host (match-string 2 host))
267 (when (and (stringp v) (not (string= "" v))) 267 (when (and (stringp v) (not (string= "" v)))
268 (setq port 268 (setq port v))))
269 (if (string-match "[^[:digit:]]" v)
270 (string-to-number v)
271 v)))))
272 (when (file-name-absolute-p host) 269 (when (file-name-absolute-p host)
273 ;; Expand file name because `file-name-absolute-p' 270 ;; Expand file name because `file-name-absolute-p'
274 ;; considers paths beginning with "~" as absolute 271 ;; considers paths beginning with "~" as absolute
diff --git a/lisp/net/network-stream.el b/lisp/net/network-stream.el
index f919efb2197..5ddaef58a89 100644
--- a/lisp/net/network-stream.el
+++ b/lisp/net/network-stream.el
@@ -65,8 +65,8 @@ BUFFER is a buffer or buffer name to associate with the process.
65 Process output goes at end of that buffer. BUFFER may be nil, 65 Process output goes at end of that buffer. BUFFER may be nil,
66 meaning that the process is not associated with any buffer. 66 meaning that the process is not associated with any buffer.
67HOST is the name or IP address of the host to connect to. 67HOST is the name or IP address of the host to connect to.
68SERVICE is the name of the service desired, or an integer specifying 68SERVICE is the name of the service desired, or an integer or
69 a port number to connect to. 69 integer string specifying a port number to connect to.
70 70
71The remaining PARAMETERS should be a sequence of keywords and 71The remaining PARAMETERS should be a sequence of keywords and
72values: 72values:
diff --git a/src/process.c b/src/process.c
index 69f5e1ddca6..359cd2195aa 100644
--- a/src/process.c
+++ b/src/process.c
@@ -3429,21 +3429,6 @@ connect_network_socket (Lisp_Object proc, Lisp_Object ip_addresses)
3429 3429
3430} 3430}
3431 3431
3432#ifndef HAVE_GETADDRINFO
3433static Lisp_Object
3434conv_numerical_to_lisp (unsigned char *number, int length, int port)
3435{
3436 Lisp_Object address = Fmake_vector (make_number (length + 1), Qnil);
3437 struct Lisp_Vector *p = XVECTOR (address);
3438
3439 p->contents[length] = make_number (port);
3440 for (int i = 0; i < length; i++)
3441 p->contents[i] = make_number (number[i]);
3442
3443 return address;
3444}
3445#endif
3446
3447/* Create a network stream/datagram client/server process. Treated 3432/* Create a network stream/datagram client/server process. Treated
3448 exactly like a normal process when reading and writing. Primary 3433 exactly like a normal process when reading and writing. Primary
3449 differences are in status display and process deletion. A network 3434 differences are in status display and process deletion. A network
@@ -3479,9 +3464,8 @@ host, and only clients connecting to that address will be accepted.
3479 3464
3480:service SERVICE -- SERVICE is name of the service desired, or an 3465:service SERVICE -- SERVICE is name of the service desired, or an
3481integer specifying a port number to connect to. If SERVICE is t, 3466integer specifying a port number to connect to. If SERVICE is t,
3482a random port number is selected for the server. (If Emacs was 3467a random port number is selected for the server. A port number can
3483compiled with getaddrinfo, a port number can also be specified as a 3468be specified as an integer string, e.g., "80", as well as an integer.
3484string, e.g. "80", as well as an integer. This is not portable.)
3485 3469
3486:type TYPE -- TYPE is the type of connection. The default (nil) is a 3470:type TYPE -- TYPE is the type of connection. The default (nil) is a
3487stream type connection, `datagram' creates a datagram type connection, 3471stream type connection, `datagram' creates a datagram type connection,
@@ -3614,11 +3598,9 @@ usage: (make-network-process &rest ARGS) */)
3614 Lisp_Object proc; 3598 Lisp_Object proc;
3615 Lisp_Object contact; 3599 Lisp_Object contact;
3616 struct Lisp_Process *p; 3600 struct Lisp_Process *p;
3617#if defined HAVE_GETADDRINFO || defined HAVE_GETADDRINFO_A
3618 const char *portstring; 3601 const char *portstring;
3619 ptrdiff_t portstringlen ATTRIBUTE_UNUSED; 3602 ptrdiff_t portstringlen ATTRIBUTE_UNUSED;
3620 char portbuf[INT_BUFSIZE_BOUND (EMACS_INT)]; 3603 char portbuf[INT_BUFSIZE_BOUND (EMACS_INT)];
3621#endif
3622#ifdef HAVE_LOCAL_SOCKETS 3604#ifdef HAVE_LOCAL_SOCKETS
3623 struct sockaddr_un address_un; 3605 struct sockaddr_un address_un;
3624#endif 3606#endif
@@ -3689,7 +3671,7 @@ usage: (make-network-process &rest ARGS) */)
3689 tem = Fplist_get (contact, QCfamily); 3671 tem = Fplist_get (contact, QCfamily);
3690 if (NILP (tem)) 3672 if (NILP (tem))
3691 { 3673 {
3692#if defined (HAVE_GETADDRINFO) && defined (AF_INET6) 3674#ifdef AF_INET6
3693 family = AF_UNSPEC; 3675 family = AF_UNSPEC;
3694#else 3676#else
3695 family = AF_INET; 3677 family = AF_INET;
@@ -3761,7 +3743,6 @@ usage: (make-network-process &rest ARGS) */)
3761 } 3743 }
3762#endif 3744#endif
3763 3745
3764#if defined HAVE_GETADDRINFO || defined HAVE_GETADDRINFO_A
3765 if (!NILP (host)) 3746 if (!NILP (host))
3766 { 3747 {
3767 /* SERVICE can either be a string or int. 3748 /* SERVICE can either be a string or int.
@@ -3783,7 +3764,6 @@ usage: (make-network-process &rest ARGS) */)
3783 portstringlen = SBYTES (service); 3764 portstringlen = SBYTES (service);
3784 } 3765 }
3785 } 3766 }
3786#endif
3787 3767
3788#ifdef HAVE_GETADDRINFO_A 3768#ifdef HAVE_GETADDRINFO_A
3789 if (!NILP (host) && !NILP (Fplist_get (contact, QCnowait))) 3769 if (!NILP (host) && !NILP (Fplist_get (contact, QCnowait)))
@@ -3815,7 +3795,6 @@ usage: (make-network-process &rest ARGS) */)
3815 } 3795 }
3816#endif /* HAVE_GETADDRINFO_A */ 3796#endif /* HAVE_GETADDRINFO_A */
3817 3797
3818#ifdef HAVE_GETADDRINFO
3819 /* If we have a host, use getaddrinfo to resolve both host and service. 3798 /* If we have a host, use getaddrinfo to resolve both host and service.
3820 Otherwise, use getservbyname to lookup the service. */ 3799 Otherwise, use getservbyname to lookup the service. */
3821 3800
@@ -3855,10 +3834,8 @@ usage: (make-network-process &rest ARGS) */)
3855 3834
3856 goto open_socket; 3835 goto open_socket;
3857 } 3836 }
3858#endif /* HAVE_GETADDRINFO */
3859 3837
3860 /* We end up here if getaddrinfo is not defined, or in case no hostname 3838 /* No hostname has been specified (e.g., a local server process). */
3861 has been specified (e.g. for a local server process). */
3862 3839
3863 if (EQ (service, Qt)) 3840 if (EQ (service, Qt))
3864 port = 0; 3841 port = 0;
@@ -3894,43 +3871,6 @@ usage: (make-network-process &rest ARGS) */)
3894 xsignal1 (Qerror, CALLN (Fformat, unknown_service, service)); 3871 xsignal1 (Qerror, CALLN (Fformat, unknown_service, service));
3895 } 3872 }
3896 3873
3897#ifndef HAVE_GETADDRINFO
3898 if (!NILP (host))
3899 {
3900 struct hostent *host_info_ptr;
3901 unsigned char *addr;
3902 int addrlen;
3903
3904 /* gethostbyname may fail with TRY_AGAIN, but we don't honor that,
3905 as it may `hang' Emacs for a very long time. */
3906 immediate_quit = 1;
3907 QUIT;
3908
3909 host_info_ptr = gethostbyname ((const char *) SDATA (host));
3910 immediate_quit = 0;
3911
3912 if (host_info_ptr)
3913 {
3914 addr = (unsigned char *) host_info_ptr->h_addr;
3915 addrlen = host_info_ptr->h_length;
3916 }
3917 else
3918 /* Attempt to interpret host as numeric inet address. This
3919 only works for IPv4 addresses. */
3920 {
3921 unsigned long numeric_addr = inet_addr (SSDATA (host));
3922
3923 if (numeric_addr == -1)
3924 error ("Unknown host \"%s\"", SDATA (host));
3925
3926 addr = (unsigned char *) &numeric_addr;
3927 addrlen = 4;
3928 }
3929
3930 ip_addresses = list1 (conv_numerical_to_lisp (addr, addrlen, port));
3931 }
3932#endif /* not HAVE_GETADDRINFO */
3933
3934 open_socket: 3874 open_socket:
3935 3875
3936 if (!NILP (buffer)) 3876 if (!NILP (buffer))