diff options
Diffstat (limited to 'src/lib/libc/net/getnetent.c')
| -rw-r--r-- | src/lib/libc/net/getnetent.c | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c index b4e16b8f5d..57fe459e2b 100644 --- a/src/lib/libc/net/getnetent.c +++ b/src/lib/libc/net/getnetent.c | |||
| @@ -1,5 +1,4 @@ | |||
| 1 | /* $NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $ */ | 1 | /* $OpenBSD: getnetent.c,v 1.13 2012/04/10 16:41:10 eric Exp $ */ |
| 2 | |||
| 3 | /* | 2 | /* |
| 4 | * Copyright (c) 1983, 1993 | 3 | * Copyright (c) 1983, 1993 |
| 5 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
| @@ -12,11 +11,7 @@ | |||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the | 12 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. | 13 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software | 14 | * 3. Neither the name of the University nor the names of its contributors |
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed by the University of | ||
| 18 | * California, Berkeley and its contributors. | ||
| 19 | * 4. Neither the name of the University nor the names of its contributors | ||
| 20 | * may be used to endorse or promote products derived from this software | 15 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. | 16 | * without specific prior written permission. |
| 22 | * | 17 | * |
| @@ -33,15 +28,7 @@ | |||
| 33 | * SUCH DAMAGE. | 28 | * SUCH DAMAGE. |
| 34 | */ | 29 | */ |
| 35 | 30 | ||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | 31 | #include <sys/param.h> |
| 37 | #if 0 | ||
| 38 | static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; | ||
| 39 | #else | ||
| 40 | static char rcsid[] = "$NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $"; | ||
| 41 | #endif | ||
| 42 | #endif /* LIBC_SCCS and not lint */ | ||
| 43 | |||
| 44 | #include <sys/types.h> | ||
| 45 | #include <sys/socket.h> | 32 | #include <sys/socket.h> |
| 46 | #include <netinet/in.h> | 33 | #include <netinet/in.h> |
| 47 | #include <arpa/inet.h> | 34 | #include <arpa/inet.h> |
| @@ -58,8 +45,7 @@ static char *net_aliases[MAXALIASES]; | |||
| 58 | int _net_stayopen; | 45 | int _net_stayopen; |
| 59 | 46 | ||
| 60 | void | 47 | void |
| 61 | setnetent(f) | 48 | setnetent(int f) |
| 62 | int f; | ||
| 63 | { | 49 | { |
| 64 | if (netf == NULL) | 50 | if (netf == NULL) |
| 65 | netf = fopen(_PATH_NETWORKS, "r" ); | 51 | netf = fopen(_PATH_NETWORKS, "r" ); |
| @@ -69,7 +55,7 @@ setnetent(f) | |||
| 69 | } | 55 | } |
| 70 | 56 | ||
| 71 | void | 57 | void |
| 72 | endnetent() | 58 | endnetent(void) |
| 73 | { | 59 | { |
| 74 | if (netf) { | 60 | if (netf) { |
| 75 | fclose(netf); | 61 | fclose(netf); |
| @@ -79,24 +65,29 @@ endnetent() | |||
| 79 | } | 65 | } |
| 80 | 66 | ||
| 81 | struct netent * | 67 | struct netent * |
| 82 | getnetent() | 68 | getnetent(void) |
| 83 | { | 69 | { |
| 84 | char *p; | 70 | char *p, *cp, **q; |
| 85 | register char *cp, **q; | 71 | size_t len; |
| 86 | 72 | ||
| 87 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) | 73 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) |
| 88 | return (NULL); | 74 | return (NULL); |
| 89 | again: | 75 | again: |
| 90 | p = fgets(line, BUFSIZ, netf); | 76 | if ((p = fgetln(netf, &len)) == NULL) |
| 91 | if (p == NULL) | ||
| 92 | return (NULL); | 77 | return (NULL); |
| 93 | if (*p == '#') | 78 | if (p[len-1] == '\n') |
| 79 | len--; | ||
| 80 | if (len >= sizeof(line) || len == 0) | ||
| 94 | goto again; | 81 | goto again; |
| 95 | cp = strpbrk(p, "#\n"); | 82 | p = memcpy(line, p, len); |
| 96 | if (cp == NULL) | 83 | line[len] = '\0'; |
| 84 | if (*p == '#') | ||
| 97 | goto again; | 85 | goto again; |
| 98 | *cp = '\0'; | 86 | if ((cp = strchr(p, '#')) != NULL) |
| 87 | *cp = '\0'; | ||
| 99 | net.n_name = p; | 88 | net.n_name = p; |
| 89 | if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) | ||
| 90 | net.n_name[MAXHOSTNAMELEN-1] = '\0'; | ||
| 100 | cp = strpbrk(p, " \t"); | 91 | cp = strpbrk(p, " \t"); |
| 101 | if (cp == NULL) | 92 | if (cp == NULL) |
| 102 | goto again; | 93 | goto again; |
| @@ -109,15 +100,17 @@ again: | |||
| 109 | net.n_net = inet_network(cp); | 100 | net.n_net = inet_network(cp); |
| 110 | net.n_addrtype = AF_INET; | 101 | net.n_addrtype = AF_INET; |
| 111 | q = net.n_aliases = net_aliases; | 102 | q = net.n_aliases = net_aliases; |
| 112 | if (p != NULL) | 103 | cp = p; |
| 113 | cp = p; | ||
| 114 | while (cp && *cp) { | 104 | while (cp && *cp) { |
| 115 | if (*cp == ' ' || *cp == '\t') { | 105 | if (*cp == ' ' || *cp == '\t') { |
| 116 | cp++; | 106 | cp++; |
| 117 | continue; | 107 | continue; |
| 118 | } | 108 | } |
| 119 | if (q < &net_aliases[MAXALIASES - 1]) | 109 | if (q < &net_aliases[MAXALIASES - 1]) { |
| 120 | *q++ = cp; | 110 | *q++ = cp; |
| 111 | if (strlen(cp) >= MAXHOSTNAMELEN-1) | ||
| 112 | cp[MAXHOSTNAMELEN-1] = '\0'; | ||
| 113 | } | ||
| 121 | cp = strpbrk(cp, " \t"); | 114 | cp = strpbrk(cp, " \t"); |
| 122 | if (cp != NULL) | 115 | if (cp != NULL) |
| 123 | *cp++ = '\0'; | 116 | *cp++ = '\0'; |
