8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / common / net / dhcp / dhcpinfo.c
blob656371f4df112513f50605487b3c76879ae29a27
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 <sys/types.h>
30 #include <stddef.h>
31 #include <stdlib.h>
32 #include <strings.h>
33 #include <netinet/in.h>
34 #include <netinet/dhcp.h>
35 #include "dhcp_impl.h"
38 * Fetch a copy of the DHCP-supplied value of the parameter requested
39 * by code in value, and the parameter value length in *vallenp.
41 * Return values:
43 * B_FALSE If invalid code, or no parameter value.
45 * B_TRUE Valid code which has a parameter value.
46 * *vallenp is set to the parameter value length.
47 * If the parameter value length is less than or
48 * equal to *vallenp, value is set to the parameter
49 * value.
52 boolean_t
53 dhcp_getinfo_pl(PKT_LIST *pl, uchar_t optcat, uint16_t code, uint16_t optsize,
54 void *value, size_t *vallenp)
57 if (pl == NULL)
58 return (B_FALSE);
60 if (optcat == DSYM_STANDARD) {
61 if (code > DHCP_LAST_OPT)
62 return (B_FALSE);
64 if (pl->opts[code] == NULL)
65 return (B_FALSE);
67 if (*vallenp < pl->opts[code]->len) {
68 *vallenp = pl->opts[code]->len;
69 return (B_TRUE);
72 bcopy(pl->opts[code]->value, value, pl->opts[code]->len);
73 *vallenp = pl->opts[code]->len;
75 } else if (optcat == DSYM_VENDOR) {
76 if (code > VS_OPTION_END)
77 return (B_FALSE);
79 if (pl->vs[code] == NULL)
80 return (B_FALSE);
82 if (*vallenp < pl->vs[code]->len) {
83 *vallenp = pl->vs[code]->len;
84 return (B_TRUE);
87 bcopy(pl->vs[code]->value, value, pl->vs[code]->len);
88 *vallenp = pl->vs[code]->len;
90 } else if (optcat == DSYM_FIELD) {
91 if (code + optsize > sizeof (PKT))
92 return (B_FALSE);
94 if (*vallenp < optsize) {
95 *vallenp = optsize;
96 return (B_TRUE);
99 *vallenp = optsize;
100 bcopy((caddr_t)pl->pkt + code, value, optsize);
102 } else
103 return (B_FALSE);
105 return (B_TRUE);