rewrite comments into one, unified style
This commit is contained in:
1 parent
6260de0085
commit
467a58c9c6
163 files changed
+3560
-2556
No files matched your search
@@ -1,3 +1,5 @@
|
||||
// User application entry points for ping.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
@@ -11,15 +13,18 @@
|
||||
#define PING_PAYLOAD_BYTES 32u
|
||||
#define PING_PACKET_BYTES (8u + PING_PAYLOAD_BYTES)
|
||||
|
||||
// Prints the requested operation.
|
||||
static void print(const char* s) {
|
||||
if (s) { SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromCstr(s) }; SysWriteConsole(&req); }
|
||||
}
|
||||
|
||||
// Prints char.
|
||||
static void print_char(char c) {
|
||||
SYS_WRITE_CONSOLE_REQUEST req = { SysSvFromParts(&c, 1) };
|
||||
SysWriteConsole(&req);
|
||||
}
|
||||
|
||||
// Prints u64.
|
||||
static void print_u64(uint64_t v) {
|
||||
char buf[32];
|
||||
int n = 0;
|
||||
@@ -31,11 +36,13 @@ static void print_u64(uint64_t v) {
|
||||
while (n > 0) print_char(buf[--n]);
|
||||
}
|
||||
|
||||
// Prints ipv4.
|
||||
static void print_ipv4(const uint8_t ip[4]) {
|
||||
print_u64(ip[0]); print("."); print_u64(ip[1]); print(".");
|
||||
print_u64(ip[2]); print("."); print_u64(ip[3]);
|
||||
}
|
||||
|
||||
// Prints rtt us.
|
||||
static void print_rtt_us(uint64_t us) {
|
||||
uint64_t whole = us / US_PER_MS;
|
||||
uint64_t frac = us % US_PER_MS;
|
||||
@@ -46,6 +53,7 @@ static void print_rtt_us(uint64_t us) {
|
||||
print_u64(frac);
|
||||
}
|
||||
|
||||
// Implements the format ipv4 operation.
|
||||
static void format_ipv4(char* out, size_t outSize, const uint8_t ip[4]) {
|
||||
if (!out || outSize == 0) return;
|
||||
size_t off = 0;
|
||||
@@ -62,6 +70,7 @@ static void format_ipv4(char* out, size_t outSize, const uint8_t ip[4]) {
|
||||
out[off < outSize ? off : outSize - 1] = 0;
|
||||
}
|
||||
|
||||
// Implements the next token operation.
|
||||
static const char* next_token(const char* s, char* out, size_t outSize) {
|
||||
if (!s || !out || outSize == 0) return NULL;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
@@ -76,6 +85,7 @@ static const char* next_token(const char* s, char* out, size_t outSize) {
|
||||
return s;
|
||||
}
|
||||
|
||||
// Parses u8.
|
||||
static bool parse_u8(const char** p, uint8_t* out) {
|
||||
const char* s = *p;
|
||||
uint32_t v = 0;
|
||||
@@ -92,6 +102,7 @@ static bool parse_u8(const char** p, uint8_t* out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parses ipv4.
|
||||
static bool parse_ipv4(const char* s, uint8_t ip[4]) {
|
||||
if (!s || !ip) return false;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@@ -104,6 +115,7 @@ static bool parse_ipv4(const char* s, uint8_t ip[4]) {
|
||||
return *s == 0;
|
||||
}
|
||||
|
||||
// Parses u32.
|
||||
static bool parse_u32(const char* s, uint32_t* out) {
|
||||
if (!s || !*s || !out) return false;
|
||||
uint32_t v = 0;
|
||||
@@ -118,6 +130,7 @@ static bool parse_u32(const char* s, uint32_t* out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Implements the resolve host operation.
|
||||
static uint32_t resolve_host(const char* host, uint8_t ip[4]) {
|
||||
if (parse_ipv4(host, ip))
|
||||
return SYS_STATUS_SUCCESS;
|
||||
@@ -145,6 +158,7 @@ static uint32_t resolve_host(const char* host, uint8_t ip[4]) {
|
||||
return SYS_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
// Implements the icmp checksum operation.
|
||||
static uint16_t icmp_checksum(const uint8_t* data, size_t length) {
|
||||
uint32_t sum = 0;
|
||||
while (length >= 2) {
|
||||
@@ -160,6 +174,7 @@ static uint16_t icmp_checksum(const uint8_t* data, size_t length) {
|
||||
return (uint16_t)(~sum & 0xFFFFu);
|
||||
}
|
||||
|
||||
// Creates echo request.
|
||||
static void make_echo_request(uint8_t packet[PING_PACKET_BYTES], uint16_t ident, uint16_t seq) {
|
||||
memset(packet, 0, PING_PACKET_BYTES);
|
||||
packet[0] = 8; // echo request
|
||||
@@ -207,11 +222,13 @@ static bool parse_echo_reply(const uint8_t* buf, size_t len, uint16_t ident, uin
|
||||
return false;
|
||||
}
|
||||
|
||||
// Implements the usage operation.
|
||||
static void usage(void) {
|
||||
print("usage: apps/ping.exe [host-or-ipv4] [count]\n");
|
||||
print("default: apps/ping.exe 10.0.2.2 4\n");
|
||||
}
|
||||
|
||||
// Runs the requested operation.
|
||||
int main(void) {
|
||||
char host[256];
|
||||
char tok[256];
|
||||
|
||||
Reference in new issue
Block a user