Ticket #252: ipv6-phase-1.diff
File ipv6-phase-1.diff, 43.0 KB (added by jhujhiti, 12 years ago) |
---|
-
libtransmission/peer-io.c
19 19 #ifdef WIN32 20 20 #include <winsock2.h> 21 21 #else 22 #include <netinet/in.h> /* struct in_addr */23 22 #include <arpa/inet.h> /* inet_ntoa */ 24 23 #endif 25 24 … … 97 96 98 97 tr_session * session; 99 98 100 struct in_addr in_addr;99 tr_address addr; 101 100 struct tr_iobuf * iobuf; 102 101 tr_list * output_datatypes; /* struct tr_datatype */ 103 102 … … 238 237 } 239 238 240 239 static tr_peerIo* 241 tr_peerIoNew( tr_session *session,242 const struct in_addr * in_addr,243 uint16_t 244 const uint8_t * 245 int 246 int 240 tr_peerIoNew( tr_session * session, 241 const tr_address * addr, 242 uint16_t port, 243 const uint8_t * torrentHash, 244 int isIncoming, 245 int socket ) 247 246 { 248 247 tr_peerIo * io; 249 248 … … 254 253 io->magicNumber = MAGIC_NUMBER; 255 254 io->crypto = tr_cryptoNew( torrentHash, isIncoming ); 256 255 io->session = session; 257 io-> in_addr = *in_addr;256 io->addr = *addr; 258 257 io->port = port; 259 258 io->socket = socket; 260 259 io->isIncoming = isIncoming != 0; … … 266 265 } 267 266 268 267 tr_peerIo* 269 tr_peerIoNewIncoming( tr_session *session,270 const struct in_addr * in_addr,271 uint16_t 272 int 268 tr_peerIoNewIncoming( tr_session * session, 269 const tr_address * addr, 270 uint16_t port, 271 int socket ) 273 272 { 274 273 assert( session ); 275 assert( in_addr );274 assert( addr ); 276 275 assert( socket >= 0 ); 277 276 278 return tr_peerIoNew( session, in_addr, port,277 return tr_peerIoNew( session, addr, port, 279 278 NULL, 1, 280 279 socket ); 281 280 } 282 281 283 282 tr_peerIo* 284 tr_peerIoNewOutgoing( tr_session *session,285 const struct in_addr * in_addr,286 int 287 const uint8_t *torrentHash )283 tr_peerIoNewOutgoing( tr_session * session, 284 const tr_address * addr, 285 int port, 286 const uint8_t * torrentHash ) 288 287 { 289 288 int socket; 290 289 291 290 assert( session ); 292 assert( in_addr );291 assert( addr ); 293 292 assert( port >= 0 ); 294 293 assert( torrentHash ); 295 294 296 socket = tr_netOpenTCP( session, in_addr, port );295 socket = tr_netOpenTCP( session, addr, port ); 297 296 298 297 return socket < 0 299 298 ? NULL 300 : tr_peerIoNew( session, in_addr, port, torrentHash, 0, socket );299 : tr_peerIoNew( session, addr, port, torrentHash, 0, socket ); 301 300 } 302 301 303 302 static void … … 336 335 return io->session; 337 336 } 338 337 339 const struct in_addr*338 const tr_address* 340 339 tr_peerIoGetAddress( const tr_peerIo * io, 341 uint16_t * port )340 uint16_t * port ) 342 341 { 343 342 assert( isPeerIo( io ) ); 344 343 345 344 if( port ) 346 345 *port = io->port; 347 346 348 return &io-> in_addr;347 return &io->addr; 349 348 } 350 349 351 350 const char* 352 tr_peerIoAddrStr( const struct in_addr* addr,353 uint16_t 351 tr_peerIoAddrStr( const tr_address * addr, 352 uint16_t port ) 354 353 { 355 354 static char buf[512]; 356 355 357 tr_snprintf( buf, sizeof( buf ), "%s:%u", inet_ntoa( *addr ), 358 ntohs( port ) ); 356 if( addr->type == TR_AF_INET ) 357 tr_snprintf( buf, sizeof( buf ), "%s:%u", tr_ntop_non_ts( addr ), 358 ntohs( port ) ); 359 else 360 tr_snprintf( buf, sizeof( buf ), "[%s]:%u", tr_ntop_non_ts( addr ), 361 ntohs( port ) ); 359 362 return buf; 360 363 } 361 364 362 365 const char* 363 366 tr_peerIoGetAddrStr( const tr_peerIo * io ) 364 367 { 365 return tr_peerIoAddrStr( &io-> in_addr, io->port );368 return tr_peerIoAddrStr( &io->addr, io->port ); 366 369 } 367 370 368 371 static void … … 401 404 if( io->socket >= 0 ) 402 405 tr_netClose( io->socket ); 403 406 404 io->socket = tr_netOpenTCP( io->session, &io-> in_addr, io->port );407 io->socket = tr_netOpenTCP( io->session, &io->addr, io->port ); 405 408 406 409 if( io->socket >= 0 ) 407 410 { -
libtransmission/peer-msgs.c
1759 1759 diffs->elements[diffs->elementCount++] = *pex; 1760 1760 } 1761 1761 1762 /* TODO: ipv6 pex */ 1762 1763 static void 1763 1764 sendPex( tr_peermsgs * msgs ) 1764 1765 { … … 1806 1807 /* "added" */ 1807 1808 tmp = walk = tr_new( uint8_t, diffs.addedCount * 6 ); 1808 1809 for( i = 0; i < diffs.addedCount; ++i ) { 1809 memcpy( walk, &diffs.added[i]. in_addr, 4 ); walk += 4;1810 memcpy( walk, &diffs.added[i].addr.addr, 4 ); walk += 4; 1810 1811 memcpy( walk, &diffs.added[i].port, 2 ); walk += 2; 1811 1812 } 1812 1813 assert( ( walk - tmp ) == diffs.addedCount * 6 ); … … 1824 1825 /* "dropped" */ 1825 1826 tmp = walk = tr_new( uint8_t, diffs.droppedCount * 6 ); 1826 1827 for( i = 0; i < diffs.droppedCount; ++i ) { 1827 memcpy( walk, &diffs.dropped[i]. in_addr, 4 ); walk += 4;1828 memcpy( walk, &diffs.dropped[i].addr.addr, 4 ); walk += 4; 1828 1829 memcpy( walk, &diffs.dropped[i].port, 2 ); walk += 2; 1829 1830 } 1830 1831 assert( ( walk - tmp ) == diffs.droppedCount * 6 ); -
libtransmission/peer-io.h
21 21 *** 22 22 **/ 23 23 24 struct in_addr;25 24 struct evbuffer; 26 25 struct tr_bandwidth; 27 26 struct tr_crypto; … … 32 31 *** 33 32 **/ 34 33 35 tr_peerIo* tr_peerIoNewOutgoing( struct tr_handle 36 const struct in_addr* addr,37 int 38 const uint8_t 34 tr_peerIo* tr_peerIoNewOutgoing( struct tr_handle * session, 35 const tr_address * addr, 36 int port, 37 const uint8_t * torrentHash ); 39 38 40 tr_peerIo* tr_peerIoNewIncoming( struct tr_handle 41 const struct in_addr* addr,42 uint16_t 43 int 39 tr_peerIo* tr_peerIoNewIncoming( struct tr_handle * session, 40 const tr_address * addr, 41 uint16_t port, 42 int socket ); 44 43 45 44 void tr_peerIoFree( tr_peerIo * io ); 46 45 … … 59 58 *** 60 59 **/ 61 60 62 const char* tr_peerIoAddrStr( const struct in_addr* addr,63 uint16_t 61 const char* tr_peerIoAddrStr( const tr_address * addr, 62 uint16_t port ); 64 63 65 64 const char* tr_peerIoGetAddrStr( const tr_peerIo * io ); 66 65 67 const struct in_addr*tr_peerIoGetAddress( const tr_peerIo * io,66 const tr_address * tr_peerIoGetAddress( const tr_peerIo * io, 68 67 uint16_t * port ); 69 68 70 69 const uint8_t* tr_peerIoGetTorrentHash( tr_peerIo * io ); -
libtransmission/peer-mgr.c
95 95 * into this list for new ones. */ 96 96 struct peer_atom 97 97 { 98 uint8_t 99 uint8_t 100 uint8_t 101 uint16_t 102 uint16_t 103 struct in_addraddr;104 time_t 105 time_t 98 uint8_t from; 99 uint8_t flags; /* these match the added_f flags */ 100 uint8_t myflags; /* flags that aren't defined in added_f */ 101 uint16_t port; 102 uint16_t numFails; 103 tr_address addr; 104 time_t time; /* when the peer's connection status last changed */ 105 time_t piece_data_time; 106 106 }; 107 107 108 108 typedef struct … … 184 184 **/ 185 185 186 186 static int 187 compareAddresses( const struct in_addr * a,188 const struct in_addr * b )189 {190 if( a->s_addr != b->s_addr )191 return a->s_addr < b->s_addr ? -1 : 1;192 193 return 0;194 }195 196 static int197 187 handshakeCompareToAddr( const void * va, 198 188 const void * vb ) 199 189 { 200 190 const tr_handshake * a = va; 201 191 202 return compareAddresses( tr_handshakeGetAddr( a, NULL ), vb );192 return tr_compareAddresses( tr_handshakeGetAddr( a, NULL ), vb ); 203 193 } 204 194 205 195 static int … … 210 200 } 211 201 212 202 static tr_handshake* 213 getExistingHandshake( tr_ptrArray *handshakes,214 const struct in_addr * in_addr )203 getExistingHandshake( tr_ptrArray * handshakes, 204 const tr_address * addr ) 215 205 { 216 206 return tr_ptrArrayFindSorted( handshakes, 217 in_addr,207 addr, 218 208 handshakeCompareToAddr ); 219 209 } 220 210 … … 224 214 { 225 215 const struct peer_atom * a = va; 226 216 227 return compareAddresses( &a->addr, vb );217 return tr_compareAddresses( &a->addr, vb ); 228 218 } 229 219 230 220 static int … … 276 266 const tr_peer * a = va; 277 267 const tr_peer * b = vb; 278 268 279 return compareAddresses( &a->in_addr, &b->in_addr );269 return tr_compareAddresses( &a->addr, &b->addr ); 280 270 } 281 271 282 272 static int … … 285 275 { 286 276 const tr_peer * a = va; 287 277 288 return compareAddresses( &a->in_addr, vb );278 return tr_compareAddresses( &a->addr, vb ); 289 279 } 290 280 291 281 static tr_peer* 292 getExistingPeer( Torrent *torrent,293 const struct in_addr * in_addr )282 getExistingPeer( Torrent * torrent, 283 const tr_address * addr ) 294 284 { 295 285 assert( torrentIsLocked( torrent ) ); 296 assert( in_addr );286 assert( addr ); 297 287 298 288 return tr_ptrArrayFindSorted( torrent->peers, 299 in_addr,289 addr, 300 290 peerCompareToAddr ); 301 291 } 302 292 303 293 static struct peer_atom* 304 getExistingAtom( const Torrent* t,305 const struct in_addr* addr )294 getExistingAtom( const Torrent * t, 295 const tr_address * addr ) 306 296 { 307 297 assert( torrentIsLocked( t ) ); 308 298 return tr_ptrArrayFindSorted( t->pool, addr, comparePeerAtomToAddress ); 309 299 } 310 300 311 301 static int 312 peerIsInUse( const Torrent *ct,313 const struct in_addr* addr )302 peerIsInUse( const Torrent * ct, 303 const tr_address * addr ) 314 304 { 315 305 Torrent * t = (Torrent*) ct; 316 306 … … 322 312 } 323 313 324 314 static tr_peer* 325 peerConstructor( tr_torrent * tor, const struct in_addr * in_addr )315 peerConstructor( tr_torrent * tor, const tr_address * addr ) 326 316 { 327 317 tr_peer * p; 328 318 329 319 p = tr_new0( tr_peer, 1 ); 330 memcpy( &p-> in_addr, in_addr, sizeof( struct in_addr) );320 memcpy( &p->addr, addr, sizeof( tr_address ) ); 331 321 p->bandwidth = tr_bandwidthNew( tor->session, tor->bandwidth ); 332 322 return p; 333 323 } 334 324 335 325 static tr_peer* 336 getPeer( Torrent *torrent,337 const struct in_addr * in_addr )326 getPeer( Torrent * torrent, 327 const tr_address * addr ) 338 328 { 339 329 tr_peer * peer; 340 330 341 331 assert( torrentIsLocked( torrent ) ); 342 332 343 peer = getExistingPeer( torrent, in_addr );333 peer = getExistingPeer( torrent, addr ); 344 334 345 335 if( peer == NULL ) 346 336 { 347 peer = peerConstructor( torrent->tor, in_addr );337 peer = peerConstructor( torrent->tor, addr ); 348 338 tr_ptrArrayInsertSorted( torrent->peers, peer, peerCompare ); 349 339 } 350 340 … … 380 370 381 371 assert( torrentIsLocked( t ) ); 382 372 383 atom = getExistingAtom( t, &peer-> in_addr );373 atom = getExistingAtom( t, &peer->addr ); 384 374 assert( atom ); 385 375 atom->time = time( NULL ); 386 376 … … 530 520 ***/ 531 521 532 522 int 533 tr_peerMgrPeerIsSeed( const tr_peerMgr * 534 const uint8_t *torrentHash,535 const struct in_addr* addr )523 tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 524 const uint8_t * torrentHash, 525 const tr_address * addr ) 536 526 { 537 527 int isSeed = FALSE; 538 528 const Torrent * t = NULL; … … 905 895 tr_peer * peer ) 906 896 { 907 897 tordbg( t, "increasing peer %s strike count to %d", 908 tr_peerIoAddrStr( &peer-> in_addr,898 tr_peerIoAddrStr( &peer->addr, 909 899 peer->port ), peer->strikes + 1 ); 910 900 911 901 if( ++peer->strikes >= MAX_BAD_PIECES_PER_PEER ) 912 902 { 913 struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );903 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 914 904 atom->myflags |= MYFLAG_BANNED; 915 905 peer->doPurge = 1; 916 906 tordbg( t, "banning peer %s", … … 975 965 976 966 /* update our atom */ 977 967 if( peer ) { 978 struct peer_atom * a = getExistingAtom( t, &peer-> in_addr );968 struct peer_atom * a = getExistingAtom( t, &peer->addr ); 979 969 a->piece_data_time = now; 980 970 } 981 971 … … 1004 994 1005 995 /* update our atom */ 1006 996 if( peer ) { 1007 struct peer_atom * a = getExistingAtom( t, &peer-> in_addr );997 struct peer_atom * a = getExistingAtom( t, &peer->addr ); 1008 998 a->piece_data_time = now; 1009 999 } 1010 1000 … … 1015 1005 { 1016 1006 if( peer ) 1017 1007 { 1018 struct peer_atom * atom = getExistingAtom( t, 1019 &peer->in_addr ); 1008 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1020 1009 const int peerIsSeed = e->progress >= 1.0; 1021 1010 if( peerIsSeed ) 1022 1011 { … … 1111 1100 } 1112 1101 1113 1102 static void 1114 ensureAtomExists( Torrent *t,1115 const struct in_addr* addr,1116 uint16_t 1117 uint8_t 1118 uint8_t 1103 ensureAtomExists( Torrent * t, 1104 const tr_address * addr, 1105 uint16_t port, 1106 uint8_t flags, 1107 uint8_t from ) 1119 1108 { 1120 1109 if( getExistingAtom( t, addr ) == NULL ) 1121 1110 { … … 1152 1141 const uint8_t * peer_id, 1153 1142 void * vmanager ) 1154 1143 { 1155 int 1156 int 1157 uint16_t 1158 const struct in_addr* addr;1159 tr_peerMgr * 1160 Torrent * 1161 tr_handshake * 1144 int ok = isConnected; 1145 int success = FALSE; 1146 uint16_t port; 1147 const tr_address * addr; 1148 tr_peerMgr * manager = (tr_peerMgr*) vmanager; 1149 Torrent * t; 1150 tr_handshake * ours; 1162 1151 1163 1152 assert( io ); 1164 1153 assert( isConnected == 0 || isConnected == 1 ); … … 1253 1242 } 1254 1243 1255 1244 void 1256 tr_peerMgrAddIncoming( tr_peerMgr * 1257 struct in_addr* addr,1258 uint16_t 1259 int 1245 tr_peerMgrAddIncoming( tr_peerMgr * manager, 1246 tr_address * addr, 1247 uint16_t port, 1248 int socket ) 1260 1249 { 1261 1250 managerLock( manager ); 1262 1251 1263 1252 if( tr_sessionIsAddressBlocked( manager->session, addr ) ) 1264 1253 { 1265 1254 tr_dbg( "Banned IP address \"%s\" tried to connect to us", 1266 inet_ntoa( *addr ) );1255 tr_ntop_non_ts( addr ) ); 1267 1256 tr_netClose( socket ); 1268 1257 } 1269 1258 else if( getExistingHandshake( manager->incomingHandshakes, addr ) ) … … 1300 1289 managerLock( manager ); 1301 1290 1302 1291 t = getExistingTorrent( manager, torrentHash ); 1303 if( !tr_sessionIsAddressBlocked( t->manager->session, &pex-> in_addr ) )1304 ensureAtomExists( t, &pex-> in_addr, pex->port, pex->flags, from );1292 if( !tr_sessionIsAddressBlocked( t->manager->session, &pex->addr ) ) 1293 ensureAtomExists( t, &pex->addr, pex->port, pex->flags, from ); 1305 1294 1306 1295 managerUnlock( manager ); 1307 1296 } … … 1320 1309 1321 1310 for( i = 0; i < n; ++i ) 1322 1311 { 1323 memcpy( &pex[i].in_addr, walk, 4 ); walk += 4; 1312 pex[i].addr.type = TR_AF_INET; 1313 memcpy( &pex[i].addr.addr, walk, 4 ); walk += 4; 1324 1314 memcpy( &pex[i].port, walk, 2 ); walk += 2; 1325 1315 if( added_f && ( n == added_f_len ) ) 1326 1316 pex[i].flags = added_f[i]; … … 1357 1347 tordbg( 1358 1348 t, 1359 1349 "peer %s contributed to corrupt piece (%d); now has %d strikes", 1360 tr_peerIoAddrStr( &peer-> in_addr, peer->port ),1350 tr_peerIoAddrStr( &peer->addr, peer->port ), 1361 1351 pieceIndex, (int)peer->strikes + 1 ); 1362 1352 addStrike( t, peer ); 1363 1353 } … … 1371 1361 { 1372 1362 const tr_pex * a = va; 1373 1363 const tr_pex * b = vb; 1374 int i = 1375 memcmp( &a->in_addr, &b->in_addr, sizeof( struct in_addr ) ); 1364 int i = tr_compareAddresses( &a->addr, &b->addr ); 1376 1365 1377 1366 if( i ) return i; 1378 1367 if( a->port < b->port ) return -1; … … 1420 1409 for( i = 0; i < peerCount; ++i, ++walk ) 1421 1410 { 1422 1411 const tr_peer * peer = peers[i]; 1423 walk-> in_addr = peer->in_addr;1412 walk->addr = peer->addr; 1424 1413 walk->port = peer->port; 1425 1414 walk->flags = 0; 1426 1415 if( peerPrefersCrypto( peer ) ) walk->flags |= ADDED_F_ENCRYPTION_FLAG; … … 1658 1647 for( i = 0; i < size; ++i ) 1659 1648 { 1660 1649 const tr_peer * peer = peers[i]; 1661 const struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );1650 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1662 1651 1663 1652 if( peer->io == NULL ) /* not connected */ 1664 1653 continue; … … 1746 1735 { 1747 1736 char * pch; 1748 1737 const tr_peer * peer = peers[i]; 1749 const struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );1738 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1750 1739 tr_peer_stat * stat = ret + i; 1751 1740 1752 tr_n etNtop( &peer->in_addr, stat->addr, sizeof( stat->addr ) );1741 tr_ntop( &peer->addr, stat->addr, sizeof( stat->addr ) ); 1753 1742 tr_strlcpy( stat->client, ( peer->client ? peer->client : "" ), 1754 1743 sizeof( stat->client ) ); 1755 1744 stat->port = ntohs( peer->port ); … … 1945 1934 { 1946 1935 const tr_torrent * tor = t->tor; 1947 1936 const time_t now = time( NULL ); 1948 const struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );1937 const struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 1949 1938 1950 1939 /* if it's marked for purging, close it */ 1951 1940 if( peer->doPurge ) … … 2207 2196 for( i = 0; i < nBad; ++i ) 2208 2197 { 2209 2198 tr_peer * peer = connections[i]; 2210 struct peer_atom * atom = getExistingAtom( t, &peer-> in_addr );2199 struct peer_atom * atom = getExistingAtom( t, &peer->addr ); 2211 2200 if( peer->pieceDataActivityDate ) 2212 2201 atom->numFails = 0; 2213 2202 else -
libtransmission/peer-mgr.h
21 21 22 22 #ifdef WIN32 23 23 #include <winsock2.h> /* struct in_addr */ 24 #else25 #include <netinet/in.h> /* struct in_addr */26 24 #endif 27 25 28 struct in_addr; 26 #include "net.h" 27 29 28 struct tr_handle; 30 29 struct tr_peer_stat; 31 30 struct tr_torrent; … … 42 41 43 42 typedef struct tr_pex 44 43 { 45 struct in_addr in_addr;46 uint16_t 47 uint8_t 44 tr_address addr; 45 uint16_t port; 46 uint8_t flags; 48 47 } 49 48 tr_pex; 50 49 … … 54 53 55 54 void tr_peerMgrFree( tr_peerMgr * manager ); 56 55 57 int tr_peerMgrPeerIsSeed( const tr_peerMgr 58 const uint8_t 59 const struct in_addr* addr );56 int tr_peerMgrPeerIsSeed( const tr_peerMgr * mgr, 57 const uint8_t * torrentHash, 58 const tr_address * addr ); 60 59 61 void tr_peerMgrAddIncoming( tr_peerMgr 62 struct in_addr* addr,63 uint16_t 64 int 60 void tr_peerMgrAddIncoming( tr_peerMgr * manager, 61 tr_address * addr, 62 uint16_t port, 63 int socket ); 65 64 66 65 tr_pex * tr_peerMgrCompactToPex( const void * compact, 67 66 size_t compactLen, -
libtransmission/blocklist.c
31 31 #include "transmission.h" 32 32 #include "platform.h" 33 33 #include "blocklist.h" 34 #include "net.h" /* tr_netResolve() */34 #include "net.h" 35 35 #include "utils.h" 36 36 37 37 /*** … … 198 198 } 199 199 200 200 int 201 _tr_blocklistHasAddress( tr_blocklist *b,202 const struct in_addr* addr )201 _tr_blocklistHasAddress( tr_blocklist * b, 202 const tr_address * addr ) 203 203 { 204 204 uint32_t needle; 205 205 const struct tr_ip_range * range; … … 211 211 if( !b->rules ) 212 212 return 0; 213 213 214 needle = ntohl( addr-> s_addr );214 needle = ntohl( addr->addr.addr4.s_addr ); 215 215 216 216 range = bsearch( &needle, 217 217 b->rules, … … 259 259 { 260 260 char * rangeBegin; 261 261 char * rangeEnd; 262 struct in_addr in_addr;262 tr_address addr; 263 263 struct tr_ip_range range; 264 264 265 265 rangeBegin = strrchr( line, ':' ); … … 270 270 if( !rangeEnd ){ free( line ); continue; } 271 271 *rangeEnd++ = '\0'; 272 272 273 if( tr_netResolve( rangeBegin, &in_addr ) )273 if( !tr_pton( rangeBegin, &addr ) ) 274 274 tr_err( "blocklist skipped invalid address [%s]\n", rangeBegin ); 275 range.begin = ntohl( in_addr.s_addr );275 range.begin = ntohl( addr.addr.addr4.s_addr ); 276 276 277 if( tr_netResolve( rangeEnd, &in_addr ) )277 if( !tr_pton( rangeEnd, &addr ) ) 278 278 tr_err( "blocklist skipped invalid address [%s]\n", rangeEnd ); 279 range.end = ntohl( in_addr.s_addr );279 range.end = ntohl( addr.addr.addr4.s_addr ); 280 280 281 281 free( line ); 282 282 -
libtransmission/blocklist.h
17 17 #ifndef TR_BLOCKLIST_H 18 18 #define TR_BLOCKLIST_H 19 19 20 struct in_addr; 20 #include "net.h" /* NEW INCLDUE */ 21 21 22 typedef struct tr_blocklist tr_blocklist; 22 23 23 24 tr_blocklist* _tr_blocklistNew( const char * filename, … … 36 37 void _tr_blocklistSetEnabled( tr_blocklist *, 37 38 int isEnabled ); 38 39 39 int _tr_blocklistHasAddress( 40 tr_blocklist *, 41 const struct 42 in_addr * addr ); 40 int _tr_blocklistHasAddress( tr_blocklist *, 41 const tr_address * addr ); 43 42 44 43 int _tr_blocklistSetContent( 45 44 tr_blocklist *, -
libtransmission/port-forwarding.c
114 114 { 115 115 int socket; 116 116 errno = 0; 117 socket = tr_netBindTCP( s->publicPort ); 117 /* TODO: this is where we want to listen on another socket */ 118 socket = tr_netBindTCP( &tr_inaddr_any, s->publicPort ); 118 119 if( socket >= 0 ) 119 120 { 120 121 tr_ninf( getKey( ), … … 138 139 139 140 for( ; ; ) /* check for new incoming peer connections */ 140 141 { 141 int 142 uint16_t 143 struct in_addraddr;142 int socket; 143 uint16_t port; 144 tr_address addr; 144 145 145 146 if( s->bindSocket < 0 ) 146 147 break; -
libtransmission/handshake.c
1196 1196 return handshake->io; 1197 1197 } 1198 1198 1199 const struct in_addr*1199 const tr_address * 1200 1200 tr_handshakeGetAddr( const struct tr_handshake * handshake, 1201 1201 uint16_t * port ) 1202 1202 { -
libtransmission/fdlimit.c
471 471 } 472 472 473 473 int 474 tr_fdSocketAccept( int 475 struct in_addr* addr,476 tr_port_t *port )474 tr_fdSocketAccept( int b, 475 tr_address * addr, 476 tr_port_t * port ) 477 477 { 478 int s = -1;479 unsigned int len;480 struct sockaddr_ insock;478 int s = -1; 479 unsigned int len; 480 struct sockaddr_storage sock; 481 481 482 482 assert( addr ); 483 483 assert( port ); … … 485 485 tr_lockLock( gFd->lock ); 486 486 if( gFd->socketCount < getSocketMax( gFd ) ) 487 487 { 488 len = sizeof( s ock);488 len = sizeof( struct sockaddr ); 489 489 s = accept( b, (struct sockaddr *) &sock, &len ); 490 490 } 491 491 if( s > -1 ) 492 492 { 493 *addr = sock.sin_addr; 494 *port = sock.sin_port; 493 /* "The ss_family field of the sockaddr_storage structure will always 494 * align with the family field of any protocol-specific structure." */ 495 if( sock.ss_family == AF_INET ) 496 { 497 struct sockaddr_in * sock4 = (struct sockaddr_in *)&sock; 498 addr->type = TR_AF_INET; 499 addr->addr.addr4.s_addr = sock4->sin_addr.s_addr; 500 *port = sock4->sin_port; 501 } 502 else 503 { 504 struct sockaddr_in6 * sock6 = (struct sockaddr_in6 *)&sock; 505 addr->type = TR_AF_INET6; 506 memcpy( &addr->addr, &sock6->sin6_addr, 507 sizeof( struct sockaddr_in6 ) ); 508 *port = sock6->sin6_port; 509 } 495 510 ++gFd->socketCount; 496 511 } 497 512 tr_lockUnlock( gFd->lock ); -
libtransmission/handshake.h
19 19 20 20 #include "transmission.h" 21 21 22 struct in_addr;23 22 struct tr_peerIo; 24 23 typedef struct tr_handshake tr_handshake; 25 24 … … 35 34 handshakeDoneCB doneCB, 36 35 void * doneUserData ); 37 36 38 const struct in_addr* tr_handshakeGetAddr(37 const tr_address * tr_handshakeGetAddr( 39 38 const struct tr_handshake * handshake, 40 39 uint16_t 41 40 * setme_port ); -
libtransmission/fdlimit.h
87 87 **********************************************************************/ 88 88 int tr_fdSocketCreate( int type ); 89 89 90 int tr_fdSocketAccept( int 91 struct in_addr* addr,92 tr_port_t *port );90 int tr_fdSocketAccept( int b, 91 tr_address * addr, 92 tr_port_t * port ); 93 93 94 94 void tr_fdSocketClose( int s ); 95 95 -
libtransmission/peer-mgr-private.h
21 21 22 22 #ifdef WIN32 23 23 #include <winsock2.h> /* struct in_addr */ 24 #else25 #include <netinet/in.h> /* struct in_addr */26 24 #endif 27 25 28 26 #include "publish.h" /* tr_publisher_tag */ … … 52 50 53 51 uint8_t encryption_preference; 54 52 uint16_t port; 55 struct in_addr in_addr;53 tr_address addr; 56 54 struct tr_peerIo * io; 57 55 58 56 struct tr_bitfield * blame; -
libtransmission/transmission.h
49 49 #define PRIu32 "lu" 50 50 #endif 51 51 #include <time.h> /* time_t */ 52 #include <netinet/in.h> /* INET6_ADDRSTRLEN */ 52 53 53 54 #define SHA_DIGEST_LENGTH 20 54 55 … … 1061 1062 uint8_t from; 1062 1063 uint16_t port; 1063 1064 1064 char addr[ 16];1065 char addr[INET6_ADDRSTRLEN]; 1065 1066 char client[80]; 1066 1067 char flagStr[32]; 1067 1068 -
libtransmission/resume.c
61 61 **** 62 62 ***/ 63 63 64 /* TODO: fast resume is done with pex */ 64 65 static void 65 66 savePeers( tr_benc * dict, 66 67 const tr_torrent * tor ) -
libtransmission/session.c
799 799 } 800 800 801 801 int 802 tr_sessionIsAddressBlocked( const tr_session * 803 const struct in_addr* addr )802 tr_sessionIsAddressBlocked( const tr_session * session, 803 const tr_address * addr ) 804 804 { 805 805 tr_list * l; 806 806 -
libtransmission/net.c
47 47 #include "platform.h" 48 48 #include "utils.h" 49 49 50 const tr_address tr_in6addr_any = { TR_AF_INET6, { IN6ADDR_ANY_INIT } }; 51 const tr_address tr_inaddr_any = { TR_AF_INET, 52 { { { { INADDR_ANY, 0x00, 0x00, 0x00 } } } } }; 50 53 51 54 void 52 55 tr_netInit( void ) … … 63 66 } 64 67 } 65 68 66 /*********************************************************************** 67 * DNS resolution 68 * 69 * Synchronous "resolution": only works with character strings 70 * representing numbers expressed in the Internet standard `.' notation. 71 * Returns a non-zero value if an error occurs. 72 **********************************************************************/ 69 const char * 70 tr_ntop( const tr_address * src, 71 char * dst, 72 int size ) 73 { 74 if( src->type == TR_AF_INET ) 75 return inet_ntop( AF_INET, &src->addr, dst, size ); 76 else 77 return inet_ntop( AF_INET6, &src->addr, dst, size ); 78 } 79 80 /* 81 * Non-threadsafe version of tr_ntop, which uses a static memory area for a buffer. 82 * This function is suitable to be called from libTransmission's networking code, 83 * which is single-threaded. 84 */ 85 const char * 86 tr_ntop_non_ts( const tr_address * src ) 87 { 88 static char buf[INET6_ADDRSTRLEN]; 89 return tr_ntop( src, buf, sizeof( buf ) ); 90 } 91 92 tr_address * 93 tr_pton( const char * src, 94 tr_address * dst ) 95 { 96 int retval = inet_pton( AF_INET, src, &dst->addr ); 97 if( retval < 0 ) 98 return NULL; 99 else if( retval == 0 ) 100 retval = inet_pton( AF_INET6, src, &dst->addr ); 101 else 102 { 103 dst->type = TR_AF_INET; 104 return dst; 105 } 106 107 if( retval < 1 ) 108 return NULL; 109 dst->type = TR_AF_INET6; 110 return dst; 111 } 112 113 /* 114 * Compare two tr_address structures. 115 * Returns: 116 * <0 if a < b 117 * >0 if a > b 118 * 0 if a == b 119 */ 73 120 int 74 tr_ netResolve( const char * address,75 struct in_addr * addr)121 tr_compareAddresses( const tr_address * a, 122 const tr_address * b) 76 123 { 77 addr->s_addr = inet_addr( address ); 78 return addr->s_addr == 0xFFFFFFFF; 124 int retval; 125 int addrlen; 126 /* IPv6 addresses are always "greater than" IPv4 */ 127 if( a->type == TR_AF_INET && b->type == TR_AF_INET6 ) 128 return 1; 129 if( a->type == TR_AF_INET6 && b->type == TR_AF_INET ) 130 return -1; 131 132 if( a->type == TR_AF_INET ) 133 addrlen = sizeof( struct in_addr ); 134 else 135 addrlen = sizeof( struct in6_addr ); 136 137 retval = memcmp( &a->addr, &b->addr, addrlen ); 138 if( retval == 0 ) 139 return 0; 140 141 return retval; 79 142 } 80 143 81 144 /*********************************************************************** … … 136 199 #endif 137 200 } 138 201 202 static void 203 setup_sockaddr( const tr_address * addr, 204 tr_port_t port, 205 struct sockaddr_storage * sockaddr) 206 { 207 struct sockaddr_in sock4; 208 struct sockaddr_in6 sock6; 209 if( addr->type == TR_AF_INET ) 210 { 211 memset( &sock4, 0, sizeof( sock4 ) ); 212 sock4.sin_family = AF_INET; 213 sock4.sin_addr.s_addr = addr->addr.addr4.s_addr; 214 sock4.sin_port = port; 215 memcpy( sockaddr, &sock4, sizeof( sock4 ) ); 216 } 217 else 218 { 219 memset( &sock6, 0, sizeof( sock6 ) ); 220 sock6.sin6_family = AF_INET6; 221 sock6.sin6_port = port; 222 memcpy( &sock6.sin6_addr, &addr->addr, sizeof( struct in6_addr ) ); 223 memcpy( sockaddr, &sock6, sizeof( sock6 ) ); 224 } 225 } 226 139 227 int 140 tr_netOpenTCP( tr_session 141 const struct in_addr* addr,142 tr_port_t 228 tr_netOpenTCP( tr_session * session, 229 const tr_address * addr, 230 tr_port_t port ) 143 231 { 144 int s;145 struct sockaddr_ insock;146 const int type = SOCK_STREAM;232 int s; 233 struct sockaddr_storage sock; 234 const int type = SOCK_STREAM; 147 235 148 236 if( ( s = createSocket( type ) ) < 0 ) 149 237 return -1; 150 238 151 239 setSndBuf( session, s ); 152 240 153 memset( &sock, 0, sizeof( sock ) ); 154 sock.sin_family = AF_INET; 155 sock.sin_addr.s_addr = addr->s_addr; 156 sock.sin_port = port; 241 setup_sockaddr( addr, port, &sock ); 157 242 158 243 if( ( connect( s, (struct sockaddr *) &sock, 159 sizeof( struct sockaddr _in) ) < 0 )244 sizeof( struct sockaddr ) ) < 0 ) 160 245 #ifdef WIN32 161 246 && ( sockerrno != WSAEWOULDBLOCK ) 162 247 #endif … … 164 249 { 165 250 tr_err( _( 166 251 "Couldn't connect socket %d to %s, port %d (errno %d - %s)" ), 167 s, inet_ntoa( *addr ), port,252 s, tr_ntop_non_ts( addr ), port, 168 253 sockerrno, tr_strerror( sockerrno ) ); 169 254 tr_netClose( s ); 170 255 s = -1; … … 177 262 } 178 263 179 264 int 180 tr_netBindTCP( int port ) 265 tr_netBindTCP( const tr_address * addr, 266 int port ) 181 267 { 182 int s;183 struct sockaddr_ insock;184 const int type = SOCK_STREAM;268 int s; 269 struct sockaddr_storage sock; 270 const int type = SOCK_STREAM; 185 271 186 272 #if defined( SO_REUSEADDR ) || defined( SO_REUSEPORT ) 187 273 int optval; … … 194 280 optval = 1; 195 281 setsockopt( s, SOL_SOCKET, SO_REUSEADDR, (char*)&optval, sizeof( optval ) ); 196 282 #endif 283 284 setup_sockaddr( addr, htons( port ), &sock ); 197 285 198 memset( &sock, 0, sizeof( sock ) );199 sock.sin_family = AF_INET;200 sock.sin_addr.s_addr = INADDR_ANY;201 sock.sin_port = htons( port );202 203 286 if( bind( s, (struct sockaddr *) &sock, 204 sizeof( struct sockaddr _in) ) )287 sizeof( struct sockaddr ) ) ) 205 288 { 206 tr_err( _( "Couldn't bind port %d : %s" ), port,207 tr_ strerror( sockerrno ) );289 tr_err( _( "Couldn't bind port %d on %s: %s" ), port, 290 tr_ntop_non_ts( addr ), tr_strerror( sockerrno ) ); 208 291 tr_netClose( s ); 209 292 return -1; 210 293 } 211 294 212 tr_dbg( "Bound socket %d to port %d", s, port ); 295 tr_dbg( "Bound socket %d to port %d on %s", s, port, 296 tr_ntop_non_ts( addr ) ); 213 297 return s; 214 298 } 215 299 216 300 int 217 tr_netAccept( tr_session 218 int 219 struct in_addr* addr,220 tr_port_t 301 tr_netAccept( tr_session * session, 302 int b, 303 tr_address * addr, 304 tr_port_t * port ) 221 305 { 222 306 int fd = makeSocketNonBlocking( tr_fdSocketAccept( b, addr, port ) ); 223 307 setSndBuf( session, fd ); … … 229 313 { 230 314 tr_fdSocketClose( s ); 231 315 } 232 233 void234 tr_netNtop( const struct in_addr * addr,235 char * buf,236 int len )237 {238 const uint8_t * cast;239 240 cast = (const uint8_t *)addr;241 tr_snprintf( buf, len, "%hhu.%hhu.%hhu.%hhu",242 cast[0], cast[1], cast[2], cast[3] );243 }244 -
libtransmission/session.h
39 39 #endif 40 40 #endif 41 41 42 #include "net.h" 42 43 44 43 45 typedef enum { TR_NET_OK, TR_NET_ERROR, TR_NET_WAIT } tr_tristate_t; 44 46 45 47 uint8_t* tr_peerIdNew( void ); … … 121 123 const char * hashString, 122 124 const char * filename ); 123 125 124 struct in_addr; 126 int tr_sessionIsAddressBlocked( const tr_session * session, 127 const tr_address * addr ); 125 128 126 int tr_sessionIsAddressBlocked( const tr_session * session,127 const struct in_addr * addr );128 129 129 130 130 void tr_globalLock( tr_session * ); 131 131 132 132 void tr_globalUnlock( tr_session * ); -
libtransmission/net.h
60 60 #define sockerrno errno 61 61 #endif 62 62 63 struct in_addr;64 struct sockaddr_in;65 63 struct tr_session; 66 64 67 /*********************************************************************** 68 * DNS resolution 69 **********************************************************************/ 70 int tr_netResolve( const char *, 71 struct in_addr * ); 65 #define TR_AF_INET 0 66 #define TR_AF_INET6 1 72 67 68 typedef struct tr_address { 69 unsigned short type : 1; 70 union { 71 /* The order here is important for tr_in{,6}addr_any initialization, 72 * since we can't use C99 designated initializers */ 73 struct in6_addr addr6; 74 struct in_addr addr4; 75 } addr; 76 } tr_address; 73 77 78 extern const tr_address tr_inaddr_any; 79 extern const tr_address tr_in6addr_any; 80 81 const char *tr_ntop( const tr_address * src, 82 char * dst, 83 int size ); 84 const char *tr_ntop_non_ts( const tr_address * src ); 85 tr_address *tr_pton( const char * src, 86 tr_address * dst ); 87 int tr_compareAddresses( const tr_address * a, 88 const tr_address * b); 89 90 74 91 /*********************************************************************** 75 92 * Sockets 76 93 **********************************************************************/ 77 int tr_netOpenTCP( struct tr_handle 78 const struct in_addr* addr,79 tr_port_t 94 int tr_netOpenTCP( struct tr_handle * session, 95 const tr_address * addr, 96 tr_port_t port ); 80 97 81 int tr_netBindTCP( int port ); 98 int tr_netBindTCP( const tr_address * addr, 99 int port ); 82 100 83 int tr_netAccept( struct tr_handle 84 int 85 struct in_addr* setme_addr,86 tr_port_t 101 int tr_netAccept( struct tr_handle * session, 102 int bound, 103 tr_address * setme_addr, 104 tr_port_t * setme_port ); 87 105 88 106 int tr_netSetTOS( int s, 89 107 int tos ); 90 108 91 109 void tr_netClose( int s ); 92 110 93 void tr_netNtop( const struct in_addr * addr,94 char * buf,95 int len );96 97 111 void tr_netInit( void ); 98 112 99 113 #endif /* _TR_NET_H_ */ -
libtransmission/tracker.c
280 280 parseOldPeers( tr_benc * bePeers, 281 281 size_t * byteCount ) 282 282 { 283 /* TODO: wtf */ 283 284 int i; 284 285 uint8_t * compact, *walk; 285 286 const int peerCount = bePeers->val.l.count; … … 290 291 291 292 for( i = 0, walk = compact; i < peerCount; ++i ) 292 293 { 293 const char * 294 int64_t 295 struct in_addraddr;296 tr_port_t 297 tr_benc * 294 const char * s; 295 int64_t itmp; 296 tr_address addr; 297 tr_port_t port; 298 tr_benc * peer = &bePeers->val.l.vals[i]; 298 299 299 if( !tr_bencDictFindStr( peer, "ip", 300 &s ) || tr_netResolve( s, &addr ) ) 301 continue; 300 if( tr_bencDictFindStr( peer, "ip", &s ) ) 301 { 302 if( tr_pton( s, &addr ) == NULL ) 303 continue; 304 if( addr.type != TR_AF_INET ) 305 continue; 306 } 302 307 303 memcpy( walk, &addr , 4 );308 memcpy( walk, &addr.addr.addr4.s_addr, 4 ); 304 309 walk += 4; 305 310 306 311 if( !tr_bencDictFindInt( peer, "port", -
Transmission.xcodeproj/project.pbxproj
2239 2239 GCC_VERSION = 4.2; 2240 2240 GCC_WARN_ABOUT_MISSING_NEWLINE = NO; 2241 2241 GCC_WARN_ABOUT_RETURN_TYPE = NO; 2242 GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES; 2243 GCC_WARN_PEDANTIC = NO; 2242 2244 GCC_WARN_PROTOTYPE_CONVERSION = NO; 2243 2245 GCC_WARN_SHADOW = NO; 2244 2246 GCC_WARN_SIGN_COMPARE = NO;