Commit 39848809 authored by Adam Wujek's avatar Adam Wujek 💬

[BUG: 1571] fix case-sensitive input to rtu_stat

Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 3b308099
......@@ -65,5 +65,6 @@ char *mac_to_string(uint8_t mac[ETH_ALEN]);
char *mac_to_buffer(uint8_t mac[ETH_ALEN], char buffer[ETH_ALEN_STR]);
int mac_from_str(uint8_t *tomac, const char *fromstr);
int mac_verify(char *mac_str);
int mac_to_lower(char *mac_str);
#endif /* __WHITERABBIT_RTU_MAC_H */
......@@ -28,6 +28,7 @@
#include <libwr/mac.h>
#include <stdio.h>
#include <ctype.h>
/**
* \brief Helper function to convert mac address into a string
......@@ -86,3 +87,19 @@ int mac_verify(char *mac_str)
}
return -1;
}
/**
* \brief Function to lowercase the mac address
*/
int mac_to_lower(char *mac_str)
{
int i;
if (ETH_ALEN_STR != strnlen(mac_str, ETH_ALEN_STR) + 1)
return -1;
for (i = 0; i < ETH_ALEN_STR; i++)
mac_str[i] = tolower(mac_str[i]);
return 0;
}
......@@ -462,7 +462,7 @@ int main(int argc, char **argv)
printf("Wrong port mask 0x%s\n", argv[4]);
exit(1);
}
if (mac_verify(argv[3])) {
if (mac_to_lower(argv[3]) || mac_verify(argv[3])) {
fprintf(stderr, "rtu_stat: Wrong MAC %s\n", argv[3]);
exit(1);
}
......@@ -494,7 +494,7 @@ int main(int argc, char **argv)
printf("Wrong port number %s\n", argv[3]);
exit(1);
}
if (mac_verify(argv[2])) {
if (mac_to_lower(argv[2]) || mac_verify(argv[2])) {
fprintf(stderr, "rtu_stat: Wrong MAC %s\n", argv[2]);
exit(1);
}
......@@ -527,7 +527,7 @@ int main(int argc, char **argv)
printf("Wrong port mask 0x%s\n", argv[4]);
exit(1);
}
if (mac_verify(argv[3])) {
if (mac_to_lower(argv[3]) || mac_verify(argv[3])) {
fprintf(stderr, "rtu_stat: Wrong MAC %s\n", argv[3]);
exit(1);
}
......@@ -558,7 +558,7 @@ int main(int argc, char **argv)
printf("Wrong port number %s\n", argv[3]);
exit(1);
}
if (mac_verify(argv[2])) {
if (mac_to_lower(argv[2]) || mac_verify(argv[2])) {
fprintf(stderr, "rtu_stat: Wrong MAC %s\n", argv[2]);
exit(1);
}
......
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