summaryrefslogtreecommitdiff
path: root/src/cmd/netstack
diff options
context:
space:
mode:
authordzwdz2023-08-30 00:03:43 +0200
committerdzwdz2023-08-30 00:03:43 +0200
commitcf7877737ff5032f8bad59d57b048f66c4813b5b (patch)
treeec9c66772331594c30b34062a2cb0f72719d6f6e /src/cmd/netstack
parentf71af249cfb9ca9eb0832cc46437b2c5cb7bb217 (diff)
style: get rid of eprintf
Diffstat (limited to 'src/cmd/netstack')
-rw-r--r--src/cmd/netstack/ether.c3
-rw-r--r--src/cmd/netstack/fs.c3
-rw-r--r--src/cmd/netstack/ipv4.c2
-rw-r--r--src/cmd/netstack/netstack.c9
-rw-r--r--src/cmd/netstack/tcp.c5
-rw-r--r--src/cmd/netstack/udp.c3
-rw-r--r--src/cmd/netstack/util.h2
7 files changed, 15 insertions, 12 deletions
diff --git a/src/cmd/netstack/ether.c b/src/cmd/netstack/ether.c
index 52abac2..7f3f3d4 100644
--- a/src/cmd/netstack/ether.c
+++ b/src/cmd/netstack/ether.c
@@ -1,4 +1,5 @@
#include <camellia/syscalls.h>
+#include <err.h>
#include "proto.h"
#include "util.h"
@@ -40,7 +41,7 @@ static const size_t fhoff = sizeof(size_t);
uint8_t *ether_start(size_t len, struct ethernet ether) {
if (len < 60 - Payload) len = 60 - Payload;
- if (!ether.dst) eprintf("NULL ether.dst!"); // TODO arp? i guess?
+ if (!ether.dst) warnx("null ether.dst");
if (!ether.src) ether.src = &state.mac;
uint8_t *buf = malloc(fhoff + Payload + len);
diff --git a/src/cmd/netstack/fs.c b/src/cmd/netstack/fs.c
index 6d51c35..92681ba 100644
--- a/src/cmd/netstack/fs.c
+++ b/src/cmd/netstack/fs.c
@@ -14,6 +14,7 @@
#include "util.h"
#include <camellia/flags.h>
#include <camellia/syscalls.h>
+#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
@@ -157,7 +158,7 @@ static void fs_open(hid_t reqh, char *path, int flags) {
if (ip_parse(strtok_r(NULL, "/", &save), &srcip) < 0)
respond(NULL, -1);
if (srcip != 0) {
- eprintf("unimplemented");
+ warnx("unimplemented");
respond(NULL, -1);
}
diff --git a/src/cmd/netstack/ipv4.c b/src/cmd/netstack/ipv4.c
index 1336dc1..eebd976 100644
--- a/src/cmd/netstack/ipv4.c
+++ b/src/cmd/netstack/ipv4.c
@@ -73,7 +73,7 @@ static void fragmented_tryinsert(const uint8_t *payload, size_t plen, struct ipv
struct fragmented *inc = fragmented_find(ip);
size_t off = (ip.fraginfo & FragOff) * 8;
bool last = !(ip.fraginfo & MoreFrags);
- // eprintf("fragmented packet, %u + %u, part of 0x%x", off, plen, inc);
+ // warnx("fragmented packet, %u + %u, part of 0x%x", off, plen, inc);
/* find the first fragment at a bigger offset, and insert before it */
struct fragment **insert = &inc->first;
diff --git a/src/cmd/netstack/netstack.c b/src/cmd/netstack/netstack.c
index 4cdf409..a8e011e 100644
--- a/src/cmd/netstack/netstack.c
+++ b/src/cmd/netstack/netstack.c
@@ -3,6 +3,7 @@
#include <camellia.h>
#include <camellia/compat.h>
#include <camellia/syscalls.h>
+#include <err.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
@@ -29,20 +30,20 @@ void fs_thread(void *arg);
int main(int argc, char **argv) {
if (argc < 4) {
- eprintf("usage: netstack iface ip gateway");
+ fprintf(stderr, "usage: netstack iface ip gateway\n");
return 1;
}
state.raw_h = camellia_open(argv[1], OPEN_RW);
if (state.raw_h < 0) {
- eprintf("couldn't open %s", argv[1]);
+ err(1, "open %s", argv[1]);
return 1;
}
if (ip_parse(argv[2], &state.ip) < 0) {
- eprintf("invalid ip");
+ errx(1, "invalid ip: %s", argv[2]);
return -1;
}
if (ip_parse(argv[3], &state.gateway) < 0) {
- eprintf("invalid gateway");
+ errx(1, "invalid gateway: %s", argv[2]);
return -1;
}
setproctitle(argv[2]);
diff --git a/src/cmd/netstack/tcp.c b/src/cmd/netstack/tcp.c
index d1adeab..cbe2c14 100644
--- a/src/cmd/netstack/tcp.c
+++ b/src/cmd/netstack/tcp.c
@@ -5,6 +5,7 @@
#include "proto.h"
#include "util.h"
#include <assert.h>
+#include <err.h>
#include <shared/ring.h>
enum {
@@ -123,7 +124,7 @@ struct tcp_conn *tcpc_new(
// TODO wait for ARP reply
arp_request(c->rip);
if (arpcache_get(state.gateway, &c->rmac) < 0) {
- eprintf("neither target nor gateway not in ARP cache, dropping");
+ warnx("neither target nor gateway not in ARP cache, dropping");
free(c);
return NULL;
}
@@ -222,7 +223,7 @@ void tcp_parse(const uint8_t *buf, size_t len, struct ipv4 ip) {
}
}
if (iter->lack != seq && iter->lack - 1 != seq) {
- eprintf("remote seq jumped by %d", seq - iter->lack);
+ warnx("remote seq jumped by %d", seq - iter->lack);
tcpc_sendraw(iter, FlagACK, NULL, 0);
return;
}
diff --git a/src/cmd/netstack/udp.c b/src/cmd/netstack/udp.c
index 3d560ae..285af41 100644
--- a/src/cmd/netstack/udp.c
+++ b/src/cmd/netstack/udp.c
@@ -1,5 +1,6 @@
#include "proto.h"
#include "util.h"
+#include <err.h>
enum {
SrcPort = 0,
@@ -55,7 +56,7 @@ struct udp_conn *udpc_new(
c->rport = u.dst;
if (arpcache_get(c->rip, &c->rmac) < 0) {
// TODO make arp request, wait for reply
- eprintf("not in ARP cache, unimplemented");
+ warnx("IP not in ARP cache, unimplemented");
free(c);
return NULL;
}
diff --git a/src/cmd/netstack/util.h b/src/cmd/netstack/util.h
index 0b29560..c1032a2 100644
--- a/src/cmd/netstack/util.h
+++ b/src/cmd/netstack/util.h
@@ -4,8 +4,6 @@
#include <stdlib.h>
#include <string.h>
-#define eprintf(fmt, ...) fprintf(stderr, "netstack: "fmt"\n" __VA_OPT__(,) __VA_ARGS__)
-
uint32_t crc32(const uint8_t *buf, size_t len);
uint16_t ip_checksum(const uint8_t *buf, size_t len);
uint16_t ip_checksumphdr(