6 #include <sys/socket.h>
7 #include <netinet/in.h>
13 int main(int argc, char **argv)
16 struct sockaddr_in addr;
19 int resp_size, pending;
20 struct proto_flist *flist;
23 if((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
24 perror("failed to create socket");
28 if(!(host = gethostbyname(argv[1]))) {
29 fprintf(stderr, "Can't find %s: %s\n", argv[1], hstrerror(h_errno));
33 memset(&addr, 0, sizeof addr);
34 addr.sin_family = AF_INET;
35 addr.sin_port = htons(64357);
36 addr.sin_addr.s_addr = *(in_addr_t*)host->h_addr;
38 printf("Connecting to %s ...\n", inet_ntoa(addr.sin_addr));
40 if(connect(s, (struct sockaddr*)&addr, sizeof addr) == -1) {
41 fprintf(stderr, "Failed to connect to %s: %s\n", argv[1], strerror(errno));
45 if(read_line(s, buf, sizeof buf) == -1) {
46 fprintf(stderr, "Failed to read server identifier\n");
49 if(memcmp(buf, "reposerve-", 10) != 0) {
50 fprintf(stderr, "Protocol error, doesn't seem we're talking to reposerve at the other end\n");
54 write(s, "flist\n", 6);
57 if((resp_size = read_resp(s)) == -1) {
58 fprintf(stderr, "flist request failed\n");
62 fprintf(stderr, "flist response empty\n");
66 if(!(resp = malloc(resp_size))) {
67 fprintf(stderr, "failed to allocate response buffer (%d bytes)\n", resp_size);
72 while(pending > 0 && (sz = read(s, ptr, pending)) > 0) {
77 fprintf(stderr, "failed to read complete response (%d/%d bytes)\n",
78 resp_size - pending, resp_size);
84 flist = (struct proto_flist*)resp;
85 ptr = resp + sizeof *flist + (flist->num_files - 1) * sizeof *flist->files;
86 for(i=0; i<flist->num_files; i++) {
87 char *name = ptr + flist->files[i].nameoffs;
88 int tmp = name[flist->files[i].namelen];
89 name[flist->files[i].namelen] = 0;
92 name[flist->files[i].namelen] = tmp;