Skip to content
This repository
Browse code

OSX requires a byteswap and Illumos another typo.

  • Loading branch information...
commit 41b4716bdcc8dc5d55c7faac1510d02d67be7c19 1 parent 0324be0
authored
2  interface/TUNMessageType_Illumos.c
@@ -23,7 +23,7 @@
23 23
  * through TUN devices and it detects it by reading the version byte.
24 24
  */
25 25
 
26  
-static inline ethertypeForPacketType(uint8_t highByte)
  26
+static inline uint16_t ethertypeForPacketType(uint8_t highByte)
27 27
 {
28 28
     return ((highByte >> 4) == 6) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4;
29 29
 }
11  interface/TUNMessageType_OSX.c
@@ -19,6 +19,9 @@
19 19
 #include <stdint.h>
20 20
 #include <netinet/in.h>
21 21
 
  22
+#define AF_INET6_BE Endian_hostToBigEndian16(AF_INET6)
  23
+#define AF_INET_BE Endian_hostToBigEndian16(AF_INET)
  24
+
22 25
 /**
23 26
  * OSX is broken and expects you to send the platform dependent
24 27
  * address family type rather than the ethertype.
@@ -26,17 +29,17 @@
26 29
 
27 30
 void TUNMessageType_push(struct Message* message, uint16_t ethertype)
28 31
 {
29  
-    uint16_t afType = (ethertype == Ethernet_TYPE_IP6) ? AF_INET6 : AF_INET;
  32
+    uint16_t afType_be = (ethertype == Ethernet_TYPE_IP6) ? AF_INET6_BE : AF_INET_BE;
30 33
 
31 34
     Message_shift(message, 4);
32 35
     ((uint16_t*) message->bytes)[0] = 0;
33  
-    ((uint16_t*) message->bytes)[1] = afType;
  36
+    ((uint16_t*) message->bytes)[1] = afType_be;
34 37
 }
35 38
 
36 39
 uint16_t TUNMessageType_pop(struct Message* message)
37 40
 {
38 41
     Message_shift(message, -4);
39  
-    uint16_t afType = ((uint16_t*) message->bytes)[-1];
  42
+    uint16_t afType_be = ((uint16_t*) message->bytes)[-1];
40 43
 
41  
-    return (afType == AF_INET6) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4;
  44
+    return (afType_be == AF_INET6_BE) ? Ethernet_TYPE_IP6 : Ethernet_TYPE_IP4;
42 45
 }

0 notes on commit 41b4716

Please sign in to comment.
Something went wrong with that request. Please try again.