struct icmp_packet
{
uint8_t type;
+
uint8_t code;
+
uint16_t checksum;
+
uint32_t reserved;
};
uint32_t length;
};
+/**
+ * Socket we use to receive "fake" ICMP replies.
+ */
static SOCKET icmpsock;
+/**
+ * Socket we use to send our ICMP requests.
+ */
static SOCKET rawsock;
+/**
+ * Target "dummy" address.
+ */
static struct in_addr dummy;
+
/**
* CRC-16 for IP/ICMP headers.
+ *
+ * @param data what to calculate the CRC over
+ * @param bytes number of bytes in data (must be multiple of 2)
+ * @return the CRC 16.
*/
static uint16_t
calc_checksum(const uint16_t *data,
return sum;
}
+
/**
* Convert IPv4 address from text to binary form.
*
* @param af address family
* @param cp the address to print
* @param buf where to write the address result
+ * @return 1 on success
*/
static int
inet_pton (int af,
}
+/**
+ * We've received an ICMP response. Process it.
+ */
static void
process_icmp_response ()
{
}
+/**
+ * Create an ICMP raw socket for reading.
+ */
static SOCKET
make_icmp_socket ()
{
}
+/**
+ * Create an ICMP raw socket for writing.
+ */
static SOCKET
make_raw_socket ()
{
process_icmp_response ();
send_icmp_echo (&external);
}
+ /* select failed (internal error or OS out of resources) */
closesocket(icmpsock);
closesocket(rawsock);
WSACleanup ();
- return 4; /* select failed! */
+ return 4;
}