summaryrefslogtreecommitdiff
blob: a19a0dcfe3eab257b2bb3aa54c3f1518635c9e86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
diff -Naur aria2-1.6.3.orig/src/bittorrent_helper.cc aria2-1.6.3/src/bittorrent_helper.cc
--- aria2-1.6.3.orig/src/bittorrent_helper.cc	2009-11-02 15:22:22.000000000 +0100
+++ aria2-1.6.3/src/bittorrent_helper.cc	2009-11-14 18:56:29.461122621 +0100
@@ -774,9 +774,9 @@
   }
   struct sockaddr_in* in = reinterpret_cast<struct sockaddr_in*>(res->ai_addr);
   uint32_t* addrp = (uint32_t*)compact;
-  *addrp = in->sin_addr.s_addr;
-  uint16_t* portp = (uint16_t*)(compact+4);
-  *portp = htons(port);
+  memcpy(addrp, &(in->sin_addr.s_addr), sizeof(uint32_t));
+  uint16_t port_nworder(htons(port));
+  memcpy(compact+4, &port_nworder, sizeof(uint16_t));
   freeaddrinfo(res);
   return true;
 }
@@ -790,7 +790,7 @@
   in.sin_len = sizeof(in);
 #endif // HAVE_SOCKADDR_IN_SIN_LEN
   in.sin_family = AF_INET;
-  in.sin_addr.s_addr = *reinterpret_cast<const uint32_t*>(compact);
+  memcpy(&(in.sin_addr.s_addr), compact, sizeof(uint32_t));
   in.sin_port = 0;
   char host[NI_MAXHOST];
   int s;
@@ -800,7 +800,9 @@
   if(s) {
     return std::pair<std::string, uint16_t>();
   }
-  uint16_t port = ntohs(*(uint16_t*)(compact+sizeof(uint32_t)));
+  uint16_t port_nworder;
+  memcpy(&port_nworder, compact+sizeof(uint32_t), sizeof(uint16_t));
+  uint16_t port = ntohs(port_nworder);
   return std::pair<std::string, uint16_t>(host, port);
 }
 
diff -Naur aria2-1.6.3.orig/src/PeerListProcessor.h aria2-1.6.3/src/PeerListProcessor.h
--- aria2-1.6.3.orig/src/PeerListProcessor.h	2009-11-02 15:22:22.000000000 +0100
+++ aria2-1.6.3/src/PeerListProcessor.h	2009-11-14 17:12:40.000000000 +0100
@@ -40,6 +40,8 @@
 #include "bencode.h"
 #include "Peer.h"
 
+#include <cstring>
+
 namespace aria2 {
 
 class PeerListProcessor {
@@ -83,9 +85,11 @@
     if(length%6 == 0) {
       for(size_t i = 0; i < length; i += 6) {
 	struct in_addr in;
-	in.s_addr = *(uint32_t*)(peerData.s().c_str()+i);
+	memcpy(&in.s_addr, peerData.s().c_str()+i, sizeof(uint32_t));
 	std::string ipaddr = inet_ntoa(in);
-	uint16_t port = ntohs(*(uint16_t*)(peerData.s().c_str()+i+4));
+	uint16_t port_nworder;
+	memcpy(&port_nworder, peerData.s().c_str()+i+4, sizeof(uint16_t));
+	uint16_t port = ntohs(port_nworder);
 	*dest = SharedHandle<Peer>(new Peer(ipaddr, port));
 	++dest;
       }