- ethernet = (const struct ethernet_header*)(packet);
- ip = (const struct ip_header*)(packet + size_ethernet);
- udp = (const struct udp_header*)(packet + size_ethernet + size_ip);
- payload = (const uint8_t *)(packet + size_ethernet + size_ip + size_udp);
-
- /* Read the RADIUS packet structure */
- request = init_packet(payload, header->len - size_ethernet - size_ip - size_udp);
- if (request == NULL) {
- librad_perror("check");
+
+ if ((data[0] == 2) && (data[1] == 0) &&
+ (data[2] == 0) && (data[3] == 0)) {
+ ip = (const struct ip_header*) (data + 4);
+
+ } else {
+ ethernet = (const struct ethernet_header*)(data);
+ ip = (const struct ip_header*)(data + size_ethernet);
+ }
+ udp = (const struct udp_header*)(((const uint8_t *) ip) + size_ip);
+ payload = (const uint8_t *)(((const uint8_t *) udp) + size_udp);
+
+ packet = malloc(sizeof(*packet));
+ if (!packet) {
+ fprintf(stderr, "Out of memory\n");
+ return;
+ }
+
+ memset(packet, 0, sizeof(*packet));
+ packet->src_ipaddr.af = AF_INET;
+ packet->src_ipaddr.ipaddr.ip4addr.s_addr = ip->ip_src.s_addr;
+ packet->src_port = ntohs(udp->udp_sport);
+ packet->dst_ipaddr.af = AF_INET;
+ packet->dst_ipaddr.ipaddr.ip4addr.s_addr = ip->ip_dst.s_addr;
+ packet->dst_port = ntohs(udp->udp_dport);
+
+ packet->data = payload;
+ packet->data_len = header->len - (payload - data);
+
+ if (!rad_packet_ok(packet, 0)) {
+ printf("Packet: %s\n", fr_strerror());
+
+ printf("\tFrom: %s:%d\n", inet_ntoa(ip->ip_src), ntohs(udp->udp_sport));
+ printf("\tTo: %s:%d\n", inet_ntoa(ip->ip_dst), ntohs(udp->udp_dport));
+ printf("\tType: %s\n", fr_packet_codes[packet->code]);
+
+ free(packet);