aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorRobert Pluim2022-07-25 12:17:07 +0200
committerRobert Pluim2022-07-26 14:16:07 +0200
commitfc1b7b720b5771a330f36e9a52688d73b790e478 (patch)
treee76b4285a5ad8dc7ed744cd4280ef90fb8b1c622 /src/process.c
parentdfa16cadc18930fad76fa6113750eaa27d367e72 (diff)
downloademacs-fc1b7b720b5771a330f36e9a52688d73b790e478.tar.gz
emacs-fc1b7b720b5771a330f36e9a52688d73b790e478.zip
Teach 'network-lookup-address-info' to validate numeric addresses
* src/process.c (Fnetwork_lookup_address_info): Add optional 'hints' argument, pass AI_NUMERICHOST to 'getaddrinfo' if it's 'numeric'. (syms_of_process): Add 'numeric' symbol. * doc/lispref/processes.texi (Misc Network): Expunge passive voice. Update 'network-lookup-address-info' description. * test/src/process-tests.el (lookup-hints-specification): (lookup-hints-values): Test new functionality. * etc/NEWS: Announce change.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/process.c b/src/process.c
index d6d51b26e11..1ac5a509e56 100644
--- a/src/process.c
+++ b/src/process.c
@@ -4641,15 +4641,20 @@ network_lookup_address_info_1 (Lisp_Object host, const char *service,
4641} 4641}
4642 4642
4643DEFUN ("network-lookup-address-info", Fnetwork_lookup_address_info, 4643DEFUN ("network-lookup-address-info", Fnetwork_lookup_address_info,
4644 Snetwork_lookup_address_info, 1, 2, 0, 4644 Snetwork_lookup_address_info, 1, 3, 0,
4645 doc: /* Look up Internet Protocol (IP) address info of NAME. 4645 doc: /* Look up Internet Protocol (IP) address info of NAME.
4646Optional parameter FAMILY controls whether to look up IPv4 or IPv6 4646Optional argument FAMILY controls whether to look up IPv4 or IPv6
4647addresses. The default of nil means both, symbol `ipv4' means IPv4 4647addresses. The default of nil means both, symbol `ipv4' means IPv4
4648only, symbol `ipv6' means IPv6 only. Returns a list of addresses, or 4648only, symbol `ipv6' means IPv6 only.
4649nil if none were found. Each address is a vector of integers, as per 4649Optional argument HINTS allows specifying the hints passed to the
4650the description of ADDRESS in `make-network-process'. In case of 4650underlying library call. The only supported value is `numeric', which
4651error displays the error message. */) 4651means treat NAME as a numeric IP address. This also suppresses DNS
4652 (Lisp_Object name, Lisp_Object family) 4652traffic.
4653Return a list of addresses, or nil if none were found. Each address
4654is a vector of integers, as per the description of ADDRESS in
4655`make-network-process'. In case of error log the error message
4656returned from the lookup. */)
4657 (Lisp_Object name, Lisp_Object family, Lisp_Object hint)
4653{ 4658{
4654 Lisp_Object addresses = Qnil; 4659 Lisp_Object addresses = Qnil;
4655 Lisp_Object msg = Qnil; 4660 Lisp_Object msg = Qnil;
@@ -4667,9 +4672,14 @@ error displays the error message. */)
4667 hints.ai_family = AF_INET6; 4672 hints.ai_family = AF_INET6;
4668#endif 4673#endif
4669 else 4674 else
4670 error ("Unsupported lookup type"); 4675 error ("Unsupported family");
4671 hints.ai_socktype = SOCK_DGRAM; 4676 hints.ai_socktype = SOCK_DGRAM;
4672 4677
4678 if (EQ (hint, Qnumeric))
4679 hints.ai_flags = AI_NUMERICHOST;
4680 else if (!NILP (hint))
4681 error ("Unsupported hints value");
4682
4673 msg = network_lookup_address_info_1 (name, NULL, &hints, &res); 4683 msg = network_lookup_address_info_1 (name, NULL, &hints, &res);
4674 if (!EQ (msg, Qt)) 4684 if (!EQ (msg, Qt))
4675 message ("%s", SSDATA(msg)); 4685 message ("%s", SSDATA(msg));
@@ -8515,6 +8525,7 @@ syms_of_process (void)
8515#ifdef AF_INET6 8525#ifdef AF_INET6
8516 DEFSYM (Qipv6, "ipv6"); 8526 DEFSYM (Qipv6, "ipv6");
8517#endif 8527#endif
8528 DEFSYM (Qnumeric, "numeric");
8518 DEFSYM (Qdatagram, "datagram"); 8529 DEFSYM (Qdatagram, "datagram");
8519 DEFSYM (Qseqpacket, "seqpacket"); 8530 DEFSYM (Qseqpacket, "seqpacket");
8520 8531