torrentd

simple torrent daemon
git clone git@git.2f30.org/torrentd.git
Log | Files | Refs | LICENSE

commit 86cd60370886168aaae24b2dcb13da237de12f97
parent 077e37b986539dbc11bfb54e1839a137dc87b318
Author: sin <sin@2f30.org>
Date:   Mon, 21 Dec 2015 17:02:43 +0000

Fix tracker_get_peers()

Diffstat:
Mtracker.c | 21+++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/tracker.c b/tracker.c @@ -11,7 +11,7 @@ tracker_get_peers(struct torrent *t, struct ben **peers) { char *url, *host, *port, *path; char *infohash, *id; - char buf[8192]; + char buf[8192], *p; int r, s; *peers = NULL; @@ -31,9 +31,22 @@ tracker_get_peers(struct torrent *t, struct ben **peers) goto err0; writeall(s, buf, r); - r = readall(s, buf, sizeof(buf) - 1); - buf[r] = '\0'; - puts(buf); + r = readall(s, buf, sizeof(buf)); + + if ((p = strnstr(buf, "\r\n\r\n", r))) { + p += 4; + r -= 4; + } else { + p = buf; + } + + if (!bdecode(p, p + r, peers)) + goto err0; + bprint(*peers, 0); + + free(url); + free(infohash); + free(id); return 0; err0: free(url);