Created
March 6, 2017 19:04
-
-
Save ryochack/4ee81fff42be7b31ce449ffd047db99e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* continuous dump from binary stream | |
* $ tail -f xxx | xstream | |
*/ | |
#include <stdio.h> | |
#include <stdint.h> | |
void xstreamer(FILE *fdin, FILE *fdout) { | |
int col = 0; | |
int n; | |
uint8_t buf[512]; | |
int cap = sizeof(buf); | |
while((n = fread(buf, 1, cap, fdin)) > 0) | |
{ | |
uint8_t *p = buf; | |
while (n--) { | |
fprintf(fdout, "%02x ", *(p++)); | |
if (++ col == 0x10) { | |
fprintf(fdout, "\r\n"); | |
col = 0; | |
} | |
} | |
fflush(fdout); | |
} | |
} | |
int main(int argc, char** argv) { | |
xstreamer(stdin, stdout); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment