From e7650ba63b552def6892ca7913194ee8c85f20d1 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 25 Feb 2016 15:54:03 +1030 Subject: [PATCH] Allow using "number strings" as services on non-GNU systems * src/process.c (string_integer_p): New function. (Fmake_network_process): Use it to allow connecting to services specified as "993" even when getaddrbyname isn't available. --- src/process.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/process.c b/src/process.c index 8c88e62ee05..62a26c381b9 100644 --- a/src/process.c +++ b/src/process.c @@ -3428,6 +3428,17 @@ conv_numerical_to_lisp (unsigned char *number, int length, int port) } #endif +/* Return true if STRING consists only of numerical characters. */ +static bool +string_integer_p (Lisp_Object string) +{ + char *s = SSDATA (string), c; + while ((c = *s++)) + if (c < '0' || c > '9') + return false; + return true; +} + /* Create a network stream/datagram client/server process. Treated exactly like a normal process when reading and writing. Primary differences are in status display and process deletion. A network @@ -3852,6 +3863,10 @@ usage: (make-network-process &rest ARGS) */) port = 0; else if (INTEGERP (service)) port = (unsigned short) XINT (service); + /* Allow the service to be a string containing the port number, + because that's allowed if you have getaddrbyname. */ + else if (string_integer_p (service)) + port = strtol (SSDATA (service), NULL, 10); else { struct servent *svc_info; -- 2.39.2