From af5c4b800878c8a7d504b68db7b4c3d0bdcb5349 Mon Sep 17 00:00:00 2001 From: "Fabio M. Di Nitto" Date: Sat, 17 Nov 2012 08:16:31 +0100 Subject: [PATCH] libknet: remove hardcoded magic numbers Signed-off-by: Fabio M. Di Nitto --- kronosnetd/vty_cli_cmds.c | 6 +++--- libknet/libknet.h | 7 ++++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/kronosnetd/vty_cli_cmds.c b/kronosnetd/vty_cli_cmds.c index 0b5335f2f..99d9a63ab 100644 --- a/kronosnetd/vty_cli_cmds.c +++ b/kronosnetd/vty_cli_cmds.c @@ -948,7 +948,7 @@ static int knet_cmd_link(struct knet_vty *vty) int paramlen = 0, paramoffset = 0, err = 0; char *param = NULL; int link_id; - char src_ipaddr[KNET_MAX_HOST_LEN], src_port[6], dst_ipaddr[KNET_MAX_HOST_LEN], dst_port[6]; + char src_ipaddr[KNET_MAX_HOST_LEN], src_port[KNET_MAX_PORT_LEN], dst_ipaddr[KNET_MAX_HOST_LEN], dst_port[KNET_MAX_PORT_LEN]; get_param(vty, 1, ¶m, ¶mlen, ¶moffset); link_id = param_to_int(param, paramlen); @@ -957,13 +957,13 @@ static int knet_cmd_link(struct knet_vty *vty) param_to_str(src_ipaddr, KNET_MAX_HOST_LEN, param, paramlen); memset(src_port, 0, sizeof(src_port)); - snprintf(src_port, 6, "%d", knet_iface->cfg_ring.base_port + host->node_id); + snprintf(src_port, KNET_MAX_PORT_LEN, "%d", knet_iface->cfg_ring.base_port + host->node_id); get_param(vty, 3, ¶m, ¶mlen, ¶moffset); param_to_str(dst_ipaddr, KNET_MAX_HOST_LEN, param, paramlen); memset(dst_port, 0, sizeof(dst_port)); - snprintf(dst_port, 6, "%d", knet_iface->cfg_ring.base_port + knet_iface->cfg_eth.node_id); + snprintf(dst_port, KNET_MAX_PORT_LEN, "%d", knet_iface->cfg_ring.base_port + knet_iface->cfg_eth.node_id); klink = &host->link[link_id]; if (!klink->configured) { diff --git a/libknet/libknet.h b/libknet/libknet.h index edb43baa9..33553f28c 100644 --- a/libknet/libknet.h +++ b/libknet/libknet.h @@ -12,6 +12,7 @@ typedef struct knet_handle *knet_handle_t; #define KNET_MAX_HOST 65536 #define KNET_MAX_LINK 8 #define KNET_MAX_HOST_LEN 64 +#define KNET_MAX_PORT_LEN 6 #define KNET_CBUFFER_SIZE 4096 /* @@ -29,10 +30,10 @@ struct knet_link { uint8_t link_id; int listener_sock; char src_ipaddr[KNET_MAX_HOST_LEN]; - char src_port[6]; + char src_port[KNET_MAX_PORT_LEN]; struct sockaddr_storage src_addr; char dst_ipaddr[KNET_MAX_HOST_LEN]; - char dst_port[6]; + char dst_port[KNET_MAX_PORT_LEN]; struct sockaddr_storage dst_addr; unsigned int configured:1; /* link is configured and ready to be used */ unsigned int connected:1; /* link is enabled for data */ @@ -76,7 +77,7 @@ struct knet_hinfo_link { uint8_t khl_link_priority; uint64_t khl_link_latency; char khl_link_dst_ipaddr[KNET_MAX_HOST_LEN]; - char khl_link_dst_port[6]; + char khl_link_dst_port[KNET_MAX_PORT_LEN]; } __attribute__((packed)); struct knet_hinfo_link_table {