Commit d2be0d66 authored by Alessandro Rubini's avatar Alessandro Rubini

shell: export {decode,print}_{mac,ip}()

They are going to be used by the syslog code.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b65c513d
......@@ -14,6 +14,10 @@ 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);
void decode_ip(const char *str, unsigned char *ip);
void print_ip(char *head, unsigned char *ip, char *tail);
struct wrc_shell_cmd {
char *name;
......
......@@ -60,5 +60,7 @@ struct wr_udp_addr {
void fill_udp(uint8_t * buf, int len, struct wr_udp_addr *uaddr);
void syslog_init(void);
void syslog_poll(void);
#endif
......@@ -15,7 +15,7 @@
#include "shell.h"
#include "../lib/ipv4.h"
static void decode_ip(const char *str, unsigned char *ip)
void decode_ip(const char *str, unsigned char *ip)
{
int i, x;
......@@ -28,6 +28,12 @@ static void decode_ip(const char *str, unsigned char *ip)
}
}
void print_ip(char *head, unsigned char *ip, char *tail)
{
pp_printf("%s%d.%d.%d.%d%s",
head, ip[0], ip[1], ip[2], ip[3], tail);
}
static int cmd_ip(const char *args[])
{
unsigned char ip[4];
......@@ -44,8 +50,7 @@ static int cmd_ip(const char *args[])
if (needIP) {
pp_printf("IP-address: in training\n");
} else {
pp_printf("IP-address: %d.%d.%d.%d\n",
ip[0], ip[1], ip[2], ip[3]);
print_ip("IP-address: ", ip, "\n");
}
return 0;
}
......
......@@ -17,7 +17,7 @@
#include "endpoint.h"
#include "../lib/ipv4.h"
static void decode_mac(const char *str, unsigned char *mac)
void decode_mac(const char *str, unsigned char *mac)
{
int i, x;
......@@ -30,6 +30,13 @@ static void decode_mac(const char *str, unsigned char *mac)
}
}
void print_mac(char *head, unsigned char *mac, char *tail)
{
pp_printf("%s%02x:%02x:%02x:%02x:%02x:%02x%s",
head, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], tail);
}
static int cmd_mac(const char *args[])
{
unsigned char mac[6];
......@@ -52,8 +59,7 @@ static int cmd_mac(const char *args[])
return -EINVAL;
}
pp_printf("MAC-address: %02x:%02x:%02x:%02x:%02x:%02x\n",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
print_mac("MAC-address: ", mac, "\n");
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