1 /* dhcp_gettag() Author: Kees J. Bot
9 #include <net/gen/in.h>
10 #include <net/gen/dhcp.h>
12 #define arraysize(a) (sizeof(a) / sizeof((a)[0]))
14 int dhcp_gettag(dhcp_t
*dp
, int searchtag
, u8_t
**pdata
, size_t *plen
)
16 /* Find a tag in the options field, or possibly in the file or sname
17 * fields. Return true iff found, and return the data and/or length if
18 * their pointers are non-null.
25 /* The DHCP magic number must be correct, or no tags. */
26 if (dp
->magic
!= DHCP_MAGIC
) return 0;
28 optfield
[0]= dp
->options
;
29 optlen
[0]= arraysize(dp
->options
);
30 optfield
[1]= dp
->file
;
31 optlen
[1]= 0; /* Unknown if used for options yet. */
32 optfield
[2]= dp
->sname
;
35 for (i
= 0; i
< 3; i
++) {
37 while (p
< optfield
[i
] + optlen
[i
]) {
39 if (tag
== 255) break;
40 len
= tag
== 0 ? 0 : *p
++;
41 if (tag
== searchtag
) {
42 if (pdata
!= nil
) *pdata
= p
;
43 if (plen
!= nil
) *plen
= len
;
46 if (tag
== DHCP_TAG_OVERLOAD
) {
47 /* There are also options in the file or sname field. */
48 if (*p
& 1) optlen
[1]= arraysize(dp
->file
);
49 if (*p
& 2) optlen
[1]= arraysize(dp
->sname
);