summaryrefslogtreecommitdiff
path: root/astraceroute.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2017-10-20 15:19:53 +0200
committerTobias Klauser <tklauser@distanz.ch>2017-10-20 15:19:53 +0200
commitfe87d2b6117de1e32769b388fe1704440e339d27 (patch)
tree3f4ad769a64ea1689c677d47ae3c7e29f077ffeb /astraceroute.c
parent9addb47bec772b53a66c39efdd404290300d0e86 (diff)
astraceroute: use switch instead of lookup table for short proto idcoverity_scan
Avoid having a 58 entry array on stack of which only 3 are ever used. Just look up the short protocol identifier via a good'ol switch. Fixes Coverity CID 1381806 Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'astraceroute.c')
-rw-r--r--astraceroute.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/astraceroute.c b/astraceroute.c
index 91674e6..21e9a90 100644
--- a/astraceroute.c
+++ b/astraceroute.c
@@ -746,6 +746,19 @@ static int timevalcmp(const void *t1, const void *t2)
return 0;
}
+static const char *proto_short(int proto)
+{
+ switch (proto) {
+ case IPPROTO_TCP:
+ return "t";
+ case IPPROTO_ICMP:
+ case IPPROTO_ICMPV6:
+ return "i";
+ default:
+ return "?";
+ }
+}
+
static int __process_time(struct ctx *ctx, int fd, int fd_cap, int ttl,
int inner_proto, uint8_t *pkt_snd, uint8_t *pkt_rcv,
const struct sockaddr_storage *ss,
@@ -756,11 +769,6 @@ static int __process_time(struct ctx *ctx, int fd, int fd_cap, int ttl,
struct timeval probes[9], *tmp, sum, res;
uint8_t *trash = xmalloc(ctx->rcvlen);
char *cwait[] = { "-", "\\", "|", "/" };
- const char *proto_short[] = {
- [IPPROTO_TCP] = "t",
- [IPPROTO_ICMP] = "i",
- [IPPROTO_ICMPV6] = "i",
- };
memset(probes, 0, sizeof(probes));
for (i = 0; i < array_size(probes) && sigint == 0; ++i) {
@@ -800,7 +808,7 @@ static int __process_time(struct ctx *ctx, int fd, int fd_cap, int ttl,
qsort(tmp, j, sizeof(struct timeval), timevalcmp);
- printf("\r%2d: %s[", ttl, proto_short[inner_proto]);
+ printf("\r%2d: %s[", ttl, proto_short(inner_proto));
idx = j / 2;
switch (j % 2) {
case 0: