Changeset 7377 for code/branches/ipv6/src/external/enet/protocol.c
- Timestamp:
- Sep 8, 2010, 4:08:09 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/ipv6/src/external/enet/protocol.c
r7330 r7377 11 11 12 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_IPV4MAPPED_PREFIX = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0,0,0,0 } }; 13 14 const ENetHostAddress ENET_HOST_BROADCAST = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } }; 14 15 … … 28 29 sizeof (ENetProtocolThrottleConfigure), 29 30 }; 31 32 ENetHostAddress 33 enet_address_map4 (enet_uint32 address) 34 { 35 ENetHostAddress addr = ENET_IPV4MAPPED_PREFIX; 36 ((enet_uint32 *)addr.addr)[3] = address; 37 return addr; 38 } 39 40 ENetAddressFamily 41 enet_get_address_family (const ENetAddress * address) 42 { 43 if (!memcmp(& address->host, & ENET_IPV4MAPPED_PREFIX, ENET_IPV4MAPPED_PREFIX_LEN)) 44 return ENET_IPV4; 45 return ENET_IPV6; 46 } 30 47 31 48 size_t … … 1025 1042 1026 1043 static int 1027 enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event )1044 enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event, ENetAddressFamily family) 1028 1045 { 1029 1046 for (;;) … … 1035 1052 buffer.dataLength = sizeof (host -> packetData [0]); 1036 1053 1037 receivedLength = enet_socket_receive ( host -> socket,1054 receivedLength = enet_socket_receive (family == ENET_IPV4 ? host -> socket4 : host -> socket6, 1038 1055 & host -> receivedAddress, 1039 1056 & buffer, 1040 1); 1057 1, 1058 family); 1041 1059 1042 1060 if (receivedLength < 0) … … 1045 1063 if (receivedLength == 0) 1046 1064 return 0; 1065 1066 if (enet_get_address_family (& host -> receivedAddress) != family) 1067 return -1; 1047 1068 1048 1069 host -> receivedData = host -> packetData [0]; … … 1501 1522 currentPeer -> lastSendTime = host -> serviceTime; 1502 1523 1503 sentLength = enet_socket_send (host -> socket, & currentPeer -> address, host -> buffers, host -> bufferCount); 1524 ENetAddressFamily family = enet_get_address_family (& currentPeer -> address); 1525 sentLength = enet_socket_send (family == ENET_IPV4 ? host -> socket4 : host -> socket6, 1526 & currentPeer -> address, 1527 host -> buffers, 1528 host -> bufferCount, 1529 family); 1504 1530 1505 1531 enet_protocol_remove_sent_unreliable_commands (currentPeer); … … 1612 1638 } 1613 1639 1614 switch (enet_protocol_receive_incoming_commands (host, event)) 1640 switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV4)) 1641 { 1642 case 1: 1643 return 1; 1644 1645 case -1: 1646 perror ("Error receiving incoming packets"); 1647 1648 return -1; 1649 1650 default: 1651 break; 1652 } 1653 1654 switch (enet_protocol_receive_incoming_commands (host, event, ENET_IPV6)) 1615 1655 { 1616 1656 case 1: … … 1664 1704 waitCondition = ENET_SOCKET_WAIT_RECEIVE; 1665 1705 1666 if (enet_socket_wait (host -> socket , & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0)1706 if (enet_socket_wait (host -> socket4, host -> socket6, & waitCondition, ENET_TIME_DIFFERENCE (timeout, host -> serviceTime)) != 0) 1667 1707 return -1; 1668 1708
Note: See TracChangeset
for help on using the changeset viewer.