another small mldonkey helper

master
leitner 22 years ago
parent 9e85dc61a0
commit f7c6b5b3ee

@ -0,0 +1,44 @@
#include <socket.h>
#include "socket.h"
#include "buffer.h"
#include <unistd.h>
#include <stdio.h>
main(int argc,char* argv[]) {
int s=socket_tcp4();
char line[1024];
char buf[4096];
int l;
int header=1;
buffer filein;
if (argc<2 || strlen(argv[1])>900) {
buffer_putsflush(buffer_2,"usage: dllink ed2k://|file|<filename>|<filesize>|<MD4-sum|\n");
return 0;
}
buffer_init(&filein,read,s,buf,sizeof buf);
if (socket_connect4(s,"\x7f\x00\x00\x01",4000)) {
perror("connect");
return 1;
}
strcpy(buf,"dllink "); strcat(buf,argv[1]); strcat(buf,"\nq\n");
write(s,buf,strlen(buf));
for (;;) {
line[0]=0;
if ((l=buffer_getline(&filein,line,(sizeof line)-1))==0 && line[l]!='\n')
break;
else {
line[l+1]=0;
if (!header) {
if (strcmp(line,"\e[7mMLdonkey command-line:\e[2;37;0m\n") &&
strcmp(line,"\e[2;37;0m\e[7mMLdonkey command-line:\e[2;37;0m\n") &&
strncmp(line,"> ",2))
buffer_put(buffer_1,line,l+1);
}
if (!strcmp(line,"Use \e[31m?\e[2;37;0m for help\n")) header=0;
if (!strcmp(line,"Use ? for help\n")) header=0;
}
}
buffer_flush(buffer_1);
}
Loading…
Cancel
Save