4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
22 #ident "%Z%%M% %I% %E% SMI"
25 * Copyright (c) 1994, by Sun Microsystems, Inc.
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
39 putservent(const struct servent
*sp
, FILE *fp
)
48 if (fprintf(fp
, "%-20s %d/%s",
49 sp
->s_name
, ntohs(sp
->s_port
), sp
->s_proto
) == EOF
)
51 for (p
= sp
->s_aliases
; *p
!= 0; p
++) {
52 if (fprintf(fp
, " %s", *p
) == EOF
)
55 if (putc('\n', fp
) == EOF
)
61 * getservbyname/addr - get entries from service database
62 * Accepts arguments as:
69 dogetserv(const char **list
)
74 if (list
== NULL
|| *list
== NULL
) {
75 while ((sp
= getservent()) != NULL
)
76 (void) putservent(sp
, stdout
);
78 for (; *list
!= NULL
; list
++) {
81 const char *protocol
= NULL
;
84 /* Copy string to avoiding modifying the argument */
85 (void) strncpy(key
, *list
, sizeof (key
));
86 key
[sizeof (key
) - 1] = NULL
;
87 /* Split at a '/' to extract protocol number */
88 if ((cp
= strchr(key
, '/')) != NULL
) {
92 port
= htons(atoi(key
));
94 sp
= getservbyport(port
, protocol
);
96 sp
= getservbyname(key
, protocol
);
98 rc
= EXC_NAME_NOT_FOUND
;
100 (void) putservent(sp
, stdout
);