ses: SUN plugin doesn't actually need libnvfru
[unleashed.git] / usr / src / lib / libfsmgt / common / nfs_netcfg.c
blobf12d244d30c2e97b84a0085dd9f4ca3b398293fe
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <errno.h>
30 #include <netconfig.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include "libfsmgt.h"
36 * Public methods
39 void
40 netcfg_free_networkid_list(char **netlist, int num_elements)
42 fileutil_free_string_array(netlist, num_elements);
43 } /* netcfg_free_networkid_list */
45 char **
46 netcfg_get_networkid_list(int *num_elements, int *errp)
48 struct netconfig *nconf;
49 NCONF_HANDLE *nc;
50 char **return_list = NULL;
53 * setnetconfig must be called before getnetconfig in order to get the
54 * netconfig handle.
56 if ((nc = setnetconfig()) == (NCONF_HANDLE *)NULL) {
57 *errp = errno;
58 return (NULL);
61 *num_elements = 0;
62 while (nconf = getnetconfig(nc)) {
63 char **tmp_list;
66 * Put the elements in the array.
68 tmp_list = realloc(return_list,
69 (size_t)(((*num_elements)+1) * sizeof (char *)));
70 if (tmp_list == NULL) {
71 *errp = errno;
72 netcfg_free_networkid_list(return_list, *num_elements);
73 *num_elements = 0;
74 (void) endnetconfig(nc);
75 return (NULL);
78 return_list = tmp_list;
80 return_list[(*num_elements)] = strdup(nconf->nc_netid);
81 if (return_list[(*num_elements)] == NULL) {
82 *errp = ENOMEM;
83 netcfg_free_networkid_list(return_list, *num_elements);
84 *num_elements = 0;
85 (void) endnetconfig(nc);
86 return (NULL);
89 *num_elements = *num_elements + 1;
92 (void) endnetconfig(nc);
94 * Caller must free the space allocated to return_list by calling
95 * netcfg_free_networkid_list.
97 return (return_list);
98 } /* netcfg_get_networkid_list */