Commit 4153fad3 authored by Bruno Randolf's avatar Bruno Randolf

add util functions ip/ether_sprintf_short

parent a2b7e2ca
......@@ -117,6 +117,15 @@ ether_sprintf(const unsigned char *mac)
return etherbuf;
}
const char*
ether_sprintf_short(const unsigned char *mac)
{
static char etherbuf[5];
snprintf(etherbuf, sizeof(etherbuf), "%02x%02x",
mac[4], mac[5]);
return etherbuf;
}
const char*
ip_sprintf(const unsigned int ip)
......@@ -129,6 +138,16 @@ ip_sprintf(const unsigned int ip)
}
const char*
ip_sprintf_short(const unsigned int ip)
{
static char ipbuf[5];
unsigned char* cip = (unsigned char*)&ip;
snprintf(ipbuf, sizeof(ipbuf), ".%d", cip[3]);
return ipbuf;
}
void
convert_string_to_mac(const char* string, unsigned char* mac)
{
......
......@@ -52,9 +52,15 @@ dump_packet(const unsigned char* buf, int len);
const char*
ether_sprintf(const unsigned char *mac);
const char*
ether_sprintf_short(const unsigned char *mac);
const char*
ip_sprintf(const unsigned int ip);
const char*
ip_sprintf_short(const unsigned int ip);
void
convert_string_to_mac(const char* string, unsigned char* mac);
......
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