- u_int32_t type = htonl(AF_INET);
- struct iovec vector[2];
-cp
- if(debug_lvl >= DEBUG_TRAFFIC)
- syslog(LOG_DEBUG, _("Writing packet of %d bytes to %s"),
- packet->len, device_info);
-
- 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)
- {
- syslog(LOG_ERR, _("Can't write to %s %s: %m"), device_info, device);
- return -1;
- }
-
- device_total_out += packet->len;
-cp
+ 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;