+ default:
+ ifdebug(TRAFFIC) logger(LOG_ERR,
+ _ ("Unknown address family %d while reading packet from %s %s"),
+ ntohl(type), device_info, device);
+ return false;
+ }
+
+ packet->len = lenin + 10;
+
+ device_total_in += packet->len;
+
+ ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Read packet of %d bytes from %s"), packet->len,
+ device_info);
+
+ return true;
+}
+
+bool write_packet(vpn_packet_t *packet)
+{
+ u_int32_t type;
+ struct iovec vector[2];
+ int af;
+
+ cp();
+
+ ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
+ packet->len, device_info);
+
+ af = (packet->data[12] << 8) + packet->data[13];
+
+ switch (af) {
+ case 0x800:
+ type = htonl(AF_INET);
+ break;
+ case 0x86DD:
+ type = htonl(AF_INET6);
+ break;
+ default:
+ ifdebug(TRAFFIC) logger(LOG_ERR,
+ _("Unknown address family %d while writing packet to %s %s"),
+ af, device_info, device);
+ return false;
+ }
+
+ vector[0].iov_base = &type;
+ vector[0].iov_len = sizeof(type);
+ vector[1].iov_base = packet->data + 14;
+ vector[1].iov_len = packet->len - 14;
+
+ if(writev(device_fd, vector, 2) < 0) {
+ logger(LOG_ERR, _("Can't write to %s %s: %s"), device_info, device,
+ strerror(errno));
+ return false;
+ }
+
+ device_total_out += packet->len;
+
+ return true;
+}
+
+void dump_device_stats(void)
+{
+ cp();