]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
(getservbyport): Allow proto == NULL.
authorUlrich Drepper <drepper@redhat.com>
Fri, 30 Jan 1998 17:18:19 +0000 (17:18 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 30 Jan 1998 17:18:19 +0000 (17:18 +0000)
(getservbyname): Allow proto == NULL.

nss/nss_files/files-service.c

index 317b4fa9cc805db9e3960161c187372b9d1cafa4..b63fafcd1ee0ff2b170e004670ca63ba53079b16 100644 (file)
@@ -1,5 +1,5 @@
 /* Services file parser in nss_files module.
-   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -39,7 +39,8 @@ LINE_PARSER
 
 #include GENERIC
 
-DB_LOOKUP (servbyname, 1 + strlen (name), (".%s/%s", name, proto),
+DB_LOOKUP (servbyname, 2 + strlen (name) + (proto ? strlen (proto) : 0),
+          (".%s/%s", name, proto ?: ""),
           {
             /* Must match both protocol (if specified) and name.  */
             if (proto != NULL && strcmp (result->s_proto, proto))
@@ -48,10 +49,12 @@ DB_LOOKUP (servbyname, 1 + strlen (name), (".%s/%s", name, proto),
           },
           const char *name, const char *proto)
 
-DB_LOOKUP (servbyport, 20, ("=%d/%s", port, proto),
+DB_LOOKUP (servbyport, 21 + (proto ? strlen (proto) : 0),
+          ("=%d/%s", ntohs (port), proto ?: ""),
           {
             /* Must match both port and protocol.  */
-            if (result->s_port == port
-                && strcmp (result->s_proto, proto) == 0)
+            if (result->s_port == ntohs (port)
+                && (proto == NULL
+                    || strcmp (result->s_proto, proto) == 0))
               break;
           }, int port, const char *proto)