diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-03-30 21:18:28 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-03-31 23:42:24 +0200 |
commit | aa6547492e62802a7782bc12545fa7cc26331218 (patch) | |
tree | 9accdff8e9555306783b7f968417342d0248e1aa /Userland/Utilities/ping.cpp | |
parent | ea34ba6fa6a66b53436edefb9c80327660b310f7 (diff) | |
download | serenity-aa6547492e62802a7782bc12545fa7cc26331218.zip |
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.
Diffstat (limited to 'Userland/Utilities/ping.cpp')
-rw-r--r-- | Userland/Utilities/ping.cpp | 16 |
1 files changed, 1 insertions, 15 deletions
diff --git a/Userland/Utilities/ping.cpp b/Userland/Utilities/ping.cpp index 977b97c929..c0253ba2ec 100644 --- a/Userland/Utilities/ping.cpp +++ b/Userland/Utilities/ping.cpp @@ -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; |