#ifndef _S_DHCP_OPTIONS_H
#define _S_DHCP_OPTIONS_H
#include <stdio.h>
#include <mach/boolean.h>
#include "ptrlist.h"
#include "dhcp.h"
#include "gen_dhcp_tags.h"
#include "gen_dhcp_types.h"
#define DHCP_OPTION_TAG_MAX 255
#define DHCP_OPTION_SIZE_MAX 255
#define TAG_OFFSET 0
#define LEN_OFFSET 1
#define OPTION_OFFSET 2
typedef struct {
char str[256];
} dhcpo_err_str_t;
struct dhcpoa_s {
u_long oa_magic;
void * oa_buffer;
int oa_size;
int oa_offset;
boolean_t oa_end_tag;
int oa_last;
int oa_prev_last;
int oa_option_count;
dhcpo_err_str_t oa_err;
int oa_reserve;
};
typedef struct dhcpoa_s dhcpoa_t;
typedef enum {
dhcpoa_success_e = 0,
dhcpoa_failed_e,
dhcpoa_full_e,
} dhcpoa_ret_t;
void
dhcpoa_init(dhcpoa_t * opt, void * buffer, int size);
void
dhcpoa_init_no_end(dhcpoa_t * opt, void * buffer, int size);
dhcpoa_ret_t
dhcpoa_add(dhcpoa_t * oa_p, dhcptag_t tag, int len, const void * option);
dhcpoa_ret_t
dhcpoa_add_from_strlist(dhcpoa_t * oa_p, dhcptag_t tag,
const char * * strlist, int strlist_len);
dhcpoa_ret_t
dhcpoa_add_from_str(dhcpoa_t * oa_p, dhcptag_t tag,
const char * str);
dhcpoa_ret_t
dhcpoa_add_dhcpmsg(dhcpoa_t * oa_p, dhcp_msgtype_t msgtype);
dhcpoa_ret_t
dhcpoa_vendor_add(dhcpoa_t * oa_p, dhcpoa_t * vendor_oa_p,
dhcptag_t tag, int len, void * option);
char *
dhcpoa_err(dhcpoa_t * oa_p);
int
dhcpoa_used(dhcpoa_t * oa_p);
int
dhcpoa_count(dhcpoa_t * oa_p);
void *
dhcpoa_buffer(dhcpoa_t * oa_p);
int
dhcpoa_freespace(dhcpoa_t * oa_p);
int
dhcpoa_size(dhcpoa_t * oa_p);
typedef ptrlist_t dhcpol_t;
void dhcpol_init(dhcpol_t * list);
void dhcpol_free(dhcpol_t * list);
int dhcpol_count(dhcpol_t * list);
boolean_t dhcpol_add(dhcpol_t * list, void * element);
void * dhcpol_element(dhcpol_t * list, int i);
boolean_t dhcpol_concat(dhcpol_t * list, dhcpol_t * extra);
boolean_t dhcpol_parse_buffer(dhcpol_t * list, void * buffer,
int length, dhcpo_err_str_t * err);
void * dhcpol_find(dhcpol_t * list, int tag, int * len_p,
int * start);
void * dhcpol_find_with_length(dhcpol_t * options,
dhcptag_t tag, int min_length);
void * dhcpol_option_copy(dhcpol_t * list, int tag,
int * len_p);
boolean_t dhcpol_parse_packet(dhcpol_t * options,
struct dhcp * pkt, int len,
dhcpo_err_str_t * err);
boolean_t dhcpol_parse_vendor(dhcpol_t * vendor,
dhcpol_t * options,
dhcpo_err_str_t * err);
void dhcpol_print(dhcpol_t * list);
void dhcpol_fprint(FILE * f, dhcpol_t * list);
int dhcpol_count_params(dhcpol_t * options,
const uint8_t * tags, int size);
const dhcptype_info_t * dhcptype_info(dhcptype_t type);
boolean_t dhcptype_from_str(const char * str,
int type, void * buf, int * len_p,
dhcpo_err_str_t * err);
boolean_t dhcptype_to_str(char * str, size_t str_len, const void * opt,
int len, int type,
dhcpo_err_str_t * err);
void dhcptype_print_simple(dhcptype_t type,
const void * opt, int option_len);
void dhcptype_print(dhcptype_t type, const void * option,
int option_len);
const dhcptag_info_t * dhcptag_info(dhcptag_t tag);
dhcptag_t dhcptag_with_name(const char * name);
const char * dhcptag_name(int tag);
boolean_t dhcptag_from_strlist(const char * * slist,
int num, int tag, void * buf,
int * len_p,
dhcpo_err_str_t * err);
boolean_t dhcptag_to_str(char * tmp, size_t tmplen, int tag,
const void * opt, int len,
dhcpo_err_str_t * err);
boolean_t dhcptag_print(const void * vopt);
#endif