Member Avatar for carlpike

Hello everyone. I am having an issue with flash style connection

So I start off by connecting to port 843 and requesting a
<policy-file-request/>

The server sends me this:

<cross-domain-policy>
<site-control permitted-cross-domain-policies="master-… />
<allow-access-from domain="*website.com" secure="false" />
<allow-access-from domain="*website.com" to-ports="443-49151"/>
</cross-domain-policy>

Since it is non secure, I try to connect to port 443 via connect. However, my connection attempt is declined. What do I do to make it accepted?

Here is what I am doing

Init Winsock
Connect to server port 843
Request policy File
Receive Policy file
Connect to server port 443... declined.

Shouldn't the server accept me as it is non secure and I have received a policy file? I am confused

Here is my sloppy code:

#include <winsock2.h>
#include <windows.h>
#include <stdio.h>

int main()
{
    WSADATA wsaData;

    if( WSAStartup(MAKEWORD(1, 1), &wsaData) != 0 )
    {
        WSACleanup();
        return 1;
    }

    LPHOSTENT hostEntry = gethostbyname("www.mywebsite.com");
    if( !hostEntry )
    {
        WSACleanup();
        return 2;
    }

    SOCKET theSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if( theSocket == INVALID_SOCKET )
    {
        return 3;
    }

    SOCKADDR_IN sin;
    sin.sin_family = AF_INET;
    sin.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
    sin.sin_port = htons(843);

    if( connect(theSocket, (LPSOCKADDR)&sin, sizeof(struct sockaddr)) == SOCKET_ERROR )
    {
        WSACleanup();
        return 4;
    }

    printf("Connected on port 843\n");

    char buffer[256] = "";
    char policyrequest[] = "<policy-file-request/>\0";
    if( send(theSocket, policyrequest, 23, 0) == 23 )
    {
        if( recv(theSocket, buffer, 256, 0) > 0 )
        {
            printf("CLIENT: %s\nSERVER: %s\n", policyrequest, buffer);
            SOCKET sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
            if( sock == INVALID_SOCKET ) { WSACleanup; return 99; }
            sin.sin_port = htons(443);
            closesocket(theSocket);
            if( connect(sock, (LPSOCKADDR)&sin, sizeof(struct sockaddr)) == SOCKET_ERROR )
            {
                printf("%d\n", WSAGetLastError());
                WSACleanup();
                return 100;
            }
        }
    }

    closesocket(theSocket);
    WSACleanup();
    return 0;
}

i try to run your code to C++ and show some following errors


Linking...
website.obj : error LNK2001: unresolved external symbol __imp__WSAGetLastError@0
website.obj : error LNK2001: unresolved external symbol __imp__closesocket@4
website.obj : error LNK2001: unresolved external symbol __imp__recv@16
website.obj : error LNK2001: unresolved external symbol __imp__send@16
website.obj : error LNK2001: unresolved external symbol __imp__connect@12
website.obj : error LNK2001: unresolved external symbol __imp__htons@4
website.obj : error LNK2001: unresolved external symbol __imp__socket@12
website.obj : error LNK2001: unresolved external symbol __imp__gethostbyname@4
website.obj : error LNK2001: unresolved external symbol __imp__WSACleanup@0
website.obj : error LNK2001: unresolved external symbol __imp__WSAStartup@8
Debug/website.exe : fatal error LNK1120: 10 unresolved externals
Error executing link.exe.

website.exe - 11 error(s), 0 warning(s)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.