summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ot_udp.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/ot_udp.c b/ot_udp.c
index 5bf9d52..4e760bb 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -105,10 +105,11 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
105 match, return an error packet */ 105 match, return an error packet */
106 udp_make_connectionid(connid, remoteip, 1); 106 udp_make_connectionid(connid, remoteip, 1);
107 if (inpacket[0] != connid[0] || inpacket[1] != connid[1]) { 107 if (inpacket[0] != connid[0] || inpacket[1] != connid[1]) {
108 const size_t s = sizeof("Connection ID missmatch."); 108 const char err_idmiss[] = "Connection ID missmatch.";
109 size_t s = sizeof(err_idmiss);
109 outpacket[0] = htonl(3); 110 outpacket[0] = htonl(3);
110 outpacket[1] = inpacket[3]; 111 outpacket[1] = inpacket[3];
111 memcpy(&outpacket[2], "Connection ID missmatch.", s); 112 memcpy(&outpacket[2], &err_idmiss[0], s);
112 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport); 113 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport);
113 stats_issue_event(EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s); 114 stats_issue_event(EVENT_CONNID_MISSMATCH, FLAG_UDP, 8 + s);
114 return 1; 115 return 1;
@@ -173,7 +174,17 @@ int handle_udp6(int64_t serversocket, struct ot_workstruct *ws) {
173 numwant = max_peers; 174 numwant = max_peers;
174 175
175 ws->reply = ws->outbuf + 8; 176 ws->reply = ws->outbuf + 8;
176 ws->reply_size = 8 + add_peer_to_torrent_and_return_peers(FLAG_UDP, ws, numwant); 177 ws->reply_size = add_peer_to_torrent_and_return_peers(FLAG_UDP, ws, numwant);
178
179 if (!ws->reply_size) {
180 const char err_unauth[] = "Requested download is not authorized for use with this tracker.";
181 size_t s = sizeof(err_unauth);
182 outpacket[0] = htonl(3);
183 memcpy(&outpacket[2], &err_unauth[0], s);
184 socket_send(serversocket, ws->outbuf, 8 + s, remoteip, remoteport);
185 return 1;
186 }
187 ws->reply_size += 8;
177 } 188 }
178 189
179 socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport); 190 socket_send(serversocket, ws->outbuf, ws->reply_size, remoteip, remoteport);