/* $Id$ */ /* * Copyright (c) 2005 Dimitri Sokolyuk * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include #include /* basename(3) */ #include "meta.h" #include "tools.h" #include "version.h" #ifndef lint static const char rcsid[] = "@(#)$Id$"; #endif /* not lint */ const char usagearg[] = "torrent [torrent ...]"; extern char *__progname; int main(int argc, char **argv) { struct btmeta *mp; struct btfile *fp; char hash[HASHSZS]; if (argc < 2) usage(usagearg); printf("%s %d.%d - decode BitTorrent metainfo files\n\n", __progname, VERSION_MAJOR, VERSION_MINOR); while(*++argv != NULL) { if ((mp = btreadmeta(*argv)) == NULL) { warnx("cannot read %s\n", *argv); continue; } printf("metainfo file.: %s\n", basename(mp->fname)); bthexdump(hash, mp->infohash, sizeof(hash)); printf("info hash.....: %s\n", hash); if (mp->nfiles == 1) { printf("file name.....: %s\n", mp->name); } else { printf("directory name: %s\n", mp->name); printf("files.........: %d\n", mp->nfiles); SIMPLEQ_FOREACH(fp, &mp->flist, link) { printf(" %s (%lld) %s\n", fp->path, fp->length, metric((double) fp->length)); } } printf("%s %lld (%lld * %lld + %lld) %s\n", mp->nfiles == 1 ? "file size.....:" : "archive size..:", mp->size, mp->size / mp->plength, mp->plength, mp->size % mp->plength, metric((double) mp->size)); printf("announce url..: http://%s", mp->announce->host); if (mp->announce->port != 80) printf(":%d", mp->announce->port); putchar('/'); if (mp->announce->path != NULL) printf("%s", mp->announce->path); putchar('\n'); /* optional fields */ if (mp->date != 0) printf("creation date.: %s", ctime(&mp->date)); if (mp->comment != NULL) printf("comment.......: %s\n", mp->comment); if (mp->by != NULL) printf("created by....: %s\n", mp->by); btfreemeta(mp); printf("\n"); } return 0; }