Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 8, 2010, 4:08:09 AM (14 years ago)
Author:
adrfried
Message:

using two separate sockets for ipv4 and ipv6

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ipv6/src/external/enet/protocol.c

    r7330 r7377  
    1111
    1212const ENetHostAddress ENET_HOST_ANY = { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
     13const ENetHostAddress ENET_IPV4MAPPED_PREFIX = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0,0,0,0 } };
    1314const ENetHostAddress ENET_HOST_BROADCAST = { { 0,0,0,0,0,0,0,0,0,0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
    1415
     
    2829    sizeof (ENetProtocolThrottleConfigure),
    2930};
     31
     32ENetHostAddress
     33enet_address_map4 (enet_uint32 address)
     34{
     35    ENetHostAddress addr = ENET_IPV4MAPPED_PREFIX;
     36    ((enet_uint32 *)addr.addr)[3] = address;
     37    return addr;
     38}
     39
     40ENetAddressFamily
     41enet_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}
    3047
    3148size_t
     
    10251042 
    10261043static int
    1027 enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event)
     1044enet_protocol_receive_incoming_commands (ENetHost * host, ENetEvent * event, ENetAddressFamily family)
    10281045{
    10291046    for (;;)
     
    10351052       buffer.dataLength = sizeof (host -> packetData [0]);
    10361053
    1037        receivedLength = enet_socket_receive (host -> socket,
     1054       receivedLength = enet_socket_receive (family == ENET_IPV4 ? host -> socket4 : host -> socket6,
    10381055                                             & host -> receivedAddress,
    10391056                                             & buffer,
    1040                                              1);
     1057                                             1,
     1058                                             family);
    10411059
    10421060       if (receivedLength < 0)
     
    10451063       if (receivedLength == 0)
    10461064         return 0;
     1065
     1066       if (enet_get_address_family (& host -> receivedAddress) != family)
     1067         return -1;
    10471068
    10481069       host -> receivedData = host -> packetData [0];
     
    15011522        currentPeer -> lastSendTime = host -> serviceTime;
    15021523
    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);
    15041530
    15051531        enet_protocol_remove_sent_unreliable_commands (currentPeer);
     
    16121638       }
    16131639
    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))
    16151655       {
    16161656       case 1:
     
    16641704       waitCondition = ENET_SOCKET_WAIT_RECEIVE;
    16651705
    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)
    16671707         return -1;
    16681708       
Note: See TracChangeset for help on using the changeset viewer.