1 /* dhcp_init(), dhcp_settag() 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]))
13 #define arraylimit(a) ((a) + arraysize(a))
15 void dhcp_init(dhcp_t
*dp
)
17 /* Initialize a DHCP packet. */
18 memset(dp
, 0, offsetof(dhcp_t
, magic
));
19 dp
->magic
= DHCP_MAGIC
;
20 memset(dp
->options
, 255, sizeof(dp
->options
));
23 int dhcp_settag(dhcp_t
*dp
, int tag
, void *data
, size_t len
)
25 /* Add a tag to a DHCP packet. No padding. Only do the options field.
26 * (This is Minix, we don't need megabytes of silly bits of data.)
27 * The length may be zero to delete a tag.
32 if (tag
<= 0 || tag
>= 255) return 0;
34 for (p
= dp
->options
; p
< arraylimit(dp
->options
) && *p
!= 255; p
+= n
) {
37 /* The tag is already there, remove it so it gets replaced. */
38 memmove(p
, p
+ n
, arraylimit(dp
->options
) - (p
+ n
));
39 memset(arraylimit(dp
->options
) - n
, 255, n
);
46 /* We're merely deleting a tag. */
48 if (p
+ 1 + 1 + len
<= arraylimit(dp
->options
)) {
53 /* Oops, it didn't fit? Is this really Minix??? */