diff options
| author | Eudald Gubert i Roldan <hola@eudald.gr> | 2020-04-03 20:17:52 +0200 |
|---|---|---|
| committer | Raspbeguy <raspbeguy@users.noreply.github.com> | 2020-04-06 13:58:06 +0200 |
| commit | 73c9c332463b4c0d744a5cb1f570609f1e19ea26 (patch) | |
| tree | 0d7d0cf5ae491540f64f8c8e061fd543e0bd95fa /info/btinfo.c | |
| parent | a7fb9a80ce0c6021096b34b170f771a1bff022f7 (diff) | |
| download | btpd-73c9c332463b4c0d744a5cb1f570609f1e19ea26.tar.gz btpd-73c9c332463b4c0d744a5cb1f570609f1e19ea26.zip | |
Removed automake dependency
Diffstat (limited to 'info/btinfo.c')
| -rw-r--r-- | info/btinfo.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/info/btinfo.c b/info/btinfo.c new file mode 100644 index 0000000..dfcddcb --- /dev/null +++ b/info/btinfo.c @@ -0,0 +1,92 @@ +#include <sys/types.h> + +#include <errno.h> +#include <getopt.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include "metainfo.h" +#include "subr.h" + +static void +usage() +{ + fprintf(stderr, "Usage: btinfo file ...\n\n"); + exit(1); +} + +static struct option longopts[] = { + { "help", no_argument, NULL, 1 }, + { NULL, 0, NULL, 0 } +}; + +static void +print_metainfo(const char *mi) +{ + uint8_t hash[20]; + char hex[SHAHEXSIZE]; + char *name = mi_name(mi); + unsigned nfiles = mi_nfiles(mi); + struct mi_file *files = mi_files(mi); + struct mi_announce *ann = mi_announce(mi); + printf("Name: %s\n", name); + printf("Info hash: %s\n", bin2hex(mi_info_hash(mi, hash), hex, 20)); + printf("Tracker URLs: [ "); + for (int i = 0; i < ann->ntiers; i++) { + printf("[ "); + for (int j = 0; j < ann->tiers[i].nurls; j++) + printf("%s ", ann->tiers[i].urls[j]); + printf("] "); + } + printf("]\n"); + printf("Number of pieces: %lu\n", (unsigned long)mi_npieces(mi)); + printf("Piece size: %lld\n", (long long)mi_piece_length(mi)); + printf("Total size: %lld\n", (long long)mi_total_length(mi)); + printf("Number of files: %u\n", nfiles); + printf("Files:\n"); + for (int i = 0; i < nfiles; i++) { + printf("%s (%lld)\n", + files[i].path, (long long)files[i].length); + } + printf("\n"); + free(name); + mi_free_files(nfiles, files); + mi_free_announce(ann); +} + +int +main(int argc, char **argv) +{ + int ch; + + srandom(time(NULL)); + while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1) + usage(); + + argc -= optind; + argv += optind; + + if (argc < 1) + usage(); + + while (argc > 0) { + char *mi = NULL; + + if ((mi = mi_load(*argv, NULL)) == NULL) { + fprintf(stderr, "failed to load torrent file '%s' (%s).\n", + *argv, strerror(errno)); + exit(1); + } + + print_metainfo(mi); + free(mi); + + argc--; + argv++; + } + + return 0; +} |