📄 net_ipv4.h
字号:
typedef struct icmphdr { uint8_t type; // ICMP_ uint8_t code; uint16_t checksum; // checksum of ICMP header + data union { struct { uint16_t id; uint16_t sequence; } echo; // ICMP_ECHO, ICMP_ECHOREPLY uint32_t gateway; struct { uint16_t __unused; uint16_t mtu; } frag; } un; unsigned char data[MAX_ICMP_DATA];} __attribute__((packed)) icmphdr_t;// ICMP IP packettypedef struct icmpip { struct iphdr ip; struct icmphdr icmp;} __attribute__((packed)) icmpip_t;/* * UDP related definitions * Some of these definitions are from /usr/include/linux/udp.h */// UDP packet headertypedef struct udphdr { uint16_t src; // source : source port uint16_t dest; // dest : destination port uint16_t len; // len : length including header and data uint16_t checksum; // check : checksum of UDP header, pseudo header and data} __attribute__((packed)) udphdr_t;// pseudo TCP/UDP header// used for calculating checksum of TCP/UDP packettypedef struct tcpudp_pseudohdr { in_addr_t src; // source address in_addr_t dest; // destination address uint8_t zero; // 0 uint8_t protocol; // protocol uint16_t length; // TCP/UDP length} __attribute__((packed)) tcpudp_pseudohdr_t;/* * BOOTP / DHCP related definitions */// BOOTP retry maximum count#define MAX_BOOTP_RETRIES 3// DHCP option length#define DHCP_OPT_LEN 312// opcode : bp_op#define BOOTP_REQUEST 1#define BOOTP_REPLY 2// DHCP_MESSAGE_TYPE code#define DHCPDISCOVER 1#define DHCPOFFER 2#define DHCPREQUEST 3#define DHCPDECLINE 4#define DHCPACK 5#define DHCPNAK 6#define DHCPRELEASE 7#define DHCPINFORM 8// BOOTP/DHCP packet header and body (option)typedef struct bootphdr { uint8_t bp_op; // opcode : BOOTP_REQUEST / BOOTP_REPLY uint8_t bp_htype; // hardware address type uint8_t bp_hlen; // hardware address length uint8_t bp_hops; // 0 uint32_t bp_xid; // random transaction ID uint16_t bp_secs; // seconds elapsed uint16_t bp_flags; // unused in_addr_t bp_ciaddr; // client IP address in_addr_t bp_yiaddr; // your (client) IP address in_addr_t bp_siaddr; // server IP address in_addr_t bp_giaddr; // gateway IP address uint8_t bp_hwaddr[16]; // client hardware address uint8_t bp_sname[64]; // optional server hostname (null-terminated) uint8_t bp_file[128]; // boot file name(null-terminated) uint8_t bp_vend[DHCP_OPT_LEN]; // optional vendor-specific area} __attribute__((packed)) bootphdr_t;// BOOTP/DHCP IP packettypedef struct bootpip { struct iphdr ip; struct udphdr udp; struct bootphdr bp;} __attribute__((packed)) bootpip_t;/* * TFTP related definitions */// TFTP retry maximum count#define MAX_TFTP_RETRIES 3// TFTP packet size#define TFTP_DEF_PACKET 512#define TFTP_MAX_PACKET 1432 // TFTP packet type#define TFTPOP_RRQ 1 // Read Request#define TFTPOP_WRQ 2 // Write Request#define TFTPOP_DATA 3 // Data#define TFTPOP_ACK 4 // Acknowledgment#define TFTPOP_ERROR 5 // Error#define TFTPOP_OACK 6 // Option Acknowledgment// TFTP error code#define TFTPERR_FILENOTFOUND 1 // File not found#define TFTPERR_ACCESSDENIED 2 // Access violation#define TFTPERR_DISKFULL 3 // Disk full or allocation exceeded#define TFTPERR_ILLEGALOP 4 // Illeegal TFTP operation#define TFTPERR_UNKNOWNID 5 // Unknown transfer ID#define TFTPERR_FILEEXIST 6 // File already exists#define TFTPERR_NOUSER 7 // No such user// return code of ipv4_tftp()#define TFTPRET_NETWORKERR 1 #define TFTPRET_FILENOTFOUND 2#define TFTPRET_ACCESSDENIED 3#define TFTPRET_OTHER 4// TFTP header and bodytypedef struct tftphdr { uint16_t opcode; // TFTPOP_ union { uint8_t rrq[TFTP_DEF_PACKET]; // TFTPOP_RRQ, TFTPOP_WRQ struct { uint16_t block; uint8_t data[TFTP_MAX_PACKET]; } data; // TFTPOP_DATA struct { uint16_t block; } ack; // TFTPOP_ACK struct { uint16_t errcode; uint8_t errmsg[TFTP_DEF_PACKET]; } err; // TFTPOP_ERROR struct { uint8_t data[TFTP_DEF_PACKET]; } oack; // TFTPOP_OACK } u;} __attribute__((packed)) tftphdr_t;// TFTP IP packettypedef struct tftpip { struct iphdr ip; struct udphdr udp; struct tftphdr tftp;} __attribute__((packed)) tftpip_t;/* * function prototypes */struct sk_buff;#define TIMEOUT (5 * 1000)// initint ipv4_init(void);void ipv4_setup_arptable(in_addr_t ipaddr, in_addr_t netmask, unsigned char *node, in_addr_t gateway, in_addr_t dns);// TCP/IP basicint ipv4_get_ipaddr_class(in_addr_t ipaddr);in_addr_t ipv4_get_default_netmask(in_addr_t ipaddr);int ipv4_ipaddr_valid(in_addr_t ipaddr);int ipv4_alloc_port(void);// packet processingint ipv4_check_for_me(struct sk_buff *skb);int ipv4_parsepacket(struct sk_buff *skb);int ipv4_processpacket(struct sk_buff *skb);// Ethernetenum { WAIT_NOTHING, WAIT_ARP_REPLY, WAIT_ICMP_REPLY, WAIT_UDP,};int eth_transmit(unsigned char *dest, uint16_t type, unsigned int len, const void *buf, int async);struct sk_buff *eth_receive(int type, int timeout);// arparptable_t *arp_lookup(unsigned long ipaddr);arptable_t *arp_alloc(void);int arp_valid(arptable_t *arp);void arp_setaddr(arptable_t *arp, in_addr_t ipaddr, in_addr_t netmask, unsigned char *node);void arp_setaddr_index(int index, in_addr_t ipaddr, in_addr_t netmask, unsigned char *node);void arp_listtable(arptable_t *arp);int arp_transmit(int opcode, in_addr_t ipaddr, unsigned char *node, int async);arptable_t *arp_dorequest(unsigned long ipaddr, int async);// IPint ip_transmit(in_addr_t destip, int protocol, int len, const void *buf, int async);unsigned int ipv4_calc_sum(const void *ip, int len);unsigned short ipv4_calc_checksum(const void *ip, int len);// ICMP / IPint icmp_ping(in_addr_t destip, int count);// UDP / IPint udp_transmit(in_addr_t destip, unsigned int srcsock, unsigned int destsock, int len, const void *buf, int async);unsigned short ipv4_calc_tcpudp_checksum(const void *data, int len, in_addr_t src, in_addr_t dest);struct sk_buff *udp_receive(in_addr_t fromip, unsigned int srcsock, unsigned int destsock, int timeout);// BOOTP / DHCP (net_ipv4_bootp.c)int ipv4_bootp(int bootp);// TFTP (net_ipv4_tftp.c)int ipv4_tftp(in_addr_t ipaddr, char *filename, unsigned int addr, unsigned int *datalen);// DNS (net_ipv4_dns.c)in_addr_t ipv4_gethostbyname(char *name);// Miscellaneousvoid ipv4_dump_packet(struct sk_buff *skb, int type, int need_parsing);void bootp_dump_packet(struct sk_buff *skb, int need_parsing);void tftp_dump_packet(struct sk_buff *skb, int need_parsing);#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -