diff --git a/site_ansto/anstoutil.c b/site_ansto/anstoutil.c index ce4d87fa..769dda93 100644 --- a/site_ansto/anstoutil.c +++ b/site_ansto/anstoutil.c @@ -151,6 +151,7 @@ int getPortNum(SConnection *pCon, char *portName) { if (fp == NULL) fp = fopen("sics_test_services", "r"); if (fp != NULL) { + int udp_port = 0; while ((cp = fgets(line, sizeof(line)-1, fp)) != NULL) { if (*cp != '#' && *cp != '\0') { char name[132], *np; @@ -161,19 +162,21 @@ int getPortNum(SConnection *pCon, char *portName) { } if (strcasecmp(portName, name) != 0) continue; - while (*cp && isblank(*cp)) { + while (*cp && isblank(*cp)) ++cp; - } if (*cp && isdigit(*cp)) { long port; port = strtol(cp, &np, 10); - if (strncasecmp("/tcp", np, 4) == 0) { + if (strncasecmp("/tcp", np, 4) == 0) return (int) port; - } + if (strncasecmp("/udp", np, 4) == 0) + udp_port = (int) port; } } } fclose(fp); + if (udp_port > 0) + return udp_port; } } while (0); sp = getservbyname(portName, NULL);