Commit d451f516 authored by Alessandro Rubini's avatar Alessandro Rubini

shell: dont print_ip() but format_ip(). Same for mac

We need the string for IP and MAC in more places than stdout.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 75d7aa72
......@@ -15,9 +15,9 @@ extern int wrc_stat_running;
const char *fromhex(const char *hex, int *v);
const char *fromdec(const char *dec, int *v);
void decode_mac(const char *str, unsigned char *mac);
void print_mac(char *head, unsigned char *mac, char *tail);
char *format_mac(char *s, const unsigned char *mac);
void decode_ip(const char *str, unsigned char *ip);
void print_ip(char *head, unsigned char *ip, char *tail);
char *format_ip(char *s, const unsigned char *ip);
struct wrc_shell_cmd {
char *name;
......
......@@ -268,6 +268,8 @@ int ptpd_netif_recvfrom(struct wrpc_socket *s, struct wr_sockaddr *from, void *d
REF_CLOCK_PERIOD_PS);
}
net_verbose("%s: called from %p\n",
__func__, __builtin_return_address(0));
net_verbose("RX: Size %d tail %d Smac %x:%x:%x:%x:%x:%x\n", size,
q->tail, hdr.srcmac[0], hdr.srcmac[1], hdr.srcmac[2],
hdr.srcmac[3], hdr.srcmac[4], hdr.srcmac[5]);
......
......@@ -29,6 +29,8 @@ static uint32_t tics;
static int cmd_syslog(const char *args[])
{
char b1[32], b2[32];
if (args[0] && !strcmp(args[0], "off")) {
syslog_addr.daddr = 0;
return 0;
......@@ -39,8 +41,9 @@ static int cmd_syslog(const char *args[])
}
decode_ip(args[0], (void *)&syslog_addr.daddr);
decode_mac(args[1], syslog_mac);
print_ip("Syslog parameters: ", (void *)&syslog_addr.daddr, ", ");
print_mac("", syslog_mac, "\n");
pp_printf("Syslog parameters: %s, %s\n",
format_ip(b1, (void *)&syslog_addr.daddr),
format_mac(b2, syslog_mac));
tics = 0; /* send the first frame immediately to the new host */
return 0;
}
......
......@@ -28,15 +28,17 @@ void decode_ip(const char *str, unsigned char *ip)
}
}
void print_ip(char *head, unsigned char *ip, char *tail)
char *format_ip(char *s, const unsigned char *ip)
{
pp_printf("%s%d.%d.%d.%d%s",
head, ip[0], ip[1], ip[2], ip[3], tail);
pp_sprintf(s, "%d.%d.%d.%d",
ip[0], ip[1], ip[2], ip[3]);
return s;
}
static int cmd_ip(const char *args[])
{
unsigned char ip[4];
char buf[20];
if (!args[0] || !strcasecmp(args[0], "get")) {
getIP(ip);
......@@ -50,7 +52,7 @@ static int cmd_ip(const char *args[])
if (needIP) {
pp_printf("IP-address: in training\n");
} else {
print_ip("IP-address: ", ip, "\n");
pp_printf("IP-address: %s\n", format_ip(buf, ip));
}
return 0;
}
......
......@@ -30,16 +30,18 @@ void decode_mac(const char *str, unsigned char *mac)
}
}
void print_mac(char *head, unsigned char *mac, char *tail)
char *format_mac(char *s, const unsigned char *mac)
{
pp_printf("%s%02x:%02x:%02x:%02x:%02x:%02x%s",
head, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], tail);
pp_sprintf(s, "%02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
return s;
}
static int cmd_mac(const char *args[])
{
unsigned char mac[6];
char buf[32];
if (!args[0] || !strcasecmp(args[0], "get")) {
/* get current MAC */
......@@ -59,7 +61,7 @@ static int cmd_mac(const char *args[])
return -EINVAL;
}
print_mac("MAC-address: ", mac, "\n");
pp_printf("MAC-address: %s\n", format_mac(buf, mac));
return 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment