下载libtorrent

https://github.com/arvidn/libtorrent/releases

编译安装

libtorrent目录下
./configure
make
make install

写码

dumptorrent.cpp

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "libtorrent/entry.hpp"
#include "libtorrent/bencode.hpp"
#include "libtorrent/torrent_info.hpp"
#include "libtorrent/announce_entry.hpp"
#include "libtorrent/bdecode.hpp"
#include "libtorrent/magnet_uri.hpp"
#include "libtorrent/hex.hpp"#include <fstream>std::vector<char> load_file(std::string const& filename)
{std::vector<char> ret;std::fstream in;in.exceptions(std::ifstream::failbit);in.open(filename.c_str(), std::ios_base::in | std::ios_base::binary);in.seekg(0, std::ios_base::end);size_t const size = in.tellg();in.seekg(0, std::ios_base::beg);ret.resize(size);in.read(ret.data(), ret.size());return ret;
}int main(int argc, char* argv[]) try
{if (argc < 2 || argc > 4) {fputs("usage: dump_torrent torrent-file [total-items-limit] [recursion-limit]\n", stderr);return 1;}int item_limit = 1000000;int depth_limit = 1000;if (argc > 2) item_limit = atoi(argv[2]);if (argc > 3) depth_limit = atoi(argv[3]);std::vector<char> buf = load_file(argv[1]);lt::bdecode_node e;int pos = -1;lt::error_code ec;std::cout << "decoding. recursion limit: " << depth_limit<< " total item count limit: " << item_limit << "\n";int const ret = lt::bdecode(&buf[0], &buf[0] + buf.size(), e, ec, &pos, depth_limit, item_limit);printf("\n\n----- raw info -----\n\n%s\n", print_entry(e).c_str());if (ret != 0) {std::cerr << "failed to decode: '" << ec.message() << "' at character: " << pos<< "\n";return 1;}lt::torrent_info const t(e);e.clear();std::vector<char>().swap(buf);// print info about torrentprintf("\n\n----- torrent file info -----\n\n""nodes:\n");typedef std::vector<std::pair<std::string, int> > node_vec;node_vec const& nodes = t.nodes();for (node_vec::const_iterator i = nodes.begin(), end(nodes.end());i != end; ++i){printf("%s: %d\n", i->first.c_str(), i->second);}puts("trackers:\n");for (std::vector<lt::announce_entry>::const_iterator i = t.trackers().begin();i != t.trackers().end(); ++i){printf("%2d: %s\n", i->tier, i->url.c_str());}char ih[41];lt::to_hex(t.info_hash().data(), 20, ih);printf("number of pieces: %d\n""piece length: %d\n""info hash: %s\n""comment: %s\n""created by: %s\n""magnet link: %s\n""name: %s\n""number of files: %d\n""files:\n", t.num_pieces(), t.piece_length(), ih, t.comment().c_str(), t.creator().c_str(), make_magnet_uri(t).c_str(), t.name().c_str(), t.num_files());lt::file_storage const& st = t.files();for (int i = 0; i < st.num_files(); ++i){int const first = st.map_file(i, 0, 0).piece;int const last = st.map_file(i, (std::max)(boost::int64_t(st.file_size(i))-1, boost::int64_t(0)), 0).piece;int const flags = st.file_flags(i);printf(" %8" PRIx64 " %11" PRId64 " %c%c%c%c [ %5d, %5d ] %7u %s %s %s%s\n", st.file_offset(i), st.file_size(i), ((flags & lt::file_storage::flag_pad_file)?'p':'-'), ((flags & lt::file_storage::flag_executable)?'x':'-'), ((flags & lt::file_storage::flag_hidden)?'h':'-'), ((flags & lt::file_storage::flag_symlink)?'l':'-'), first, last, boost::uint32_t(st.mtime(i)), st.hash(i) != lt::sha1_hash(0) ? lt::to_hex(st.hash(i).to_string()).c_str() : "", st.file_path(i).c_str(), (flags & lt::file_storage::flag_symlink) ? "-> " : "", (flags & lt::file_storage::flag_symlink) ? st.symlink(i).c_str() : "");}return 0;
}
catch (std::exception const& e)
{std::cerr << "ERROR: " << e.what() << "\n";
}

库软连接

ln -s /usr/local/lib/libtorrent-rasterbar.so.10 /usr/lib/libtorrent-rasterbar.so.10

编译

不使用boost库

g++ -std=c++11 dumptorrent.cpp -o dumptorrent -ltorrent-rasterbar -pthread

其他

也可以在安装好boost库和libtorrent后在example文件夹直接make

make dump_torrent

Linux下C++ libtorrent库使用相关推荐

  1. Linux下的静态库、动态库和动态加载库

    from: http://www.techug.com/linux-static-lib-dynamic-lib 库的存在极大的提高了C/C++程序的复用性,但是库对于初学者来说有些难以驾驭,本文从L ...

  2. linux 下基于jrtplib库的实时传送实现

    linux 下基于jrtplib库的实时传送实现 一.RTP 是进行实时流媒体传输的标准协议和关键技术 实时传输协议(Real-time Transport Protocol,PRT)是在 Inter ...

  3. linux下安装uuid库

    1.linux 下安装UUID库 1.1)ubuntu下安装uuid链接库 sudo apt-get install uuid-dev 1.2)CentOS yum install libuuid-d ...

  4. Linux下基于Libmad库的MP3音乐播放器编写

    linux下基于Libmad库的MP3音乐播放器编写 libmad是一个开源mp3解码库,其对mp3解码算法做了很多优化,性能较好,很多播放器如mplayer.xmms等都是使用这个开源库进行解码的: ...

  5. linux下基于jrtplib库的实时传送实现

    linux 下基于jrtplib库的实时传送实现 一.RTP 是进行实时流媒体传输的标准协议和关键技术  实时传输协议(Real-time Transport Protocol,PRT)是在 Inte ...

  6. linux dlopen 内存,Linux下加载库的有关问题(dlopenm, dlsym)

    Linux下加载库的问题(dlopenm, dlsym) 如题, 程序中发现load库成功,但是加载函数的时候报错: undefined symbol functionname 是很简单的一个东西,因 ...

  7. linux下生成静态库和动态库

    linux下生成静态库和动态库 一.动态库.静态库简介 库是写好的现有的,成熟的,可以复用的代码.现实中每个程序都要依赖很多基础的底层库,不可能每个人的代码都从零开始,因此库的存在意义非同寻常.本质上 ...

  8. linux 下的动态库制作 以及在python 中如何调用 c 函数库

    linux 下的动态库制作 以及在python 中如何调用 c 函数库 动态库: 动态库又称动态链接库英文为DLL,是Dynamic Link Library 的缩写形式,DLL是一个包含可由多个程序 ...

  9. Linux下curses函数库的详细介绍

    Linux下curses函数库的详细介绍 curses库介绍 安装 curses库函数介绍 初始化和重置函数 管理屏幕的函数 输出到屏幕 从屏幕读取 清除屏幕 移动光标 字符属性 管理键盘的函数 键盘 ...

  10. Linux下的动态库和静态库

    什么是库? 在 Linux 开发时,我们经常会看到一些形如 xxx.so 的名称出现,其中 so 是 Shared Object 的缩写,即可以共享的目标文件,也就是我们所称为的动态链接库,和在 Wi ...

最新文章

  1. Linux疑难杂症解决方案100篇(十)-uptime命令查看linux系统负载
  2. 【Python 】单引号和双引号有什么区别?
  3. 记录MySQL下所执行的所有命令
  4. 邮件服务器对接移动设备 企业邮箱随身邮
  5. oem718d 基准站设置_RTK电台、网络模式作业设置流程
  6. 关于计算机的网络作文,关于网络世界的作文
  7. java模拟JVM的GCRoots追踪算法,对象可达性分析
  8. [蓝桥杯]基础练习 十六进制转八进制
  9. 黑马程序员pink老师_CSS学习笔记
  10. 【粉丝福利,免费送书】SQL编程思想
  11. 18-移动端等比例缩放rem
  12. php ini 分号,当分号(;)被包含在值中时,用PHP解析INI文件
  13. 小学数学题的Java实现
  14. HFSS初探日志(六)被动毫米波成像系统馈源天线
  15. 普利姆(prim)算法与迪杰斯特拉(dijestella)算法
  16. MySQL查询(DQL)之基础查询+条件查询+排序查询
  17. 使用超级用户登录系统linux,登录和退出Linux系统
  18. 标准数据中国省市区+银行支行数据
  19. python修复老照片_老照片修复还原
  20. CTO俱乐部系列之四:3G和移动互联网的CTO俱乐部活动

热门文章

  1. 生物信息学在疾病基础研究中的应用
  2. 【QT学习教程1】制作用户登陆界面
  3. (152)IES光源概述文件
  4. 向量的方向余弦公式_方向余弦矩阵(DCM)简介
  5. 深度学习环境安装所需软件介绍cuda+cudnn+driver+anaconda+keras+tensorFlow+Pycharm+Jupyer(下载地址+配图)
  6. elementUi——select选择框的下拉框样式调整——基础积累
  7. 版本管理工具 SVN和git
  8. social-share,社会化分享组件之jquery版
  9. radon变换的原理-通过直线方程式的计算来检测出直线
  10. Tekla二次开发 第4节 曲梁及双截面梁