Commit Graph

32 Commits

Author SHA1 Message Date
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Optimoos
4ed7456486 Ping: Add TTL config option and value to output
This change adds the TTL value of the inbound packet to the output of
the userland ping program, bringing it more in line with other common
ping utilities. It also adds the (optional) -t option to configure the
TTL of the outgoing packet if desired.
2023-06-22 00:14:56 +02:00
Tim Ledbetter
d89e23d63e ping: Don't call exit() from within closing_statistics()
This improves readability slightly, as it isn't immediately obvious
that calling this function terminates the program.
2023-06-19 06:15:40 +02:00
Tim Ledbetter
e74324ad34 ping: Don't wait before displaying closing statistics
Previously, we would wait for the ping interval after the last ping
before displaying the closing statistics. We now display the closing
statistics and exit as soon as the required number of pings has been
performed.
2023-06-19 06:15:40 +02:00
Tim Ledbetter
834dc3747c ping: Avoid overflow for large interval values
Previously `usleep()` was being used, which takes a 32-bit integer
number of microseconds as a parameter. This caused an overflow for
intervals larger than 4294 seconds. We now use `clock_nanosleep()`
instead and ensure the user cannot specify a value larger than
`UINT32_MAX` seconds.
2023-06-19 06:15:40 +02:00
Tim Ledbetter
58e75be199 ping: Add -i option to specify the time to wait between packets 2023-05-16 12:56:11 +02:00
Tim Ledbetter
755bd4d3c2 ping: Add -q option to specify quiet mode
Quiet mode suppresses all output except the statistics shown before
the program exits.
2023-05-16 12:56:11 +02:00
Ali Mohammad Pur
500044906d LibCore+Everywhere: Remove ArgsParser::add*(char const*&)
This is not guaranteed to always work correctly as ArgsParser deals in
StringViews and might have a non-properly-null-terminated string as a
value. As a bonus, using StringView (and DeprecatedString where
necessary) leads to nicer looking code too :^)
2023-03-01 10:47:19 +01:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Brian Gianforcaro
fbceebb717 ping: Utilize TRY + Core::System wrappers 2022-03-22 11:39:20 +01:00
brapru
4cbce0e34c ping: Fix broken count argument error
By storing count as an Optional<size_t>, we can leverage count's empty
state to proceed with pinging indefinitely, and ensure a proper value is
passed when count does have a value.

This returns pings expected behavior to send infinite packets when a
count is not specified, stop after sending a specified count, and
disallow any count < 1.

Closes #12524
2022-02-17 09:08:40 -05:00
brapru
75a3be852d ping: Count argument must be greater than zero
Previously, when passing 0 as a count number to the ping utility it
would ping the specified host indefinitely. This is obviously not the
intended behavior, so forcing the count to be in the range of 1 <= value
<= UINT32_MAX resolves the issue.
2022-02-14 12:48:43 +01:00
brapru
ef3605604e ping: Fix off by one error in count argument
Previously, the count and total_pings comparison was evaluated after a
ping was sent for that iteration. This would cause one extra ping to be
sent greater than the specific count passed.
2022-02-14 12:48:43 +01:00
brapru
2af9a8e862 ping: Port to LibMain 2022-01-27 12:56:07 +01:00
Sam Atkins
45cf40653a Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOr
Apologies for the enormous commit, but I don't see a way to split this
up nicely. In the vast majority of cases it's a simple change. A few
extra places can use TRY instead of manual error checking though. :^)
2022-01-24 22:36:09 +01:00
dayarthvader
67b7bbe1f6 ping: Handle optional field in the IPv4 header 2022-01-22 22:11:21 +00:00
Nico Weber
f46a40a471 Utilities: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Ali Mohammad Pur
97e97bccab Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safe 2021-09-06 01:53:26 +02:00
Thomas Wagenveld
4181c0330c Ping: Add -s argument to specify the payload size of the ping
Change the static buffers to ByteBuffers to deal with the dynamic
size of the incoming and outgoing packets. Use sizeof(struct ip) rather
than the magic number '20' for the IPv4 header size.
Report the size of the reply packet to the console.
2021-08-03 09:06:11 +02:00
brapru
3013ca5fd0 Utilities: Add count option for ping 2021-07-25 00:32:32 +02:00
Linus Groh
f5c35fccca Userland: Replace most printf-style APIs with AK::Format APIs :^) 2021-06-01 21:30:16 +01:00
Jean-Baptiste Boric
3038edab00 Utilities: Correct non-standard assert macros includes 2021-05-17 18:14:05 +01:00
Jean-Baptiste Boric
e16894af5a LibC: Do not include errno.h inside unistd.h
POSIX does not mandate this, therefore let's not do it.
2021-05-14 22:24:02 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
SPDX License Identifiers are a more compact / standardized
way of representing file license information.

See: https://spdx.dev/resources/use/#identifiers

This was done with the `ambr` search and replace tool.

 ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-22 11:22:27 +02:00
Idan Horowitz
aa6547492e 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.
2021-03-31 23:42:24 +02:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Linus Groh
1fd349b8c2 Userland: Use INET_ADDRSTRLEN for inet_ntop() buffers
There's no point in using different, seemingly randomly sized buffers as
the required size for storing an IPv4 address representation is well
known (16 bytes).
2021-02-09 22:58:19 +01:00
Linus Groh
22c6783db2 ping: Replace two magic numbers with ICMP_* macros 2021-02-08 20:00:08 +01:00
Andreas Kling
2cd07c6212 Kernel+Userland: Remove "dns" pledge promise alias
This was just an alias for "unix" that I added early on back when there
was some belief that we might be compatible with OpenBSD. We're clearly
never going to be compatible with their pledges so just drop the alias.
2021-01-22 19:39:44 +01:00
Andreas Kling
ececac65c2 Userland: Move command-line utilities to Userland/Utilities/ 2021-01-12 12:04:09 +01:00