From 818594ee1fa0e7e0472bad783c8927a560661df2 Mon Sep 17 00:00:00 2001 From: Fernando Giorgetti Date: Tue, 10 Apr 2018 16:39:27 -0300 Subject: [PATCH] DISPATCH-960 - Resolving service port when using http listener --- src/amqp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/amqp.c b/src/amqp.c index fcad53a406..fffa8c5bf2 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -21,6 +21,9 @@ #include #include #include +#include +#include +#include const char * const QD_MA_PREFIX = "x-opt-qd."; const char * const QD_MA_INGRESS = "x-opt-qd.ingress"; @@ -73,11 +76,24 @@ const char * const QD_AMQP_COND_FRAME_SIZE_TOO_SMALL = "amqp:frame-size-too-smal const char * const QD_AMQP_PORT_STR = "5672"; const char * const QD_AMQPS_PORT_STR = "5671"; +const char * const QD_AMQP_DFLT_PROTO = "tcp"; + int qd_port_int(const char* port_str) { if (!strcmp(port_str, QD_AMQP_PORT_STR)) return QD_AMQP_PORT_INT; if (!strcmp(port_str, QD_AMQPS_PORT_STR)) return QD_AMQPS_PORT_INT; errno = 0; unsigned long n = strtoul(port_str, NULL, 10); if (errno || n > 0xFFFF) return -1; + + // Port is not an integer (port = 'amqp' or 'amqps') + if ( !n && strlen(port_str) > 0 ) { + // Resolve service port + struct servent *serv_info = getservbyname(port_str, QD_AMQP_DFLT_PROTO); + // Service port is resolved + if ( serv_info ) { + return ntohs(serv_info->s_port); + } + } + return n; }