Skip to content

Commit

Permalink
The "__attribute__((packed))" tag on structures causes some files not to
Browse files Browse the repository at this point in the history
compile with Sun C, as "interface.h" isn't being included before the
structures are being declared.

Furthermore, in the files that Sun C *can* compile, it doesn't cause Sun
C to generate code that's safe with unaligned accesses, as
"__attribute__" is defined as a do-nothing macro with compilers that
don't support it.

Therefore, we get rid of that tag on the structures to which it was
added, and instead use "EXTRACT_16BIT()" and "EXTRACT_32BIT()" to fetch
16-bit and 32-bit big-endian quantities from packets.  We also fix some
other references to multi-byte quantities to get rid of code that tries
to do unaligned loads on platforms that don't support them.

We also throw in a hack that makes those macros use
"__attribute__((packed))" on structures containing only one 16-bit or
32-bit integer to get the compiler to generate unaligned-safe code
rather than doing it by hand.  (GCC on SPARC produces the same code that
doing it by hand does; I don't know if GCC on any other big-endian
strict-alignment processor generates better code for that case.  On
little-endian processors, as "ntohs()" and "ntohl()" might be functions,
that might actually produce worse code.)

Fix some places to use "%u" rather than "%d" to print unsigned
quantities.
  • Loading branch information
yuguy committed Dec 11, 2002
1 parent 3a4254f commit fcc82f4
Show file tree
Hide file tree
Showing 81 changed files with 1,025 additions and 932 deletions.
4 changes: 2 additions & 2 deletions ah.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct ah {
u_int16_t ah_reserve; /* Reserved for future use */
u_int32_t ah_spi; /* Security parameter index */
/* variable size, 32bit bound*/ /* Authentication data */
} __attribute__((packed));
};

struct newah {
u_int8_t ah_nxt; /* Next Header */
Expand All @@ -52,6 +52,6 @@ struct newah {
u_int32_t ah_spi; /* Security parameter index */
u_int32_t ah_seq; /* Sequence number field */
/* variable size, 32bit bound*/ /* Authentication data */
} __attribute__((packed));
};

#endif /*_NETINET6_AH_H_*/
18 changes: 9 additions & 9 deletions appletalk.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
*
* AppleTalk protocol formats (courtesy Bill Croft of Stanford/SUMEX).
*
* @(#) $Header: /tcpdump/master/tcpdump/appletalk.h,v 1.14 2002-11-09 17:19:17 itojun Exp $ (LBL)
* @(#) $Header: /tcpdump/master/tcpdump/appletalk.h,v 1.15 2002-12-11 07:13:49 guy Exp $ (LBL)
*/

struct LAP {
u_int8_t dst;
u_int8_t src;
u_int8_t type;
} __attribute__((packed));
};
#define lapShortDDP 1 /* short DDP type */
#define lapDDP 2 /* DDP type */
#define lapKLAP 'K' /* Kinetics KLAP type */
Expand All @@ -44,14 +44,14 @@ struct atDDP {
u_int8_t dstSkt;
u_int8_t srcSkt;
u_int8_t type;
} __attribute__((packed));
};

struct atShortDDP {
u_int16_t length;
u_int8_t dstSkt;
u_int8_t srcSkt;
u_int8_t type;
} __attribute__((packed));
};

#define ddpMaxWKS 0x7F
#define ddpMaxData 586
Expand All @@ -77,7 +77,7 @@ struct atATP {
u_int8_t bitmap;
u_int16_t transID;
int32_t userData;
} __attribute__((packed));
};

#define atpReqCode 0x40
#define atpRspCode 0x80
Expand All @@ -96,7 +96,7 @@ struct atATP {
struct atEcho {
u_int8_t echoFunction;
u_int8_t *echoData;
} __attribute__((packed));
};

#define echoSkt 4 /* the echoer socket */
#define echoSize 1 /* size of echo header */
Expand All @@ -109,14 +109,14 @@ struct atEcho {
struct atNBP {
u_int8_t control;
u_int8_t id;
} __attribute__((packed));
};

struct atNBPtuple {
u_int16_t net;
u_int8_t node;
u_int8_t skt;
u_int8_t enumerator;
} __attribute__((packed));
};

#define nbpBrRq 0x10
#define nbpLkUp 0x20
Expand All @@ -143,7 +143,7 @@ struct atNBPtuple {
struct zipHeader {
u_int8_t command;
u_int8_t netcount;
} __attribute__((packed));
};

#define zipHeaderSize 2
#define zipQuery 1
Expand Down
4 changes: 2 additions & 2 deletions arcnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#) $Id: arcnet.h,v 1.1 2001-04-17 08:39:18 guy Exp $ (LBL)
* @(#) $Id: arcnet.h,v 1.2 2002-12-11 07:13:50 guy Exp $ (LBL)
*
* from: NetBSD: if_arc.h,v 1.13 1999/11/19 20:41:19 thorpej Exp
*/
Expand All @@ -56,7 +56,7 @@ struct arc_header {
u_int8_t arc_type2; /* same as arc_type */
u_int8_t arc_flag2; /* real flag value */
u_int16_t arc_seqid2; /* real seqid value */
} __attribute__((__packed__));
};

#define ARC_HDRLEN 3
#define ARC_HDRNEWLEN 6
Expand Down
6 changes: 3 additions & 3 deletions bootp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.12 2002-11-09 17:19:17 itojun Exp $ (LBL) */
/* @(#) $Header: /tcpdump/master/tcpdump/bootp.h,v 1.13 2002-12-11 07:13:50 guy Exp $ (LBL) */
/*
* Bootstrap Protocol (BOOTP). RFC951 and RFC1048.
*
Expand Down Expand Up @@ -36,7 +36,7 @@ struct bootp {
u_int8_t bp_sname[64]; /* server host name */
u_int8_t bp_file[128]; /* boot file name */
u_int8_t bp_vend[64]; /* vendor-specific area */
} __attribute__((packed));
};

/*
* UDP port numbers, server and client.
Expand Down Expand Up @@ -214,7 +214,7 @@ struct cmu_vend {
struct in_addr v_ins1, v_ins2; /* IEN-116 name servers */
struct in_addr v_ts1, v_ts2; /* Time servers */
u_int8_t v_unused[24]; /* currently unused */
} __attribute__((packed));
};


/* v_flags values */
Expand Down
54 changes: 27 additions & 27 deletions decnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/tcpdump/decnet.h,v 1.10 2002-11-09 17:19:17 itojun Exp $ (LBL)
* @(#) $Header: /tcpdump/master/tcpdump/decnet.h,v 1.11 2002-12-11 07:13:50 guy Exp $ (LBL)
*/

#ifndef WIN32
Expand All @@ -42,7 +42,7 @@ union etheraddress {
u_int8_t dne_hiord[4]; /* DECnet HIORD prefix */
u_int8_t dne_nodeaddr[2]; /* DECnet node address */
} dne_remote;
} __attribute__((packed));
};

typedef union etheraddress etheraddr; /* Ethernet address */

Expand All @@ -56,7 +56,7 @@ typedef union etheraddress etheraddr; /* Ethernet address */
struct dn_naddr {
u_int16_t a_len; /* length of address */
u_int8_t a_addr[DN_MAXADDL]; /* address as bytes */
} __attribute__((packed));
};

/*
* Define long and short header formats.
Expand All @@ -67,7 +67,7 @@ struct shorthdr
word sh_dst; /* destination node address */
word sh_src; /* source node address */
byte sh_visits; /* visit count */
} __attribute__((packed));
};

struct longhdr
{
Expand All @@ -82,13 +82,13 @@ struct longhdr
byte lg_visits; /* visit count */
byte lg_service; /* service class (reserved) */
byte lg_pt; /* protocol type (reserved) */
} __attribute__((packed));
};

union routehdr
{
struct shorthdr rh_short; /* short route header */
struct longhdr rh_long; /* long route header */
} __attribute__((packed));
};

/*
* Define the values of various fields in the protocol messages.
Expand Down Expand Up @@ -160,7 +160,7 @@ struct initmsgIII /* phase III initialization message */
byte inIII_eco; /* ECO number */
byte inIII_ueco; /* user ECO number */
byte inIII_rsvd; /* reserved image field */
} __attribute__((packed));
};

struct initmsg /* initialization message */
{
Expand All @@ -173,35 +173,35 @@ struct initmsg /* initialization message */
byte in_ueco; /* user ECO number */
word in_hello; /* hello timer */
byte in_rsvd; /* reserved image field */
} __attribute__((packed));
};

struct verifmsg /* verification message */
{
byte ve_flags; /* route flags */
word ve_src; /* source node address */
byte ve_fcnval; /* function value image field */
} __attribute__((packed));
};

struct testmsg /* hello and test message */
{
byte te_flags; /* route flags */
word te_src; /* source node address */
byte te_data; /* test data image field */
} __attribute__((packed));
};

struct l1rout /* level 1 routing message */
{
byte r1_flags; /* route flags */
word r1_src; /* source node address */
byte r1_rsvd; /* reserved field */
} __attribute__((packed));
};

struct l2rout /* level 2 routing message */
{
byte r2_flags; /* route flags */
word r2_src; /* source node address */
byte r2_rsvd; /* reserved field */
} __attribute__((packed));
};

struct rhellomsg /* router hello message */
{
Expand All @@ -216,7 +216,7 @@ struct rhellomsg /* router hello message */
byte rh_area; /* reserved */
word rh_hello; /* hello timer */
byte rh_mpd; /* reserved */
} __attribute__((packed));
};

struct ehellomsg /* endnode hello message */
{
Expand All @@ -233,7 +233,7 @@ struct ehellomsg /* endnode hello message */
word eh_hello; /* hello timer */
byte eh_mpd; /* (reserved) */
byte eh_data; /* test data image field */
} __attribute__((packed));
};

union controlmsg
{
Expand All @@ -244,7 +244,7 @@ union controlmsg
struct l2rout cm_l2rout; /* level 2 routing message */
struct rhellomsg cm_rhello; /* router hello message */
struct ehellomsg cm_ehello; /* endnode hello message */
} __attribute__((packed));
};

/* Macros for decoding routing-info fields */
#define RI_COST(x) ((x)&0777)
Expand Down Expand Up @@ -366,51 +366,51 @@ struct nsphdr /* general nsp header */
byte nh_flags; /* message flags */
word nh_dst; /* destination link address */
word nh_src; /* source link address */
} __attribute__((packed));
};

struct seghdr /* data segment header */
{
byte sh_flags; /* message flags */
word sh_dst; /* destination link address */
word sh_src; /* source link address */
word sh_seq[3]; /* sequence numbers */
} __attribute__((packed));
};

struct minseghdr /* minimum data segment header */
{
byte ms_flags; /* message flags */
word ms_dst; /* destination link address */
word ms_src; /* source link address */
word ms_seq; /* sequence number */
} __attribute__((packed));
};

struct lsmsg /* link service message (after hdr) */
{
byte ls_lsflags; /* link service flags */
byte ls_fcval; /* flow control value */
} __attribute__((packed));
};

struct ackmsg /* acknowledgement message */
{
byte ak_flags; /* message flags */
word ak_dst; /* destination link address */
word ak_src; /* source link address */
word ak_acknum[2]; /* acknowledgement numbers */
} __attribute__((packed));
};

struct minackmsg /* minimum acknowledgement message */
{
byte mk_flags; /* message flags */
word mk_dst; /* destination link address */
word mk_src; /* source link address */
word mk_acknum; /* acknowledgement number */
} __attribute__((packed));
};

struct ciackmsg /* connect acknowledgement message */
{
byte ck_flags; /* message flags */
word ck_dst; /* destination link address */
} __attribute__((packed));
};

struct cimsg /* connect initiate message */
{
Expand All @@ -420,7 +420,7 @@ struct cimsg /* connect initiate message */
byte ci_services; /* requested services */
byte ci_info; /* information */
word ci_segsize; /* maximum segment size */
} __attribute__((packed));
};

struct ccmsg /* connect confirm message */
{
Expand All @@ -431,7 +431,7 @@ struct ccmsg /* connect confirm message */
byte cc_info; /* information */
word cc_segsize; /* maximum segment size */
byte cc_optlen; /* optional data length */
} __attribute__((packed));
};

struct cnmsg /* generic connect message */
{
Expand All @@ -441,7 +441,7 @@ struct cnmsg /* generic connect message */
byte cn_services; /* requested services */
byte cn_info; /* information */
word cn_segsize; /* maximum segment size */
} __attribute__((packed));
};

struct dimsg /* disconnect initiate message */
{
Expand All @@ -450,12 +450,12 @@ struct dimsg /* disconnect initiate message */
word di_src; /* source link address */
word di_reason; /* reason code */
byte di_optlen; /* optional data length */
} __attribute__((packed));
};

struct dcmsg /* disconnect confirm message */
{
byte dc_flags; /* message flags */
word dc_dst; /* destination link address */
word dc_src; /* source link address */
word dc_reason; /* reason code */
} __attribute__((packed));
};
6 changes: 3 additions & 3 deletions esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct esp {
/*8bit*/ /* next header */
/*8bit*/ /* next header */
/*variable size, 32bit bound*/ /* Authentication data (new IPsec) */
} __attribute__((packed));
};

struct newesp {
u_int32_t esp_spi; /* ESP */
Expand All @@ -57,12 +57,12 @@ struct newesp {
/*8bit*/ /* next header */
/*8bit*/ /* next header */
/*variable size, 32bit bound*/ /* Authentication data */
} __attribute__((packed));
};

struct esptail {
u_int8_t esp_padlen; /* pad length */
u_int8_t esp_nxt; /* Next header */
/*variable size, 32bit bound*/ /* Authentication data (new IPsec)*/
} __attribute__((packed));
};

#endif /*_NETINET6_ESP_H_*/
Loading

0 comments on commit fcc82f4

Please sign in to comment.