dest-unreach / socat / contrib / servicenames

Service name resolution failure

Introduction

James Sainsbury found a problem with socat's service name resolution and contributed a solution.

Please note that this bug appears to affect all implementations on little endian machines (alpha, i386), and that it exists in socat 1.5 and 1.6.0.0

Message of the contributor

I was trying to get socat running on an old alpha (tru64 4.0) which doesn't have getaddrinfo() but the wrapper in xio-ip.c works but port names weren't working but numeric ports were (too many htons()) and the parseport() function was being called with 'family' rather than 'protocol.'

The patch pretty much covers it. RGDS

diff -r -u socat-1.6.0.0/xio-ip.c socat-1.6.0.0-p/xio-ip.c
--- socat-1.6.0.0/xio-ip.c      Wed Mar  7 08:08:02 2007
+++ socat-1.6.0.0-p/xio-ip.c    Fri Apr 27 17:10:02 2007
@@ -144,7 +144,7 @@
       with NIS), so we handle this specially */
    if (service && isdigit(service[0]&0xff)) {
       char *extra;
-      port = strtoul(service, &extra, 0);
+      port = htons(strtoul(service, &extra, 0));
       if (*extra != '\0') {
         Warn2("xiogetaddrinfo(, \"%s\", ...): extra trailing data \"%s\"",
               service, extra);
@@ -396,15 +396,16 @@

 #if WITH_TCP || WITH_UDP
    if (service) {
-      port = parseport(service, family);
+       port = parseport(service, protocol);
+
    }
    if (port >= 0) {
       switch (family) {
 #if WITH_IP4
-      case PF_INET:  sau->ip4.sin_port  = htons(port); break;
+      case PF_INET:  sau->ip4.sin_port  = port; break;
 #endif /* WITH_IP4 */
 #if WITH_IP6
-      case PF_INET6: sau->ip6.sin6_port = htons(port); break;
+      case PF_INET6: sau->ip6.sin6_port = port; break;
 #endif /* WITH_IP6 */
       }
    }

Requisites

Apply this patch to socat 1.6.0.0 source.

Download

socat-servicenames.patch

Status

This patch is intended to be integrated into the next release following socat 1.6.0.0.