Permalink
Browse files

OSX requires a byteswap and Illumos another typo.

  • Loading branch information...
Caleb James DeLisle
Caleb James DeLisle committed Dec 10, 2012
1 parent 0324be0 commit 41b4716bdcc8dc5d55c7faac1510d02d67be7c19
Showing with 8 additions and 5 deletions.
  1. +1 −1 interface/TUNMessageType_Illumos.c
  2. +7 −4 interface/TUNMessageType_OSX.c
@@ -23,7 +23,7 @@
* through TUN devices and it detects it by reading the version byte.
*/
-static inline ethertypeForPacketType(uint8_t highByte)
+static inline uint16_t ethertypeForPacketType(uint8_t highByte)
{
return ((highByte >> 4) == 6) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4;
}
@@ -19,24 +19,27 @@
#include <stdint.h>
#include <netinet/in.h>
+#define AF_INET6_BE Endian_hostToBigEndian16(AF_INET6)
+#define AF_INET_BE Endian_hostToBigEndian16(AF_INET)
+
/**
* OSX is broken and expects you to send the platform dependent
* address family type rather than the ethertype.
*/
void TUNMessageType_push(struct Message* message, uint16_t ethertype)
{
- uint16_t afType = (ethertype == Ethernet_TYPE_IP6) ? AF_INET6 : AF_INET;
+ uint16_t afType_be = (ethertype == Ethernet_TYPE_IP6) ? AF_INET6_BE : AF_INET_BE;
Message_shift(message, 4);
((uint16_t*) message->bytes)[0] = 0;
- ((uint16_t*) message->bytes)[1] = afType;
+ ((uint16_t*) message->bytes)[1] = afType_be;
}
uint16_t TUNMessageType_pop(struct Message* message)
{
Message_shift(message, -4);
- uint16_t afType = ((uint16_t*) message->bytes)[-1];
+ uint16_t afType_be = ((uint16_t*) message->bytes)[-1];
- return (afType == AF_INET6) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4;
+ return (afType_be == AF_INET6_BE) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4;
}

0 comments on commit 41b4716

Please sign in to comment.