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.

89 lignes
1.9 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. printf("Name: %s\n", name);
  30. printf("Info hash: %s\n", bin2hex(mi_info_hash(mi, hash), hex, 20));
  31. printf("Tracker URLs: [ ");
  32. for (int i = 0; i < ann->ntiers; i++) {
  33. printf("[ ");
  34. for (int j = 0; j < ann->tiers[i].nurls; j++)
  35. printf("%s ", ann->tiers[i].urls[j]);
  36. printf("] ");
  37. }
  38. printf("]\n");
  39. printf("Number of pieces: %lu\n", (unsigned long)mi_npieces(mi));
  40. printf("Piece size: %lld\n", (long long)mi_piece_length(mi));
  41. printf("Total size: %lld\n", (long long)mi_total_length(mi));
  42. printf("Number of files: %u\n", nfiles);
  43. printf("Files:\n");
  44. for (int i = 0; i < nfiles; i++) {
  45. printf("%s (%lld)\n",
  46. files[i].path, (long long)files[i].length);
  47. }
  48. printf("\n");
  49. free(name);
  50. mi_free_files(nfiles, files);
  51. mi_free_announce(ann);
  52. }
  53. int
  54. main(int argc, char **argv)
  55. {
  56. int ch;
  57. srandom(time(NULL));
  58. while ((ch = getopt_long(argc, argv, "", longopts, NULL)) != -1)
  59. usage();
  60. argc -= optind;
  61. argv += optind;
  62. if (argc < 1)
  63. usage();
  64. while (argc > 0) {
  65. char *mi = NULL;
  66. if ((mi = mi_load(*argv, NULL)) == NULL)
  67. err(1, "mi_load: %s", *argv);
  68. print_metainfo(mi);
  69. free(mi);
  70. argc--;
  71. argv++;
  72. }
  73. return 0;
  74. }