diff --git a/Userland/Libraries/LibC/serenity.cpp b/Userland/Libraries/LibC/serenity.cpp index 1cf5f5f68f..f3a0517e94 100644 --- a/Userland/Libraries/LibC/serenity.cpp +++ b/Userland/Libraries/LibC/serenity.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -149,4 +150,19 @@ int getkeymap(char* name_buffer, size_t name_buffer_size, u32* map, u32* shift_m int rc = syscall(SC_getkeymap, ¶ms); __RETURN_WITH_ERRNO(rc, rc, -1); } + +u16 internet_checksum(const void* ptr, size_t count) +{ + u32 checksum = 0; + auto* w = (const u16*)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); +} } diff --git a/Userland/Libraries/LibC/serenity.h b/Userland/Libraries/LibC/serenity.h index ecadd164e3..8a7f632a0b 100644 --- a/Userland/Libraries/LibC/serenity.h +++ b/Userland/Libraries/LibC/serenity.h @@ -109,4 +109,6 @@ int serenity_readlink(const char* path, size_t path_length, char* buffer, size_t int getkeymap(char* name_buffer, size_t name_buffer_size, uint32_t* map, uint32_t* shift_map, uint32_t* alt_map, uint32_t* altgr_map, uint32_t* shift_altgr_map); int setkeymap(const char* name, const uint32_t* map, uint32_t* const shift_map, const uint32_t* alt_map, const uint32_t* altgr_map, const uint32_t* shift_altgr_map); +uint16_t internet_checksum(const void* ptr, size_t count); + __END_DECLS 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 #include #include +#include #include #include #include @@ -37,21 +38,6 @@ #include #include -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;