vcpe/dhcp_tools/main.h

101 lines
2.5 KiB
C
Raw Normal View History

//
// Created by xajhuang on 2023/4/19.
//
#ifndef VCPE_MAIN_H
#define VCPE_MAIN_H
#include <gtk/gtk.h>
#include "uthash/uthash.h"
#include "rfc2131.h"
#include "service/dhcpd.h"
#define ADD_LOG_MSG(level, m, format, ...) \
(format_log_msg(level, (m), "[%s] - %s(%d):" format, basename_v2(__FILE__), __FUNCTION__, __LINE__, ##__VA_ARGS__))
typedef enum {
COL_INDEX = 0,
COL_VNI,
COL_MAC,
COL_HOSTNAME,
COL_DISCOVER,
COL_OFFER,
COL_REQUEST,
COL_ACK,
COL_RESULT,
COL_STATUS,
2023-04-20 09:48:19 +00:00
COL_ATTR_EDITABLE,
COL_ATTR_VISIABLE,
NUM_COLS
} COL_NAME;
typedef enum {
COL_DHCP_ITEM = 0,
COL_DHCP_VALUE,
COL_ITEM_ATTR_VISIABLE,
COL_VALUE_ATTR_VISIABLE,
NUM_DHCP_COLS
} COL_DHCP_INFO_NAME;
typedef enum {
STEP_BEGIN = 0,
STEP_DISCOVER,
STEP_OFFER,
STEP_REQUEST,
STEP_ACK,
STEP_END,
} DHCP_STEP;
typedef enum {
STA_WAIT_START = 0,
STA_SEND_REQ,
STA_RECV_RSP,
STA_RECV_NACK,
STA_ERROR
} DHCP_STATUS;
typedef struct {
U8 *p;
int buf_size;
struct timeval tm;
U32 snd;
} BUF_INFO, *PBUF_INFO;
typedef struct {
U32 index;
U32 vni;
U8 mac[6];
S8 hostname[64];
DHCP_STEP step;
DHCP_STATUS status;
BUF_INFO pDiscBuf;
BUF_INFO pOfferBuf;
BUF_INFO pReqBuf;
BUF_INFO pAckBuf;
DHCP_RSP offerRsp;
DHCP_RSP ackRsp;
S8 treeId[32];
U8 close;
UT_hash_handle hh;
} DHCP_INFO, *PDHCP_INFO;
U32 rand_number();
PDHCP_INFO get_dhcp_info_by_id(U32 xid);
int dhcp_tools_init_network(const char *pNicName);
U8 *dhcp_create_discover_req(PDHCP_INFO pInfo, int *pOutSize);
U8 *dhcp_create_request_req(PDHCP_INFO pInfo, int *pOutSize);
int cacheDhcpOfferBuffer(PDHCP_INFO pInfo, U8 *pBuf, int size);
int cacheDhcpAckBuffer(PDHCP_INFO pInfo, U8 *pBuf, int size);
void details_wnd_create(GtkBuilder *builder);
void details_wnd_show(PDHCP_INFO pInfo);
void hex_wnd_create(GtkBuilder *builder);
void hex_wnd_show(PDHCP_INFO pInfo);
void statis_wnd_create(GtkBuilder *builder);
void write_log_msg(const char *pMsg, int mode);
GtkBuilder *get_main_builder();
void format_log_msg(int level, int mode, const char *pMsg, ...);
PDHCP_PROTO get_dhcp_date(void *pBuf, U32 *pOptSize, U32 bufSize);
#endif //VCPE_MAIN_H