Changeset 7330 for code/branches/ipv6/src/external/enet
- Timestamp:
- Sep 3, 2010, 12:28:21 AM (14 years ago)
- Location:
- code/branches/ipv6/src/external/enet
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ipv6/src/external/enet/host.c
r7328 r7330 50 50 51 51 host -> socket = enet_socket_create (ENET_SOCKET_TYPE_DATAGRAM); 52 enet_socket_set_option (host -> socket, ENET_SOCKOPT_V6ONLY, 0); // Needs to be set before bind. 53 52 54 if (host -> socket == ENET_SOCKET_NULL || (address != NULL && enet_socket_bind (host -> socket, address) < 0)) 53 55 { -
code/branches/ipv6/src/external/enet/include/enet/enet.h
r7328 r7330 51 51 ENET_SOCKOPT_RCVBUF = 3, 52 52 ENET_SOCKOPT_SNDBUF = 4, 53 ENET_SOCKOPT_REUSEADDR = 5 53 ENET_SOCKOPT_REUSEADDR = 5, 54 ENET_SOCKOPT_V6ONLY = 6 54 55 } ENetSocketOption; 55 56 56 enum 57 { 58 ENET_HOST_ANY = 0, /**< specifies the default server host */ 59 ENET_HOST_BROADCAST = 0xFFFFFFFF, /**< specifies a subnet-wide broadcast */ 60 61 ENET_PORT_ANY = 0 /**< specifies that a port should be automatically chosen */ 62 }; 57 typedef struct _ENetHostAddress 58 { 59 enet_uint8 addr[16]; 60 } ENetHostAddress; 61 62 extern const ENetHostAddress ENET_HOST_ANY; /**< specifies the default server host */ 63 extern const ENetHostAddress ENET_HOST_BROADCAST; /**< specifies a IPv4 subnet-wide broadcast */ 64 #define ENET_PORT_ANY 0 /**< specifies that a port should be automatically chosen */ 63 65 64 66 /** … … 74 76 typedef struct _ENetAddress 75 77 { 76 enet_uint32 host; 78 ENetHostAddress host; 79 enet_uint32 scopeID; //FIXME: this is of different size on Windows 77 80 enet_uint16 port; 78 81 } ENetAddress; … … 489 492 ENET_API int enet_address_get_host (const ENetAddress * address, char * hostName, size_t nameLength); 490 493 494 /** Maps an IPv4 Address to an IPv6 address. 495 @param address IPv4 address in network byte order 496 @returns the IPv4-mapped IPv6 address in network byte order 497 */ 498 static inline ENetHostAddress enet_address_map4 (enet_uint32 address) 499 { 500 ENetHostAddress addr = ENET_HOST_ANY; 501 ((enet_uint16 *)addr.addr)[5] = 0xffff; 502 ((enet_uint32 *)addr.addr)[3] = address; 503 return addr; 504 } 505 491 506 /** @} */ 492 507 -
code/branches/ipv6/src/external/enet/protocol.c
r7328 r7330 9 9 #include "enet/time.h" 10 10 #include "enet/enet.h" 11 12 const ENetHostAddress ENET_HOST_ANY = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } }; 13 const ENetHostAddress ENET_HOST_BROADCAST = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; 11 14 12 15 static size_t commandSizes [ENET_PROTOCOL_COMMAND_COUNT] = … … 263 266 { 264 267 if (currentPeer -> state != ENET_PEER_STATE_DISCONNECTED && 265 currentPeer -> address.host == host -> receivedAddress.host &&266 268 currentPeer -> address.port == host -> receivedAddress.port && 267 currentPeer -> connectID == command -> connect.connectID) 269 currentPeer -> connectID == command -> connect.connectID && 270 !memcmp(& currentPeer -> address.host, & host -> receivedAddress.host, sizeof (ENetHostAddress))) 268 271 return NULL; 269 272 } … … 849 852 if (peer -> state == ENET_PEER_STATE_DISCONNECTED || 850 853 peer -> state == ENET_PEER_STATE_ZOMBIE || 851 (host -> receivedAddress.host != peer -> address.host &&852 peer -> address.host != ENET_HOST_BROADCAST) ||853 854 (peer -> outgoingPeerID < ENET_PROTOCOL_MAXIMUM_PEER_ID && 854 sessionID != peer -> incomingSessionID)) 855 sessionID != peer -> incomingSessionID) || 856 ( memcmp(& peer -> address.host, & host -> receivedAddress.host, sizeof (ENetHostAddress)) && 857 memcmp(& peer -> address.host, & ENET_HOST_BROADCAST, sizeof (ENetHostAddress)) && 858 peer -> address.host.addr[0] != 0xff ) ) 855 859 return 0; 856 860 } … … 892 896 if (peer != NULL) 893 897 { 894 peer -> address.host = host -> receivedAddress.host; 895 peer -> address.port = host -> receivedAddress.port; 898 peer -> address = host -> receivedAddress; 896 899 peer -> incomingDataTotal += host -> receivedDataLength; 897 900 } -
code/branches/ipv6/src/external/enet/unix.c
r7328 r7330 75 75 enet_address_set_host (ENetAddress * address, const char * name) 76 76 { 77 struct hostent * hostEntry = NULL; 78 #ifdef HAS_GETHOSTBYNAME_R 79 struct hostent hostData; 80 char buffer [2048]; 81 int errnum; 82 83 #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 84 gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); 85 #else 86 hostEntry = gethostbyname_r (name, & hostData, buffer, sizeof (buffer), & errnum); 87 #endif 88 #else 89 hostEntry = gethostbyname (name); 90 #endif 91 92 if (hostEntry == NULL || 93 hostEntry -> h_addrtype != AF_INET) 94 { 95 #ifdef HAS_INET_PTON 96 if (! inet_pton (AF_INET, name, & address -> host)) 97 #else 98 if (! inet_aton (name, (struct in_addr *) & address -> host)) 99 #endif 100 return -1; 101 return 0; 102 } 103 104 address -> host = * (enet_uint32 *) hostEntry -> h_addr_list [0]; 77 struct addrinfo hints; 78 struct addrinfo * result; 79 struct addrinfo * res; 80 81 memset(& hints, 0, sizeof (hints)); 82 hints.ai_flags = AI_NUMERICSERV | AI_ADDRCONFIG; 83 hints.ai_family = AF_UNSPEC; 84 85 if ( getaddrinfo(name, NULL, &hints, &result) ) 86 { 87 return -1; 88 } 89 90 for (res = result; res != NULL; res = res -> ai_next) 91 { 92 if (res -> ai_family == AF_INET) 93 { 94 address -> host = enet_address_map4( ((struct sockaddr_in *) res -> ai_addr ) -> sin_addr.s_addr ); 95 address -> scopeID = 0; 96 break; 97 } 98 if (res -> ai_family == AF_INET6) 99 { 100 address -> host = * (ENetHostAddress *) & ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_addr; 101 address -> scopeID = ((struct sockaddr_in6 *) res -> ai_addr ) -> sin6_scope_id; 102 break; 103 } 104 } 105 freeaddrinfo(result); 106 if (res == NULL) return -1; 105 107 106 108 return 0; 107 109 } 108 110 111 static int 112 enet_address_get_host_x (const ENetAddress * address, char * name, size_t nameLength, int flags) 113 { 114 struct sockaddr_in6 sin; 115 116 memset (& sin, 0, sizeof (struct sockaddr_in6)); 117 118 sin.sin6_family = AF_INET6; 119 sin.sin6_addr = * (struct in6_addr *) & address -> host; 120 sin.sin6_scope_id = address -> scopeID; 121 122 if ( getnameinfo((struct sockaddr *) & sin, sizeof(sin), name, nameLength, NULL, 0, flags)) 123 { 124 return -1; 125 } 126 127 return 0; 128 } 129 109 130 int 110 131 enet_address_get_host_ip (const ENetAddress * address, char * name, size_t nameLength) 111 132 { 112 #ifdef HAS_INET_NTOP 113 if (inet_ntop (AF_INET, & address -> host, name, nameLength) == NULL) 114 #else 115 char * addr = inet_ntoa (* (struct in_addr *) & address -> host); 116 if (addr != NULL) 117 strncpy (name, addr, nameLength); 133 return enet_address_get_host_x(address, name, nameLength, NI_NUMERICHOST); 134 } 135 136 int 137 enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) 138 { 139 return enet_address_get_host_x(address, name, nameLength, 0); 140 } 141 142 int 143 enet_socket_bind (ENetSocket socket, const ENetAddress * address) 144 { 145 struct sockaddr_in6 sin; 146 147 memset (& sin, 0, sizeof (struct sockaddr_in6)); 148 149 sin.sin6_family = AF_INET6; 150 151 if (address != NULL) 152 { 153 sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); 154 sin.sin6_addr = * (struct in6_addr *) & address -> host; 155 sin.sin6_scope_id = address -> scopeID; 156 } 118 157 else 119 #endif 120 return -1; 121 return 0; 122 } 123 124 int 125 enet_address_get_host (const ENetAddress * address, char * name, size_t nameLength) 126 { 127 struct in_addr in; 128 struct hostent * hostEntry = NULL; 129 #ifdef HAS_GETHOSTBYADDR_R 130 struct hostent hostData; 131 char buffer [2048]; 132 int errnum; 133 134 in.s_addr = address -> host; 135 136 #if defined(linux) || defined(__linux) || defined(__linux__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 137 gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & hostEntry, & errnum); 138 #else 139 hostEntry = gethostbyaddr_r ((char *) & in, sizeof (struct in_addr), AF_INET, & hostData, buffer, sizeof (buffer), & errnum); 140 #endif 141 #else 142 in.s_addr = address -> host; 143 144 hostEntry = gethostbyaddr ((char *) & in, sizeof (struct in_addr), AF_INET); 145 #endif 146 147 if (hostEntry == NULL) 148 return enet_address_get_host_ip (address, name, nameLength); 149 150 strncpy (name, hostEntry -> h_name, nameLength); 151 152 return 0; 153 } 154 155 int 156 enet_socket_bind (ENetSocket socket, const ENetAddress * address) 157 { 158 struct sockaddr_in sin; 159 160 memset (& sin, 0, sizeof (struct sockaddr_in)); 161 162 sin.sin_family = AF_INET; 163 164 if (address != NULL) 165 { 166 sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); 167 sin.sin_addr.s_addr = address -> host; 168 } 169 else 170 { 171 sin.sin_port = 0; 172 sin.sin_addr.s_addr = INADDR_ANY; 158 { 159 sin.sin6_port = 0; 160 sin.sin6_addr = in6addr_any; 161 sin.sin6_scope_id = 0; 173 162 } 174 163 175 164 return bind (socket, 176 165 (struct sockaddr *) & sin, 177 sizeof (struct sockaddr_in ));166 sizeof (struct sockaddr_in6)); 178 167 } 179 168 … … 187 176 enet_socket_create (ENetSocketType type) 188 177 { 189 return socket ( PF_INET, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0);178 return socket (AF_INET6, type == ENET_SOCKET_TYPE_DATAGRAM ? SOCK_DGRAM : SOCK_STREAM, 0); 190 179 } 191 180 … … 220 209 break; 221 210 211 case ENET_SOCKOPT_V6ONLY: 212 result = setsockopt (socket, IPPROTO_IPV6, IPV6_V6ONLY, (char *) & value, sizeof (int)); 213 break; 214 222 215 default: 223 216 break; … … 229 222 enet_socket_connect (ENetSocket socket, const ENetAddress * address) 230 223 { 231 struct sockaddr_in sin; 232 233 memset (& sin, 0, sizeof (struct sockaddr_in)); 234 235 sin.sin_family = AF_INET; 236 sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); 237 sin.sin_addr.s_addr = address -> host; 238 239 return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in)); 224 struct sockaddr_in6 sin; 225 226 memset (& sin, 0, sizeof (struct sockaddr_in6)); 227 228 sin.sin6_family = AF_INET6; 229 sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); 230 sin.sin6_addr = * (struct in6_addr *) & address -> host; 231 sin.sin6_scope_id = address -> scopeID; 232 233 return connect (socket, (struct sockaddr *) & sin, sizeof (struct sockaddr_in6)); 240 234 } 241 235 … … 244 238 { 245 239 int result; 246 struct sockaddr_in sin;247 socklen_t sinLength = sizeof (struct sockaddr_in );240 struct sockaddr_in6 sin; 241 socklen_t sinLength = sizeof (struct sockaddr_in6); 248 242 249 243 result = accept (socket, … … 256 250 if (address != NULL) 257 251 { 258 address -> host = (enet_uint32) sin.sin_addr.s_addr; 259 address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); 252 address -> host = * (ENetHostAddress *) & sin.sin6_addr; 253 address -> scopeID = sin.sin6_scope_id; 254 address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); 260 255 } 261 256 … … 276 271 { 277 272 struct msghdr msgHdr; 278 struct sockaddr_in sin;273 struct sockaddr_in6 sin; 279 274 int sentLength; 280 275 … … 283 278 if (address != NULL) 284 279 { 285 memset (& sin, 0, sizeof (struct sockaddr_in)); 286 287 sin.sin_family = AF_INET; 288 sin.sin_port = ENET_HOST_TO_NET_16 (address -> port); 289 sin.sin_addr.s_addr = address -> host; 280 memset (& sin, 0, sizeof (struct sockaddr_in6)); 281 282 sin.sin6_family = AF_INET6; 283 sin.sin6_port = ENET_HOST_TO_NET_16 (address -> port); 284 sin.sin6_addr = * (struct in6_addr *) & address -> host; 285 sin.sin6_scope_id = address -> scopeID; 290 286 291 287 msgHdr.msg_name = & sin; 292 msgHdr.msg_namelen = sizeof (struct sockaddr_in );288 msgHdr.msg_namelen = sizeof (struct sockaddr_in6); 293 289 } 294 290 … … 316 312 { 317 313 struct msghdr msgHdr; 318 struct sockaddr_in sin;314 struct sockaddr_in6 sin; 319 315 int recvLength; 320 316 … … 324 320 { 325 321 msgHdr.msg_name = & sin; 326 msgHdr.msg_namelen = sizeof (struct sockaddr_in );322 msgHdr.msg_namelen = sizeof (struct sockaddr_in6); 327 323 } 328 324 … … 347 343 if (address != NULL) 348 344 { 349 address -> host = (enet_uint32) sin.sin_addr.s_addr; 350 address -> port = ENET_NET_TO_HOST_16 (sin.sin_port); 345 address -> host = * (ENetHostAddress *) & sin.sin6_addr; 346 address -> scopeID = sin.sin6_scope_id; 347 address -> port = ENET_NET_TO_HOST_16 (sin.sin6_port); 351 348 } 352 349
Note: See TracChangeset
for help on using the changeset viewer.