Ejemplo n.º 1
0
    // Init structures for an IPX game.
PUBLIC bool COM_InitIpxGame(int maxlink, int socket) {
    int i;
    if (COM_Links != NULL || !COM_IPXPresent || maxlink <= 0)
        return FALSE;

    COM_Type = COMT_IPX;
        // Init links.
    COM_Links = NEW(maxlink*sizeof(*COM_Links));
    if (COM_Links == NULL)
        return FALSE;
    memset(COM_Links, 0, maxlink*sizeof(*COM_Links));
    COM_MaxLinks = maxlink;
    COM_NLinks = 0;

        // Init packets.
    NumIPXPackets = NUMINPACKETS + maxlink + 1;
    IPXPackets = IPX_AllocPackets(NumIPXPackets, MAXPACKETSIZE);
    if (IPXPackets == NULL) {
        DISPOSE(COM_Links);
        return FALSE;
    }
        // Assign out packets to links.
    for (i = 0; i < maxlink; i++) {
        COM_Links[i].ipx = IPX_PACKET(IPXPackets, NUMINPACKETS + i);
    }
        // Open socket.
    IPXAddress.socket = IPX_FlipWord(socket);
    IPX_OpenSocket(0, &IPXAddress.socket);

        // Init in packets.
    for (i = 0; i < NUMINPACKETS; i++) {
            // Setup receive socket.
        IPX_InitInPacket(IPX_PACKET(IPXPackets,i), IPXAddress.socket);
            // And listen on it.
        IPX_ListenForPacket(&IPX_PACKET(IPXPackets,i)->ecb);
    }
    return TRUE;
}
Ejemplo n.º 2
0
/** InitializeNetwork

    Initialize the whole network subsystem. Do IPX installation check,
    determine maximum driver packet size and allocate buffer that has to be in
    low memory in order to be accessible by the IPX network driver. Open our
    socket on dynamically assigned port. Return string error description, or
    nullptr if all went well.

    Memory layout of low memory:
    +--------------------------------+
    |                                |
    | buffer for receiving packets,  |
    | sized dynamically              |
    |                                |
    |--------------------------------|
    | buffer for sending packet      |
    | (1 fragment descriptor -       |
    |  maximum size)                 |
    +--------------------------------|
    | our local ipx address          |
    +--------------------------------+
*/
const char *InitializeNetwork()
{
    if (!IPX_IsInstalled())
        return "IPX compatible network not detected.";

    if (m_lowMemory)      /* if this isn't nullptr we're initialized already */
        return nullptr;

    /* -1 cause DOSBox actually rejects packets of max size */
    if ((m_maxPacketSize = IPX_GetMaximumPacketSize() - 1) < (int)sizeof(IPX_Header) + 128)
        return "Insufficient IPX packet size.";

    WriteToLog("IPX maximum packet size is %d.", m_maxPacketSize);
    /* allocate 1 more byte for receiving buffer just in case (DOSBox receive() allows full size) */
    int lowMemorySize = MAX_RECV_PACKETS * (sizeof(ECB) + (m_maxPacketSize + 1));
    m_sendPacket = (SWOSPP_Packet *)lowMemorySize;
    lowMemorySize += sizeof(ECB) + m_maxPacketSize + 1 + sizeof(IPX_Address);
    m_lowMemory = (char *)AllocateLowMemory(lowMemorySize);
    if (!m_lowMemory)
        return "Failed to allocate DOS memory.";

    WriteToLog("%d bytes of low memory allocated, at %#x", lowMemorySize, m_lowMemory);
    /* got the memory, now initialize it and set up all the pointers */
    memset(m_lowMemory, 0, lowMemorySize);
    /* initialize send buffer, we can only send 1 max size descriptor anyway */
    m_sendPacket = (SWOSPP_Packet *)(m_lowMemory + (int)m_sendPacket);
    m_sendPacket->ecb.fragmentCount = 1;
    m_sendPacket->ecb.fragDesc[0].address[0] = (char *)(&m_sendPacket->ipx) - m_lowMemory;
    m_sendPacket->ecb.fragDesc[0].address[1] = (uint)m_lowMemory >> 4;

    /* get the port dynamically */
    if ((m_socketId = IPX_OpenSocket()) == -1) {
        FreeLowMemory(m_lowMemory);
        m_lowMemory = nullptr;
        return "Failed to open socket.";
    }

    /* and finally, space for our IPX address */
    m_ourAddress = IPX_GetInterNetworkAddress((char *)m_sendPacket + sizeof(ECB) + m_maxPacketSize + 1);
    m_ourAddress->socket = m_socketId;
    HexDumpToLog((char *)m_ourAddress, sizeof(IPX_Address), "our IPX address");

    /* set up receiving ECBs */
    for (int i = 0; i < MAX_RECV_PACKETS; i++) {
        m_packets[i] = (SWOSPP_Packet *)(m_lowMemory + i * (sizeof(ECB) + m_maxPacketSize));
        m_packets[i]->ecb.socketNumber = m_socketId;
        m_packets[i]->ecb.fragmentCount = 1;
        m_packets[i]->ecb.fragDesc[0].address[0] = (uint)&m_packets[i]->ipx - (uint)m_lowMemory;
        m_packets[i]->ecb.fragDesc[0].address[1] = (uint)m_lowMemory >> 4;
        m_packets[i]->ecb.fragDesc[0].size = m_maxPacketSize;
        IPX_Listen((ECB *)m_packets[i]);
    }

    /* set up broadcast node */
    CopyAddress(&m_broadcastAddress, m_ourAddress);
    memset(m_broadcastAddress.node, -1, sizeof(m_broadcastAddress.node));

    /* finish setting up sending ECB */
    m_sendPacket->ecb.socketNumber = m_socketId;
    m_sendPacket->verifyStamp = 'SWPP';
    CopyAddress(&m_sendPacket->ipx.source, m_ourAddress);
    m_clientAckIds = (ClientAckId *)qAlloc(MAX_CONNECTIONS * sizeof(ClientAckId));
    m_numClients = 0;

    /* phew... all OK */
    return nullptr;
}