diff options
author | epochqwert <epoch@53flpnlls43fcguy.onion> | 2015-02-22 19:47:33 -0600 |
---|---|---|
committer | epochqwert <epoch@53flpnlls43fcguy.onion> | 2015-02-22 19:47:33 -0600 |
commit | 4bdfc44f4681ef322378e614a409d5acc4d6586c (patch) | |
tree | 7e3aab5f5fa606ec172a4cf27ed9e3d967877f42 | |
parent | e751fa847caee5c8fc6c1bd0c7f49505d685bea6 (diff) | |
download | misc-4bdfc44f4681ef322378e614a409d5acc4d6586c.tar.gz misc-4bdfc44f4681ef322378e614a409d5acc4d6586c.zip |
added a URC dumper.
-rw-r--r-- | src/bin/urcdump.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/bin/urcdump.c b/src/bin/urcdump.c new file mode 100644 index 0000000..8d19370 --- /dev/null +++ b/src/bin/urcdump.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <sys/socket.h> +#include <netinet/in.h> + +#define BS 4096 + +int main(int argc,char *argv[]) { + int s; + struct sockaddr_in name; + char *tmp; + char chunk[BS]; + int off=0; + char buf[BS]; + int len=sizeof(struct sockaddr_in); + if(argc < 3) { + printf("usage: urcdump serv port\n"); + return -2; + } + s=socket(PF_INET,SOCK_STREAM,6); + memset(&name,0,len); + name.sin_family=AF_INET; + name.sin_addr.s_addr=inet_addr(argv[1]); + name.sin_port=htons(atoi(argv[2])); + setlinebuf(stdout); + if(connect(s,(struct sockaddr *)&name,len) == -1) return -1; + + while((len=read(s,buf,BS-1)) > 0) { + memcpy(chunk+off,buf,len); + off+=len; + if(off > 26) { + if((tmp=memchr(chunk+26,'\n',off-26))) { + tmp++; + write(1,chunk+26,tmp-chunk-26); + memmove(chunk,tmp,tmp-chunk+1); + off-=(tmp-chunk); + } + } + } +} |