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]
23 * Copyright (c) 1994, by Sun Microsystems, Inc.
28 #include <sys/types.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
37 putservent(const struct servent
*sp
, FILE *fp
)
46 if (fprintf(fp
, "%-20s %d/%s",
47 sp
->s_name
, ntohs(sp
->s_port
), sp
->s_proto
) == EOF
)
49 for (p
= sp
->s_aliases
; *p
!= 0; p
++) {
50 if (fprintf(fp
, " %s", *p
) == EOF
)
53 if (putc('\n', fp
) == EOF
)
59 * getservbyname/addr - get entries from service database
60 * Accepts arguments as:
67 dogetserv(const char **list
)
72 if (list
== NULL
|| *list
== NULL
) {
73 while ((sp
= getservent()) != NULL
)
74 (void) putservent(sp
, stdout
);
76 for (; *list
!= NULL
; list
++) {
79 const char *protocol
= NULL
;
82 /* Copy string to avoiding modifying the argument */
83 (void) strncpy(key
, *list
, sizeof (key
));
84 key
[sizeof (key
) - 1] = '\0';
85 /* Split at a '/' to extract protocol number */
86 if ((cp
= strchr(key
, '/')) != NULL
) {
90 port
= htons(atoi(key
));
92 sp
= getservbyport(port
, protocol
);
94 sp
= getservbyname(key
, protocol
);
96 rc
= EXC_NAME_NOT_FOUND
;
98 (void) putservent(sp
, stdout
);