A clone of btpd with my configuration changes.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

93 行
2.0 KiB

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