]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
Re-instantiated the pack directives. Nested structs do break individual field natural...
authorlikewise <likewise>
Thu, 6 May 2004 03:27:13 +0000 (03:27 +0000)
committerlikewise <likewise>
Thu, 6 May 2004 03:27:13 +0000 (03:27 +0000)
doc/sys_arch.txt
src/include/ipv4/lwip/icmp.h
src/include/ipv4/lwip/ip.h
src/include/ipv4/lwip/ip_addr.h
src/include/lwip/arch.h
src/include/lwip/dhcp.h
src/include/lwip/tcp.h
src/include/lwip/udp.h
src/include/netif/etharp.h
src/netif/ppp/vjbsdhdr.h

index 9f2a999a0d20c8ed950c900438f5dfe752fd572f..95d0add737a9c185549e5a9ed719cba88c99cd9e 100644 (file)
@@ -154,6 +154,12 @@ cc.h       - Architecture environment, some compiler specific, some
   Typedefs for the types used by lwip -
     u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t
 
+  Compiler hints for packing lwip's structures -
+    PACK_STRUCT_FIELD(x)
+    PACK_STRUCT_STRUCT
+    PACK_STRUCT_BEGIN
+    PACK_STRUCT_END
+
   Platform specific diagnostic output -
     LWIP_PLATFORM_DIAG(x)    - non-fatal, print a message.
     LWIP_PLATFORM_ASSERT(x)  - fatal, print message and abandon execution.
index 8063eac6253f5408e1e2a9fa5cc08fe22ad23637..634405b714f1f6465a4991386bf2344af12adddd 100644 (file)
@@ -71,24 +71,36 @@ void icmp_input(struct pbuf *p, struct netif *inp);
 void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
 void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
 
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 struct icmp_echo_hdr {
-  u16_t _type_code;
-  u16_t chksum;
-  u16_t id;
-  u16_t seqno;
-};
+  PACK_STRUCT_FIELD(u16_t _type_code);
+  PACK_STRUCT_FIELD(u16_t chksum);
+  PACK_STRUCT_FIELD(u16_t id);
+  PACK_STRUCT_FIELD(u16_t seqno);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
 
+PACK_STRUCT_BEGIN
 struct icmp_dur_hdr {
-  u16_t _type_code;
-  u16_t chksum;
-  u32_t unused;
-};
+  PACK_STRUCT_FIELD(u16_t _type_code);
+  PACK_STRUCT_FIELD(u16_t chksum);
+  PACK_STRUCT_FIELD(u32_t unused);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
 
+PACK_STRUCT_BEGIN
 struct icmp_te_hdr {
-  u16_t _type_code;
-  u16_t chksum;
-  u32_t unused;
-};
+  PACK_STRUCT_FIELD(u16_t _type_code);
+  PACK_STRUCT_FIELD(u16_t chksum);
+  PACK_STRUCT_FIELD(u32_t unused);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
 
 #define ICMPH_TYPE(hdr) (ntohs((hdr)->_type_code) >> 8)
 #define ICMPH_CODE(hdr) (ntohs((hdr)->_type_code) & 0xff)
index 58eab8abeb6fd77bb5d0897e7fa500e2ae838305..c8b9c22248ef74bd48f06ceba661e9b776cbe15b 100644 (file)
@@ -94,27 +94,37 @@ err_t ip_output_if(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest,
 #define        SOF_OOBINLINE   (u16_t)0x0100U          /* leave received OOB data in line */
 #define        SOF_REUSEPORT   (u16_t)0x0200U          /* allow local address & port reuse */
 
+
+
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 struct ip_hdr {
   /* version / header length / type of service */
-  u16_t _v_hl_tos;
+  PACK_STRUCT_FIELD(u16_t _v_hl_tos);
   /* total length */
-  u16_t _len;
+  PACK_STRUCT_FIELD(u16_t _len);
   /* identification */
-  u16_t _id;
+  PACK_STRUCT_FIELD(u16_t _id);
   /* fragment offset field */
-  u16_t _offset;
+  PACK_STRUCT_FIELD(u16_t _offset);
 #define IP_RF 0x8000        /* reserved fragment flag */
 #define IP_DF 0x4000        /* dont fragment flag */
 #define IP_MF 0x2000        /* more fragments flag */
 #define IP_OFFMASK 0x1fff   /* mask for fragmenting bits */
   /* time to live / protocol*/
-  u16_t _ttl_proto;
+  PACK_STRUCT_FIELD(u16_t _ttl_proto);
   /* checksum */
-  u16_t _chksum;
+  PACK_STRUCT_FIELD(u16_t _chksum);
   /* source and destination IP addresses */
-  struct ip_addr src;
-  struct ip_addr dest; 
-};
+  PACK_STRUCT_FIELD(struct ip_addr src);
+  PACK_STRUCT_FIELD(struct ip_addr dest); 
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
 
 #define IPH_V(hdr)  (ntohs((hdr)->_v_hl_tos) >> 12)
 #define IPH_HL(hdr) ((ntohs((hdr)->_v_hl_tos) >> 8) & 0x0f)
index e524c8db767a3acea6db72b313a799d8014e449c..7ac4954b33b1e708024b05499bfaab53121182f8 100644 (file)
 
 #include "lwip/arch.h"
 
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 struct ip_addr {
-  u32_t addr;
-};
-
+  PACK_STRUCT_FIELD(u32_t addr);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
+
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 struct ip_addr2 {
-  u16_t addrw[2];
-};
+  PACK_STRUCT_FIELD(u16_t addrw[2]);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
 
 /* For compatibility with BSD code */
 struct in_addr {
index b70a5fc4c7fdd0194c97e2e631d001d9da814ec7..e0d622a4b2b0442e57a174548c34d81c5ea5a63b 100644 (file)
 
 #include "arch/cc.h"
 
+#ifndef PACK_STRUCT_BEGIN
+#define PACK_STRUCT_BEGIN
+#endif /* PACK_STRUCT_BEGIN */
+
+#ifndef PACK_STRUCT_END
+#define PACK_STRUCT_END
+#endif /* PACK_STRUCT_END */
+
+#ifndef PACK_STRUCT_FIELD
+#define PACK_STRUCT_FIELD(x) x
+#endif /* PACK_STRUCT_FIELD */
+
+
+
 #ifdef LWIP_PROVIDE_ERRNO
 
 #define  EPERM     1  /* Operation not permitted */
index 0314171ad28536e1d3866920d286ad3d56b110d2..73a0bcbaf30e31205ead3bb6d76cd7db41f8c0a1 100644 (file)
@@ -55,35 +55,44 @@ struct dhcp
 #endif
 };
 
+/* MUST be compiled with "pack structs" or equivalent! */
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 /** minimum set of fields of any DHCP message */
 struct dhcp_msg
 {
-  u8_t op;
-  u8_t htype;
-  u8_t hlen;
-  u8_t hops;
-  u32_t xid;
-  u16_t secs;
-  u16_t flags;
-  struct ip_addr ciaddr;
-  struct ip_addr yiaddr;
-  struct ip_addr siaddr;
-  struct ip_addr giaddr;
+  PACK_STRUCT_FIELD(u8_t op);
+  PACK_STRUCT_FIELD(u8_t htype);
+  PACK_STRUCT_FIELD(u8_t hlen);
+  PACK_STRUCT_FIELD(u8_t hops);
+  PACK_STRUCT_FIELD(u32_t xid);
+  PACK_STRUCT_FIELD(u16_t secs);
+  PACK_STRUCT_FIELD(u16_t flags);
+  PACK_STRUCT_FIELD(struct ip_addr ciaddr);
+  PACK_STRUCT_FIELD(struct ip_addr yiaddr);
+  PACK_STRUCT_FIELD(struct ip_addr siaddr);
+  PACK_STRUCT_FIELD(struct ip_addr giaddr);
 #define DHCP_CHADDR_LEN 16U
-  u8_t chaddr[DHCP_CHADDR_LEN];
+  PACK_STRUCT_FIELD(u8_t chaddr[DHCP_CHADDR_LEN]);
 #define DHCP_SNAME_LEN 64U
-  u8_t sname[DHCP_SNAME_LEN];
+  PACK_STRUCT_FIELD(u8_t sname[DHCP_SNAME_LEN]);
 #define DHCP_FILE_LEN 128U
-  u8_t file[DHCP_FILE_LEN];
-  u32_t cookie;
+  PACK_STRUCT_FIELD(u8_t file[DHCP_FILE_LEN]);
+  PACK_STRUCT_FIELD(u32_t cookie);
 #define DHCP_MIN_OPTIONS_LEN 68U
 /** allow this to be configured in lwipopts.h, but not too small */
 #if ((!defined(DHCP_OPTIONS_LEN)) || (DHCP_OPTIONS_LEN < DHCP_MIN_OPTIONS_LEN))
 /** set this to be sufficient for your options in outgoing DHCP msgs */
 #  define DHCP_OPTIONS_LEN DHCP_MIN_OPTIONS_LEN
 #endif
-  u8_t options[DHCP_OPTIONS_LEN];
-};
+  PACK_STRUCT_FIELD(u8_t options[DHCP_OPTIONS_LEN]);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
 
 /** start DHCP configuration */
 err_t dhcp_start(struct netif *netif);
index 95d1febc37edfbb54651736a1b49dd327f973f52..d200e7c39f8dfde866d81f5636a26afaa2965475 100644 (file)
@@ -161,16 +161,25 @@ void             tcp_rexmit  (struct tcp_pcb *pcb);
 #define  TCP_KEEPCNT       9                             /* Counter for KEEPALIVE probes */
 #define  TCP_MAXIDLE       TCP_KEEPCNT * TCP_KEEPINTVL   /* Maximum KEEPALIVE probe time */
 
+
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 struct tcp_hdr {
-  u16_t src;
-  u16_t dest;
-  u32_t seqno;
-  u32_t ackno;
-  u16_t _hdrlen_rsvd_flags;
-  u16_t wnd;
-  u16_t chksum;
-  u16_t urgp;
-};
+  PACK_STRUCT_FIELD(u16_t src);
+  PACK_STRUCT_FIELD(u16_t dest);
+  PACK_STRUCT_FIELD(u32_t seqno);
+  PACK_STRUCT_FIELD(u32_t ackno);
+  PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
+  PACK_STRUCT_FIELD(u16_t wnd);
+  PACK_STRUCT_FIELD(u16_t chksum);
+  PACK_STRUCT_FIELD(u16_t urgp);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
 
 #define TCPH_OFFSET(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 8)
 #define TCPH_HDRLEN(phdr) (ntohs((phdr)->_hdrlen_rsvd_flags) >> 12)
index 94a7227f80dcd63da0a83c88faa8732e01c89a01..c54859476176a0e4b3687954caeac1cbc9397101 100644 (file)
 #define UDP_HLEN 8
 
 struct udp_hdr {
-  u16_t src;
-  u16_t dest;  /* src/dest UDP ports */
-  u16_t len;
-  u16_t chksum;
-};
+  PACK_STRUCT_FIELD(u16_t src);
+  PACK_STRUCT_FIELD(u16_t dest);  /* src/dest UDP ports */
+  PACK_STRUCT_FIELD(u16_t len);
+  PACK_STRUCT_FIELD(u16_t chksum);
+} PACK_STRUCT_STRUCT;
 
 #define UDP_FLAGS_NOCHKSUM 0x01U
 #define UDP_FLAGS_UDPLITE  0x02U
index 6142922d3728b29290324491eb88d55e3622db8d..4d6eefa012410b0564bc08e71b4467cc25cf682c 100644 (file)
 #include "lwip/netif.h"
 #include "lwip/ip.h"
 
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/bpstruct.h"
+#endif
+PACK_STRUCT_BEGIN
 struct eth_addr {
-  u8_t addr[6];
-};
+  PACK_STRUCT_FIELD(u8_t addr[6]);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
 
+PACK_STRUCT_BEGIN
 struct eth_hdr {
-  /* Ethernet header is 14 bytes, this breaks natural alignment on
-   * subsequent (TCP/IP) protocol header fields. */
 #if ETH_PAD_SIZE
-  u8_t padding[ETH_PAD_SIZE];
+  PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
 #endif
-  struct eth_addr dest;
-  struct eth_addr src;
-  u16_t type;
-};
+  PACK_STRUCT_FIELD(struct eth_addr dest);
+  PACK_STRUCT_FIELD(struct eth_addr src);
+  PACK_STRUCT_FIELD(u16_t type);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
 
+PACK_STRUCT_BEGIN
 /** the ARP message */
 struct etharp_hdr {
-  /* Ethernet header */
-  struct eth_hdr ethhdr;
-  u16_t hwtype;
-  u16_t proto;
-  u16_t _hwlen_protolen;
-  u16_t opcode;
-  struct eth_addr shwaddr;
-  /* assume 2-byte alignment */
-  struct ip_addr2 sipaddr;
-  struct eth_addr dhwaddr;
-  /* assume 2-byte alignment */
-  struct ip_addr2 dipaddr;
-};
+  PACK_STRUCT_FIELD(struct eth_hdr ethhdr);
+  PACK_STRUCT_FIELD(u16_t hwtype);
+  PACK_STRUCT_FIELD(u16_t proto);
+  PACK_STRUCT_FIELD(u16_t _hwlen_protolen);
+  PACK_STRUCT_FIELD(u16_t opcode);
+  PACK_STRUCT_FIELD(struct eth_addr shwaddr);
+  PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
+  PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
+  PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
+} PACK_STRUCT_STRUCT;
+PACK_STRUCT_END
 
+PACK_STRUCT_BEGIN
 struct ethip_hdr {
-  struct eth_hdr eth;
-  struct ip_hdr ip;
+  PACK_STRUCT_FIELD(struct eth_hdr eth);
+  PACK_STRUCT_FIELD(struct ip_hdr ip);
 };
+#ifdef PACK_STRUCT_USE_INCLUDES
+#  include "arch/epstruct.h"
+#endif
 
 #define ARP_TMR_INTERVAL 10000
 
index 8a5ecc3be09fe83da88dfd3c31daabb2dbb403c2..a089352ade270e0f6b7d7f427696b7fd97193eb3 100644 (file)
@@ -11,6 +11,7 @@
  * pragmatically since otherwise unsigned comparisons can result
  * against negative integers quite easily, and fail in subtle ways.
  */
+PACK_STRUCT_BEGIN
 struct ip
 {
 #if defined(NO_CHAR_BITFIELDS)
@@ -38,6 +39,7 @@ struct ip
        u_short ip_sum;                                 /* checksum */
        struct  in_addr ip_src,ip_dst;  /* source and dest address */
 };
+PACK_STRUCT_END
 
 typedef u32_t tcp_seq;
 
@@ -45,6 +47,7 @@ typedef u32_t tcp_seq;
  * TCP header.
  * Per RFC 793, September, 1981.
  */
+PACK_STRUCT_BEGIN
 struct tcphdr  
 {
        u_short th_sport;               /* source port */
@@ -68,5 +71,6 @@ struct tcphdr
        u_short th_sum;                 /* checksum */
        u_short th_urp;                 /* urgent pointer */
 };
+PACK_STRUCT_END
 
 #endif /* VJBSDHDR_H */