no retries or perror if EADDRNOTAVAIL, so can fail gracefully if no net
[unix-history] / usr / src / lib / libc / net / getprotoent.c
index def32cd..00c4653 100644 (file)
@@ -1,13 +1,22 @@
-/*     getprotoent.c   4.2     82/10/05        */
+/*
+ * Copyright (c) 1983 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)getprotoent.c      5.1 (Berkeley) %G%";
+#endif not lint
 
 #include <stdio.h>
 
 #include <stdio.h>
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <netdb.h>
 #include <ctype.h>
 
 #define        MAXALIASES      35
 
 #include <sys/socket.h>
 #include <netdb.h>
 #include <ctype.h>
 
 #define        MAXALIASES      35
 
-static char *PROTODB = "/usr/lib/protocols";
+static char PROTODB[] = "/etc/protocols";
 static FILE *protof = NULL;
 static char line[BUFSIZ+1];
 static struct protoent proto;
 static FILE *protof = NULL;
 static char line[BUFSIZ+1];
 static struct protoent proto;
@@ -61,19 +70,20 @@ again:
        if (p != NULL)
                *p++ = '\0';
        proto.p_proto = atoi(cp);
        if (p != NULL)
                *p++ = '\0';
        proto.p_proto = atoi(cp);
-       proto.p_aliases = proto_aliases;
-       cp = p;
-       q = proto_aliases;
-       while (*cp) {
-               if (*cp == ' ' || *cp == '\t') {
-                       cp++;
-                       continue;
+       q = proto.p_aliases = proto_aliases;
+       if (p != NULL) {
+               cp = p;
+               while (cp && *cp) {
+                       if (*cp == ' ' || *cp == '\t') {
+                               cp++;
+                               continue;
+                       }
+                       if (q < &proto_aliases[MAXALIASES - 1])
+                               *q++ = cp;
+                       cp = any(cp, " \t");
+                       if (cp != NULL)
+                               *cp++ = '\0';
                }
                }
-               if (q < &proto_aliases[MAXALIASES - 1])
-                       *q++ = cp;
-               cp = any(cp, " \t");
-               if (*cp != NULL)
-                       *cp++ = '\0';
        }
        *q = NULL;
        return (&proto);
        }
        *q = NULL;
        return (&proto);