Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #28 from ghazel/master

PACKED_ATTRIBUTE to work around GCC accepting but not supporting pragma pack
  • Loading branch information...
commit 286cbe512af6280ca6dde4715359245eb497e9a1 2 parents 4be31bb + 512074b
Greg Hazel ghazel authored
Showing with 17 additions and 9 deletions.
  1. +9 −1 templates.h
  2. +8 −8 utp.cpp
10 templates.h
View
@@ -19,6 +19,14 @@
#endif
#endif
+#ifdef __GNUC__
+// Used for gcc tool chains accepting but not supporting pragma pack
+// See http://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
+#define PACKED_ATTRIBUTE __attribute__((__packed__))
+#else
+#define PACKED_ATTRIBUTE
+#endif
+
// Utility templates
#undef min
#undef max
@@ -48,7 +56,7 @@ namespace aux
}
template <class T>
-struct big_endian
+struct PACKED_ATTRIBUTE big_endian
{
T operator=(T i) { m_integer = aux::host_to_network(i); return i; }
operator T() const { return aux::network_to_host(m_integer); }
16 utp.cpp
View
@@ -94,7 +94,7 @@ char addrbuf2[65];
#pragma pack(push,1)
-struct PackedSockAddr {
+struct PACKED_ATTRIBUTE PackedSockAddr {
// The values are always stored here in network byte order
union {
@@ -192,7 +192,7 @@ struct PackedSockAddr {
}
};
-struct RST_Info {
+struct PACKED_ATTRIBUTE RST_Info {
PackedSockAddr addr;
uint32 connid;
uint32 timestamp;
@@ -211,7 +211,7 @@ struct RST_Info {
#define PACKET_SIZE_BIG 1400
#define PACKET_SIZE_HUGE_BUCKET 4
-struct PacketFormat {
+struct PACKED_ATTRIBUTE PacketFormat {
// connection ID
uint32_big connid;
uint32_big tv_sec;
@@ -229,21 +229,21 @@ struct PacketFormat {
uint16_big ack_nr;
};
-struct PacketFormatAck {
+struct PACKED_ATTRIBUTE PacketFormatAck {
PacketFormat pf;
byte ext_next;
byte ext_len;
byte acks[4];
};
-struct PacketFormatExtensions {
+struct PACKED_ATTRIBUTE PacketFormatExtensions {
PacketFormat pf;
byte ext_next;
byte ext_len;
byte extensions[8];
};
-struct PacketFormatV1 {
+struct PACKED_ATTRIBUTE PacketFormatV1 {
// packet_type (4 high bits)
// protocol version (4 low bits)
byte ver_type;
@@ -266,14 +266,14 @@ struct PacketFormatV1 {
uint16_big ack_nr;
};
-struct PacketFormatAckV1 {
+struct PACKED_ATTRIBUTE PacketFormatAckV1 {
PacketFormatV1 pf;
byte ext_next;
byte ext_len;
byte acks[4];
};
-struct PacketFormatExtensionsV1 {
+struct PACKED_ATTRIBUTE PacketFormatExtensionsV1 {
PacketFormatV1 pf;
byte ext_next;
byte ext_len;
Please sign in to comment.
Something went wrong with that request. Please try again.