📄 dhcp-librawnet.h
字号:
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-librawnet.h,v 1.21 2003/07/05 19:18:17 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */#ifndef DHCP_LIBRAWNET_H#define DHCP_LIBRAWNET_H/* type definitions. */typedef uint8_t dhcp_opt_tag_t;typedef size_t dhcp_opt_len_t;typedef uint16_t dhcp_opt_type_t;typedef uint16_t dhcp_opt_val_type_t;/* forward declare dhcp_opt to typedef function pointers below. */struct dhcp_opt;/* typedef of dhcp option function pointers. *//* converters from external data to internal */typedef int (*dhcp_opt_from_string)(struct dhcp_opt *opt, const char *input);typedef int (*dhcp_opt_from_user_string)(struct dhcp_opt *opt, list_t *input_list);typedef int (*dhcp_opt_from_network)(struct dhcp_opt *opt, const uint8_t *data, size_t len);/* converts from internal data to other data formats. */typedef void *(*dhcp_opt_to_network_data)(struct dhcp_opt *opt);typedef void *(*dhcp_opt_to_host_data)(struct dhcp_opt *opt);typedef char *(*dhcp_opt_to_user_string)(struct dhcp_opt *opt);typedef char *(*dhcp_opt_to_string)(struct dhcp_opt *opt);/* data structures. *//* interface control object: * we store dnet's interface handle, * and interface_entry structure. * We need the entry structure */typedef struct { intf_t *interface_handle; struct intf_entry *interface_entry;} interface_control_t;/* DHCP fixed header -- before dhcp options. *//* Size of header independant of any padding * sizeof() the structure may return. */#define DHCP_FIXEDHDR_LEN 236typedef struct { uint8_t op; uint8_t htype; uint8_t hlen; uint8_t hops; uint32_t xid; uint16_t secs; uint16_t flags; uint32_t ciaddr; uint32_t yiaddr; uint32_t siaddr; uint32_t giaddr;#define DHCP_CHADDR_SIZE 16 unsigned char chaddr[DHCP_CHADDR_SIZE];#define DHCP_SNAME_SIZE 64 unsigned char sname[DHCP_SNAME_SIZE];#define DHCP_FILE_SIZE 128 unsigned char file[DHCP_FILE_SIZE]; /* options go here. */} dhcphdr;/* the data destructor. */typedef void (*dhcp_opt_data_destroy)(struct dhcp_opt *opt);typedef struct dhcp_opt_attr { dhcp_opt_tag_t tag; /* tag */ dhcp_opt_len_t len; /* member length in octets */ dhcp_opt_val_type_t type; /* type of opt */ dhcp_opt_val_type_t val_type; /* type of val */ /* data extraction routines. */ dhcp_opt_to_network_data to_network_data; /* to network data representation. */ dhcp_opt_to_user_string to_user_string; /* to user string representation. */ dhcp_opt_to_string to_internal_string; /* to internal string representation. */ /* data creation routines. */ dhcp_opt_from_network from_network; /* network data to internal. */ dhcp_opt_from_user_string from_user_string; /* user string to internal. */ dhcp_opt_from_string from_internal_string; /* string to internal. */ dhcp_opt_data_destroy destroy; /* destroy option datum. */} dhcp_opt_attr_t;/* the dhcp option object. */typedef struct dhcp_opt { void *val; /* value */ size_t num; /* num */ dhcp_opt_attr_t *opt_attr; /* attributes */} dhcp_opt_t;/* DHCP object * * for packet assembly/disassembly. */typedef struct { dhcphdr fixedheader; /* DHCP fixed header. */ uint32_t magic_cookie; /* Magic cookie. */ list_t *options; /* Option list. */} dhcp_obj;/* * Other packet objects. * * We use these to create a single interface * for creating custom packeting. * */typedef struct { struct eth_hdr header;} eth_obj;typedef struct { struct ip_hdr header;} ip_obj;typedef struct { struct arp_hdr header; struct arp_ethip arp_data;} arp_obj;typedef struct { struct icmp_hdr icmp_header; union icmp_msg icmp_msg;} icmp_obj;typedef struct { struct udp_hdr header;} udp_obj;/* * DHCP raw network object. * * We do all our network transmission * through this data structure. * */typedef struct { /* we should not interface directly with any of these members * above the rawnet layer: FIXME -- unfortunately we do. */ pcap_t *pcap; /* packet capturing device (pcap). */ int pcap_fd; /* file descriptor we can select on for pcap. */ eth_t *eth; /* ethernet device handler (libdnet). */ uint16_t src_port, dst_port; /* udp ports for writing packets. */ char *device; /* device name. */ char *packet_data; /* packet data. */ int packet_len; /* total length of packet. */ struct timeval tstamp; /* timestamp. */ eth_addr_t chw_addr; /* our hardware address. */ ip_addr_t cip_addr; /* our ip address. */ eth_addr_t *fake_hw_addr; /* our fake hardware address. */ int promiscuous; /* run in promiscuous mode flag. */ int mtu; /* mtu setting. */ interface_control_t *intf_handle; /* interface control handle. */ /* * Data objects * * After reception of packets on the wire * they're aligned and placed into these * objects. * */ uint8_t type; /* Type of data: * ARP, ICMP DHCP */ char *pcap_filter; /* low level pcap filter. */ /* Packet data. */ eth_obj *ether_p; ip_obj *ip_p; arp_obj *arp_p; icmp_obj *icmp_p; udp_obj *udp_p; dhcp_obj *dhcp_p;} rawnet_t;/* constants. *//* Reasonable defaults in case services db isn't up to date. */#define BOOTP_CLIENT 68#define BOOTP_SERVER 67/* Raw net types for packets. */#define RAWNET_UNKNOWN 0#define RAWNET_ARP 1#define RAWNET_ICMP 2#define RAWNET_DHCP 3/* Raw net return types when * receiving packets. */#define RAWNET_OK 0#define RAWNET_PCAP_ERROR -1#define RAWNET_ERROR -2 /* generic error. */#define RAWNET_MALFORMED_PACKET -3#define RAWNET_UNHANDLED -4#define RAWNET_TIMEOUT -5#define RAWNET_USER_INTERRUPT -6/* DHCP Type messages */# define DHCP_DISCOVER_TM 1# define DHCP_OFFER_TM 2# define DHCP_REQUEST_TM 3# define DHCP_DECLINE_TM 4# define DHCP_DHCPACK_TM 5# define DHCP_DHCPNAK_TM 6# define DHCP_RELEASE_TM 7/* BOOTP Types */#define DHCP_BOOTP_REQUEST 1#define DHCP_BOOTP_REPLY 2/* Flags */#define DHCP_BROADCAST_FLAG 0x8000/* Option tags. *//* (this is me trying to make constant names out of long option * names. let the comedy ensue!) */# define TAG_DHCP_PAD 0# define TAG_DHCP_SUBNET_MASK 1# define TAG_DHCP_TIME_OFFSET 2# define TAG_DHCP_ROUTER 3# define TAG_DHCP_TIME_SERVER 4# define TAG_DHCP_NAME_SERVER 5# define TAG_DHCP_DOMAIN_NAME_SERVER 6# define TAG_DHCP_LOG_SERVER 7# define TAG_DHCP_COOKIE_SERVER 8# define TAG_DHCP_LPR_SERVER 9# define TAG_DHCP_IMPRESS_SERVER 10# define TAG_DHCP_RESOURCE_LOCATION_SERVER 11# define TAG_DHCP_HOST_NAME 12# define TAG_DHCP_BOOT_FILE_SIZE 13# define TAG_DHCP_MERIT_DUMP_FILE 14# define TAG_DHCP_DOMAIN_NAME 15# define TAG_DHCP_SWAP_SERVER 16# define TAG_DHCP_ROOT_PATH 17# define TAG_DHCP_EXTENSIONS_PATH 18# define TAG_DHCP_IP_FORWARDING 19# define TAG_DHCP_NON_LOCAL_SOURCE_ROUTING 20# define TAG_DHCP_POLICY_FILTER 21# define TAG_DHCP_MAX_DGRAM_REASSUMBLY_SIZE 22# define TAG_DHCP_IP_TIME_TO_LIVE 23# define TAG_DHCP_MTU_AGING_TIMEOUT 24# define TAG_DHCP_MTU_PLATEAU_TABLE 25# define TAG_DHCP_INTERFACE_MTU 26
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -