- memcpy(&port,
- &buf[sizeof (struct ip_packet) *2 + sizeof (struct icmp_packet) * 2],
- sizeof(uint32_t));
- port = ntohs(port);
- DWORD ssize = sizeof(buf);
- WSAAddressToString((LPSOCKADDR)&sip,
- sizeof(sip),
- NULL,
- buf,
- &ssize);
- fprintf (stdout,
- "%s:%d\n",
- buf,
- port);
- }
- else if (ip_pkt.proto == IPPROTO_UDP)
- {
- memcpy(&udp_pkt,
- &buf[off],
- sizeof(udp_pkt));
- DWORD ssize = sizeof(buf);
- WSAAddressToString((LPSOCKADDR)&sip,
- sizeof(sip),
- NULL,
- buf,
- &ssize);
- fprintf (stdout,
- "%s:%d\n",
- buf,
- ntohs((uint16_t)udp_pkt.length));
+ case IPPROTO_ICMP:
+ if (have != (sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct icmp_echo_header)) )
+ {
+ /* malformed */
+ return;
+ }
+ /* grab ICMP ECHO content */
+ memcpy (&icmp_echo,
+ &buf[off],
+ sizeof (struct icmp_echo_header));
+ port = (uint16_t) ntohl (icmp_echo.reserved);
+ break;
+ case IPPROTO_UDP:
+ if (have != (sizeof (struct ip_header) * 2 +
+ sizeof (struct icmp_ttl_exceeded_header) +
+ sizeof (struct udp_header)) )
+ {
+ /* malformed */
+ return;
+ }
+ /* grab UDP content */
+ memcpy (&udp_pkt,
+ &buf[off],
+ sizeof (struct udp_header));
+ port = ntohs (udp_pkt.length);
+ break;
+ default:
+ /* different type than what we want */
+ return;