This method is much more stable than reading dd's output via stdin.
Signed-off-by: Roman Yeryomin <[email protected]>
Index: package/maccalc/src/main.c
===================================================================
--- a/package/maccalc/src/main.c (revision 28007)
+++ b/package/maccalc/src/main.c (working copy)
@@ -14,6 +14,7 @@
#include <stdint.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#define MAC_ADDRESS_LEN 6
@@ -127,16 +128,27 @@
static int maccalc_do_bin2mac(int argc, const char *argv[])
{
unsigned char mac[MAC_ADDRESS_LEN];
+ int source;
ssize_t c;
- if (argc != 0) {
- usage();
- return ERR_INVALID;
+ switch (argc) {
+ case 0:
+ source = STDIN_FILENO;
+ break;
+ case 1:
+ source = open(argv[0] , O_RDONLY);
+ break;
+ default:
+ usage();
+ return ERR_INVALID;
}
- c = read(STDIN_FILENO, mac, sizeof(mac));
+ c = read(source, mac, sizeof(mac));
+ if (argc > 0)
+ close(source);
+
if (c != sizeof(mac)) {
- fprintf(stderr, "failed to read from stdin\n");
+ fprintf(stderr, "failed to read from %i\n", source);
return ERR_IO;
}
@@ -182,7 +194,7 @@
" add <mac> <number>\n"
" and|or|xor <mac1> <mac2>\n"
" mac2bin <mac>\n"
- " bin2mac\n",
+ " bin2mac [<file>]\n",
maccalc_name);
}
_______________________________________________
openwrt-devel mailing list
[email protected]
https://lists.openwrt.org/mailman/listinfo/openwrt-devel