torrentd

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

commit 995be1d691783afd8ce9bd77043ca80ca612f05a
parent 71c431c23ebdafb7c8efadf4131a0c002169ee55
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Mon, 21 Dec 2015 23:57:11 +0100

check protocol, don't try to connect to udp trackers

Diffstat:
Mstorrent.h | 2+-
Mtracker.c | 9+++++++--
Mutil.c | 9++++++---
3 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/storrent.h b/storrent.h @@ -81,4 +81,4 @@ ssize_t readall(int, void *, size_t); size_t strlcpy(char *, const char *, size_t); #undef strlcat size_t strlcat(char *, const char *, size_t); -char *parseurl(char *, char **, char **, char **); +char *parseurl(char *, char **, char **, char **, char **); diff --git a/tracker.c b/tracker.c @@ -9,15 +9,20 @@ int getpeers(struct torrent *t, struct ben **reply) { - char *url, *host, *port, *path; + char *url, *proto, *host, *port, *path; char *infohash, *id; char buf[8192], *p; int r, s; *reply = NULL; - url = parseurl(t->announcers[0].urls[0], &host, &port, &path); + url = parseurl(t->announcers[0].urls[0], &proto, &host, &port, &path); infohash = urlencode((char *)t->infohash, 20); id = urlencode(peerid(), 20); + if (proto && strcmp(proto, "http")) { + fprintf(stderr, "unsupported protocol: %s\n", proto); + goto fail; + } + r = snprintf(buf, sizeof(buf), "GET /%s?info_hash=%s&peer_id=%s&port=6881&uploaded=0&" "downloaded=0&left=%zu&event=started HTTP/1.1\r\n\r\n", diff --git a/util.c b/util.c @@ -271,15 +271,18 @@ strlcat(char *dst, const char *src, size_t dsize) } char * -parseurl(char *url, char **host, char **port, char **path) +parseurl(char *url, char **proto, char **host, char **port, char **path) { char *tmp, *p, *newurl; - *host = *port = *path = NULL; + *proto = *host = *port = *path = NULL; if (!(newurl = p = strdup(url))) err(1, "strdup"); - if ((tmp = strstr(p, "://"))) + if ((tmp = strstr(p, "://"))) { + *proto = p; + *tmp = '\0'; p = tmp + 3; + } if (!*p) return newurl; *host = p;