1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <string.h>
#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
#define BS 4096
int main(int argc,char *argv[]) {
int s;
struct sockaddr_in name;
//char *tmp;
int 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) {
for(tmp=0;tmp<len;tmp++) {
if(isprint((short)*(buf+tmp))) {
write(1,(buf+tmp),1);
} else {
write(1,"%",1);
write(1,"0123456789abcdef"+((buf[tmp])>>4&15),1);
write(1,"0123456789abcdef"+((buf[tmp])&15),1);
}
}
/*
while(off > 26) {
if((tmp=memchr(chunk+26,'\n',off-26))) {
tmp++;
//old write(1,chunk+26,tmp-chunk-26);
//testing:
for(len=26;len<tmp-chunk-1;len++) {
if(isprint(*(chunk+len))) {
write(1,(chunk+len),1);
} else {
write(1,"%",1);
write(1,"0123456789abcdef"+((*chunk+len)>>4 & 15),1);
write(1,"0123456789abcdef"+((*chunk+len)&15),1);
}
}
memmove(chunk,tmp,tmp-chunk+1);
off-=(tmp-chunk);
}
}
*/
}
return 0;
}
|