mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:07:45 +00:00
LibC+ping: Move internet_checksum to serenity header
This will be useful for traceroute and any other packet related application, so this will reduce code duplication.
This commit is contained in:
parent
ea34ba6fa6
commit
aa6547492e
3 changed files with 19 additions and 15 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <serenity.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
@ -37,21 +38,6 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static uint16_t internet_checksum(const void* ptr, size_t count)
|
||||
{
|
||||
uint32_t checksum = 0;
|
||||
auto* w = (const uint16_t*)ptr;
|
||||
while (count > 1) {
|
||||
checksum += ntohs(*w++);
|
||||
if (checksum & 0x80000000)
|
||||
checksum = (checksum & 0xffff) | (checksum >> 16);
|
||||
count -= 2;
|
||||
}
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum & 0xffff) + (checksum >> 16);
|
||||
return htons(~checksum);
|
||||
}
|
||||
|
||||
static int total_pings;
|
||||
static int successful_pings;
|
||||
static uint32_t total_ms;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue