A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

81 lignes
1.7 KiB

  1. #include <sys/types.h>
  2. #include <err.h>
  3. #include <errno.h>
  4. #include <getopt.h>
  5. #include <inttypes.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include "metainfo.h"
  9. #include "subr.h"
  10. static void
  11. usage()
  12. {
  13. fprintf(stderr, "Usage: btinfo file ...\n\n");
  14. exit(1);
  15. }
  16. static struct option longopts[] = {
  17. { "help", no_argument, NULL, 1 },
  18. { NULL, 0, NULL, 0 }
  19. };
  20. static void
  21. print_metainfo(const char *mi)
  22. {
  23. uint8_t hash[20];
  24. char hex[SHAHEXSIZE];
  25. char *name = mi_name(mi);
  26. unsigned nfiles = mi_nfiles(mi);
  27. struct mi_file *files = mi_files(mi);
  28. struct mi_announce *ann = mi_announce(mi);
  29. for (int i = 0; i < ann->ntiers; i++)
  30. for (int j = 0; j < ann->tiers[i].nurls; j++)
  31. printf("%d: %s\n", i, ann->tiers[i].urls[j]);
  32. printf("\n");
  33. mi_free_announce(ann);
  34. mi_info_hash(mi, hash);
  35. bin2hex(hash, hex, 20);
  36. printf("name: %s\n", name);
  37. printf("info hash: %s\n", hex);
  38. printf("length: %jd\n", (intmax_t)mi_total_length(mi));
  39. printf("piece length: %jd\n", (intmax_t)mi_piece_length(mi));
  40. printf("files: %u\n", nfiles);
  41. for (unsigned i = 0; i < nfiles; i++)
  42. printf("%s(%jd)\n", files[i].path, (intmax_t)files[i].length);
  43. free(name);
  44. }
  45. int
  46. main(int argc, char **argv)
  47. {
  48. int ch;
  49. srandom(time(NULL));
  50. while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1)
  51. usage();
  52. argc -= optind;
  53. argv += optind;
  54. if (argc < 1)
  55. usage();
  56. while (argc > 0) {
  57. char *mi = NULL;
  58. if ((mi = mi_load(*argv, NULL)) == NULL)
  59. err(1, "mi_load: %s", *argv);
  60. print_metainfo(mi);
  61. free(mi);
  62. argc--;
  63. argv++;
  64. }
  65. return 0;
  66. }