From: Tobias Brunner Date: Sun, 16 Jun 2013 18:05:08 +0000 (+0200) Subject: tun-device: Packets sent over utun devices on Mac OS X have the protocol family prepended X-Git-Tag: 5.1.0dr1~80^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66aaabf34238aa3ddcbb328b370e2d5abae566b4;p=thirdparty%2Fstrongswan.git tun-device: Packets sent over utun devices on Mac OS X have the protocol family prepended --- diff --git a/src/libstrongswan/networking/tun_device.c b/src/libstrongswan/networking/tun_device.c index 00de2eddf5..af7e57140f 100644 --- a/src/libstrongswan/networking/tun_device.c +++ b/src/libstrongswan/networking/tun_device.c @@ -225,6 +225,12 @@ METHOD(tun_device_t, write_packet, bool, { ssize_t s; +#ifdef __APPLE__ + /* UTUN's expect the packets to be prepended by a 32-bit protocol number + * instead of parsing the packet again, we assume IPv4 for now */ + u_int32_t proto = htonl(AF_INET); + packet = chunk_cata("cc", chunk_from_thing(proto), packet); +#endif s = write(this->tunfd, packet.ptr, packet.len); if (s < 0) { @@ -271,6 +277,11 @@ METHOD(tun_device_t, read_packet, bool, return FALSE; } packet->len = len; +#ifdef __APPLE__ + /* UTUN's prepend packets with a 32-bit protocol number */ + packet->len -= sizeof(u_int32_t); + memmove(packet->ptr, packet->ptr + sizeof(u_int32_t), packet->len); +#endif return TRUE; }