0

Okay so I am working on a piece of software that connects to a server I made that sits on my home computer. I had my cousin that works in silicon valley take a look at it and he can't figure out why it isn't working. I am using the winsockx.h header because the software will be running on an Xbox 360 console but the header is designed to function the same way as the standard winsock headers.

I have port 9001 forwarded and setup for my home computer so the setup shouldn't be a problem. I have also been told that my server should function properly but that I should have the main listener on a seperate thread so multiple clients can be handled at the same time.

FYI: When I call DbgPrint it sends data to a debug moniter called xbWatson and it will also detect errors and show them on the screen.

Here are the 2 main screenshots focusing on the issue.. Debug Moniter: http://i.gyazo.com/b4c5e90b427113992fa02cdb3c73e7e2.png & Where the code breaks: http://i.gyazo.com/5942967dd8456f4f194107bfce1d2b4c.png

VOID Connect()
{
    DbgPrint("-- Creating XNetStartupParams variable 'pXNSP'... ");
    XNetStartupParams pXNSP;
    DbgPrint("Done!\n");
    DbgPrint("-- Allocating variable 'pXNSP'... ");
    memset(&pXNSP, 0, sizeof(XNetStartupParams));
    DbgPrint("Done!\n");
    DbgPrint("-- Configuring Size of our 'pXNSP' structure... ");
    pXNSP.cfgSizeOfStruct = sizeof(XNetStartupParams);
    DbgPrint("Done!\n");
    DbgPrint("-- Configuring Flags of our 'pXNSP' variable... ");
    pXNSP.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
    DbgPrint("Done!\n");
    DbgPrint("-- Starting XNet using our 'pXNSP' variable... ");
    XNetStartup(&pXNSP);
    DbgPrint("Done!\n");

    DbgPrint("-- Creating WSADATA variable 'lpWSADATA'... ");
    WSADATA lpWSADATA;
    DbgPrint("Done!\n");
    DbgPrint("-- Starting WSA using our 'lpWSADATA' variable... ");
    WSAStartup(MAKEWORD(2, 2), &lpWSADATA);
    DbgPrint("Done!\n");

    DbgPrint("-- Creating SOCKADDR_IN variable 'SocketAddress'... ");
    SOCKADDR_IN SocketAddress;
    DbgPrint("Done!\n");

    DbgPrint("-- Creating a socket and returning it to our 'ConnectSocket' variable... ");
    ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    DbgPrint("Done!\n");
    DbgPrint("-- Enabling our broadcast... ");
    BOOL bBroadcast = TRUE;
    DbgPrint("Done!\n");
    DbgPrint("-- Optimizing our SOCKET variable 'ConnectSocket'... ");
    setsockopt(ConnectSocket, SOL_SOCKET, 0x5801, (PCHAR)&bBroadcast, 4);
    DbgPrint("Done!\n");

    DbgPrint("-- Configuring port of our 'SocketAddress' variable... ");
    SocketAddress.sin_port = htons(9001);
    DbgPrint("Done!\n");
    DbgPrint("-- Configuring ipv4 address of our 'SocketAddress' variable... ");
    SocketAddress.sin_addr.S_un.S_un_b.s_b1 = Server[0];
    SocketAddress.sin_addr.S_un.S_un_b.s_b2 = Server[1];
    SocketAddress.sin_addr.S_un.S_un_b.s_b3 = Server[2];
    SocketAddress.sin_addr.S_un.S_un_b.s_b4 = Server[3];
    DbgPrint("Done!\n");
    DbgPrint("-- Configuring family of our 'SocketAddress' variable... ");
    SocketAddress.sin_family = AF_INET;
    DbgPrint("Done!\n");

    DbgPrint("-- Creating integer variable 'SocketAddressSize'... ");
    INT SocketAddressSize = sizeof(SocketAddress);
    DbgPrint("Done!\n");

    for(;;)
    {
        DbgPrint("-- Checking for socket errors in our connection... ");
        if(connect(ConnectSocket, (PSOCKADDR)&SocketAddress, SocketAddressSize) == SOCKET_ERROR)
        {
            DbgPrint("Done (w/ errors)!\n");
            Error = FALSE;
            Authed = FALSE;
            return;
        }
        else
        {
            DbgPrint("Done (w/o errors)!\n");
            return;
        }
    }
}

VOID Disconnect()
{
    closesocket(ConnectSocket);
}

VOID Auth()
{
    DbgPrint("[Skylight] Authorization Started:\n");
    DbgPrint("- Connecting to server:\n");
    Connect();
    DbgPrint("- Configuring our 'ServerRequest' variable... ");
    ServerRequest.Version = 1;
    ServerRequest.Key = 9001;
    ServerRequest.Req = (REQUEST)1;
    DbgPrint("Done!\n");
    DbgPrint("- Creating byte[0x10] variable 'CPUKey'... ");
    BYTE CPUKey[0x10];
    DbgPrint("Done!\n");
    DbgPrint("- Getting/Storing CPU Key from system... ");
    UINT64 addr = 0x8000000000000000ULL | ((DWORD)MmGetPhysicalAddress(CPUKey) & 0xFFFFFFFF);
    HvxGetVersions( 0x72627472, 5, 0x20, addr, 0x10 );
    DbgPrint("Done!\n");
    DbgPrint("- Sending our 'CPUKey' variable to the server... ");
    send(ConnectSocket, (PCHAR)&CPUKey, 0x10, NULL);
    DbgPrint("Done!\n");
    DbgPrint("- Freeing our 'CPUKey' variable... ");
    free(CPUKey);
    DbgPrint("Done!\n");
    DbgPrint("- Waiting for authorization response from the server... ");
    recv(ConnectSocket, (PCHAR)&Authed, 4, NULL);
    DbgPrint("Done!\n");
    DbgPrint("- Disconnecting from server... ");
    Disconnect();
    DbgPrint("Done!\n"); DbgPrint("\n");
}
Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134
Joshe343
  • 65
  • 1
  • 10
  • Just so you know, the main thread in the source calls "Auth" and "Auth" is what calls "Connect" and "Disconnect". – Joshe343 Oct 02 '14 at 22:39
  • 1
    I don't think your given code matches your screenshot. For example, according to your code `Creating integer ...` should happen immediately after `Configuring family ...` but that's not what your screenshot shows. – Greg Hewgill Oct 02 '14 at 22:42
  • I changed it a bit, it shouldn't make a difference though. The only thing is that `SocketAddressSize` was set to `sizeof(SOCKADDR_IN)`. – Joshe343 Oct 02 '14 at 22:51

0 Answers0