⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ether.h

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 H
📖 第 1 页 / 共 2 页
字号:
/*  * This file is a single "contains-all" header file to support different * components of ethernet/IP along with the peer and upper layer protocols * like ICMP, UDP, TFTP, DHCP etc... * *  General notice: *  This code is part of a boot-monitor package developed as a generic base *  platform for embedded system designs.  As such, it is likely to be *  distributed to various projects beyond the control of the original *  author.  Please notify the author of any enhancements made or bugs found *  so that all may benefit from the changes.  In addition, notification back *  to the author will allow the new user to pick up changes that may have *  been made by other users after this version of the code was distributed. * *  Note1: the majority of this code was edited with 4-space tabs. *  Note2: as more and more contributions are accepted, the term "author" *         is becoming a mis-representation of credit. * *  Original author:    Ed Sutter *  Email:              esutter@lucent.com *  Phone:              908-582-2351 *//************************************************************************ * * Retransmission delay stuff... *  */#define DELAY_INIT_ARP          1#define DELAY_INIT_DHCP         2#define DELAY_INIT_TFTP         3#define DELAY_INCREMENT         4#define DELAY_RETURN            5#define DELAY_OR_TIMEOUT_RETURN 6#define RETRANSMISSION_TIMEOUT  -1#define RETRANSMISSION_ACTIVE   1/************************************************************************ * * Ethernet stuff... *  */   struct ether_addr {    unsigned char  ether_addr_octet[6];}; struct  ether_header {    struct  ether_addr ether_dhost;    struct  ether_addr ether_shost;    unsigned short ether_type;};#define ETHERSIZE   sizeof(struct ether_header) #define ETHERTYPE_PUP           0x0200          /* PUP protocol */#define ETHERTYPE_IP            0x0800          /* IP protocol */#define ETHERTYPE_ARP           0x0806          /* Addr resolution protocol */#define ETHERTYPE_REVARP        0x8035          /* Reverse ARP */#define ETHER_MINPKT            64/* snoopInfo: * Structure to support snooping by the monitor's ethernet interface. * This feature is not working yet.  The intent is that when snooping is * enabled, it is given a block of memory into which it places the snooped * packets. */struct  snoopinfo {    int     on;                 /* 1 if snooping is on. */    unsigned long   base;       /* Base of memory storage. */    unsigned long   addr;       /* Running address of memory storage. */    unsigned long   size;       /* Size of memory storage. */    unsigned long   pktcnt;     /* Number of packets stored. */    unsigned char   mac[6];     /* MAC address to snoop. */};                                /************************************************************************ * * ARP/RARP stuff... * */#define SIZEOFARPCACHE  8#define ARPSIZE (sizeof(struct ether_header) + sizeof(struct arphdr))struct arphdr {    unsigned short  hardware;       /* 1 for ethernet */    unsigned short  protocol;    unsigned char   hlen;    unsigned char   plen;    unsigned short  operation;      unsigned char   senderha[6];    unsigned char   senderia[4];    unsigned char   targetha[6];    unsigned char   targetia[4];};/* ARP/RARP operations:. */#define ARP_REQUEST     1#define ARP_RESPONSE    2#define RARP_REQUEST    3#define RARP_RESPONSE   4/************************************************************************ * * IP stuff... * */struct in_addr {    unsigned long s_addr;};#define getIP_V(x)      ((x)>>4) #define getIP_HL(x)     ((x)&0xf)#define IP_DONTFRAG     0x4000          /* dont fragment flag */#define IP_MOREFRAGS    0x2000          /* more fragments flag */#define IP_VER          0x4#define IP_HDR_LEN      (sizeof(struct ip)>>2)#define IP_HDR_VER_LEN  ((IP_VER<<4)|IP_HDR_LEN)#define IP_HLEN(ihdr)   ((ihdr->ip_vhl&0x0f)<<2)struct ip {    unsigned char  ip_vhl;      /* version & header length */    unsigned char  ip_tos;      /* type of service */    short  ip_len;              /* total length */    unsigned short ip_id;       /* identification */    short  ip_off;              /* fragment offset field */    unsigned char  ip_ttl;      /* time to live */    unsigned char  ip_p;        /* protocol */    unsigned short ip_sum;      /* checksum */    struct in_addr ip_src;      /* source address */    struct in_addr ip_dst;      /* dest address */};#define IPSIZE  sizeof(struct ip)/* ip protocols */#define IP_IP   0#define IP_ICMP 1#define IP_IGMP 2#define IP_GGP  3#define IP_TCP  6#define IP_PUP  12#define IP_UDP  17/************************************************************************ * * ICMP stuff... *  */#define ICMP_UNREACHABLESIZE (sizeof(struct ether_header) + \    sizeof(struct ip) + sizeof(struct icmp_unreachable_hdr) + datalen)#define ICMP_TIMERQSTSIZE (sizeof(struct ether_header) + \    sizeof(struct ip) + sizeof(struct icmp_time_hdr))#define ICMP_ECHORQSTSIZE (sizeof(struct ether_header) + \    sizeof(struct ip) + sizeof(struct icmp_echo_hdr))#define INVALID_TIMESTAMP 0xffffffff#define NONSTANDARD_TIMESTAMP 0x80000000/* ICMP protocol header. */struct icmp_hdr {    unsigned char   type;       /* type of message */    unsigned char   code;       /* type subcode */    unsigned short  cksum;      /* ones complement cksum of struct */};/* ICMP time request. */struct icmp_time_hdr {    unsigned char   type;       /* type of message */    unsigned char   code;       /* type subcode */    unsigned short  cksum;      /* ones complement cksum of struct */    unsigned short  id;         /* identifier */    unsigned short  seq;        /* sequence number */    unsigned long   orig;       /* originate timestamp */    unsigned long   recv;       /* receive timestamp */    unsigned long   xmit;       /* transmit timestamp */};/* ICMP echo reply. */struct icmp_echo_hdr {    unsigned char   type;       /* type of message */    unsigned char   code;       /* type subcode */    unsigned short  cksum;      /* ones complement cksum of struct */    unsigned short  id;         /* identifier */    unsigned short  seq;        /* sequence number */};struct icmp_unreachable_hdr {    unsigned char   type;       /* type of message */    unsigned char   code;       /* type subcode */    unsigned short  cksum;      /* ones complement cksum of struct */    unsigned short unused1;     /* Is alway zero */    unsigned short unused2;     /* Is alway zero */};/* ICMP types */#define ICMP_ECHOREPLY          0#define ICMP_DESTUNREACHABLE    3#define ICMP_SOURCEQUENCH       4#define ICMP_REDIRECT           5#define ICMP_ECHOREQUEST        8#define ICMP_TIMEEXCEEDED       11#define ICMP_PARAMPROBLEM       12#define ICMP_TIMEREQUEST        13#define ICMP_TIMEREPLY          14#define ICMP_INFOREQUEST        15#define ICMP_INFOREPLY          16#define ICMP_ADDRMASKREQUEST    17#define ICMP_ADDRMASKREPLY      18/* A few unreachable codes. */#define ICMP_UNREACHABLE_PROTOCOL           2#define ICMP_UNREACHABLE_PORT               3#define ICMP_DEST_UNREACHABLE_MAX_CODE      12/************************************************************************ * * UDP stuff... * *//* UDP protocol header. */struct Udphdr {    unsigned short  uh_sport;       /* source port */    unsigned short  uh_dport;       /* destination port */    unsigned short  uh_ulen;        /* udp length */    unsigned short  uh_sum;         /* udp checksum */};#define UDPSIZE sizeof(struct Udphdr)/* UDP pseudo header. */struct UdpPseudohdr {    struct in_addr ip_src;      /* source address */    struct in_addr ip_dst;      /* dest address */    unsigned char   zero;       /* fixed to zero */    unsigned char   proto;      /* protocol */    unsigned short  ulen;       /* udp length */};#define UDP_OPEN    2#define UDP_DATA    3#define UDP_ACK     4#define UDP_TTL     0x3c/************************************************************************ * * TFTP stuff... * *//* TFTP state values: */#define TFTPOFF         0#define TFTPIDLE        1#define TFTPACTIVE      2#define TFTPERROR       3#define TFTPSENTRRQ     4#define TFTPTIMEOUT     5/* TFTP opcode superset (see Stevens pg 466) */#define TFTP_RRQ        1#define TFTP_WRQ        2#define TFTP_DAT        3#define TFTP_ACK        4#define TFTP_ERR        5#define TFTP_OACK       6   /* RFC2347: Option Acknowledgement opcode. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -