possible patch regarding problems parsing /etc/protocols

Per Jessen <[email protected]> Sat, 26 Oct 2002 11:26:44 +0200
Newsgroups org.kernel.vger.linux-diald
Message-ID <[email protected]>
--------------Boundary-00=_KW0LFEW9WZG832Y6GPHL
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

All,
I'm sure there is a reason why utils.c isn't using the getservent/getprot=
oent services from netdb.h -=20
maybe platform related ? I don't know - but here is a patch that 1) uses =
those services for accessing
/etc/protocols and /etc/services, and thereby fixes the minor problem wit=
h comments in either file.
At least it works on Linux.=20

http://mitglied.lycos.de/pjessen/patches/patch-diald-1.0-utils

--=20

regards,
Per Jessen, Zurich
http://www.enidan.com - home of the J1 serial console.

Genius may have its limitations, but stupidity is not thus handicapped.
--------------Boundary-00=_KW0LFEW9WZG832Y6GPHL
Content-Type: text/x-diff;
  charset="us-ascii";
  name="patch-diald-1.0-utils"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="patch-diald-1.0-utils"

--- diald-1.0/utils.c	Sat Jun 16 21:51:39 2001
+++ diald-1.0.pj/utils.c	Sat Oct 26 10:50:57 2002
@@ -2,6 +2,7 @@
 
 #include <diald.h>
 
+#include <netdb.h>
 
 /* Grumble. Attempt to generate a nicely formatted ascii date without
  * a built in newline.
@@ -35,6 +36,35 @@
     return i;
 }
 
+int getprotocol(const char *name)
+{
+        struct protoent *p;
+
+        return  NULL!=(p=getprotobyname(name)) ? p->p_proto : 0;
+}
+
+char *getprotonumber(int proto)
+{
+        static char buf[16];
+        struct protoent *p;
+
+        if ( NULL!=(p=getprotobynumber(proto)) )
+                strcpy(buf,p->p_name);
+        else
+                sprintf(buf, "%d", proto);
+
+        return buf;
+}
+
+
+int getservice(const char *name, const char *proto)
+{
+        struct servent *service;
+
+        return  NULL!=(service=getservbyname( name, proto)) ? ntohs(service->s_port) : 0;
+}
+
+#if 0
 struct proto {
 	char *name;
 	int proto;
@@ -151,6 +181,7 @@
         }
     return 0;
 }
+#endif
 
 #if 0
 /* Stuff needed because to keep checker happy,

--------------Boundary-00=_KW0LFEW9WZG832Y6GPHL--