Skip to content

Instantly share code, notes, and snippets.

@ryochack
Created March 6, 2017 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryochack/4ee81fff42be7b31ce449ffd047db99e to your computer and use it in GitHub Desktop.
Save ryochack/4ee81fff42be7b31ce449ffd047db99e to your computer and use it in GitHub Desktop.
/**
* 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