Code: Select all
struct sockaddr_in {
        unsigned short sin_family; // REVIEW: is this correct ?
        unsigned short sin_port; // use htons()
        unsigned char sin_addr[4];
        char    sin_zero[8];
};
int sceNetInetConnect(SOCKET s, const void *name, int namelen);
int ConnectToTcpAddr (unsigned long host, int port) {
    int sock, err;
    struct sockaddr_in addr;
    _memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    *(u32*)addr.sin_addr = htonl(host);
    sock = sceNetInetSocket(AF_INET, SOCK_STREAM, 0);
    if(sock < 0) {
        printf("Socket error %i\n", sceNetInetGetErrno());
    } else {
        printf("Socket %i ok\n", sock);
    }
    err = sceNetInetConnect(sock, &addr, sizeof(addr));
    if (err < 0) {
        printf("Connect error %i\n", sceNetInetGetErrno());
    } else {
        printf("Connect ok\n");
    }
    return sock;
}
(192.168.0.1)
Code: Select all
Socket 8 ok
Connect error 106
which doesnt make much sense to me unless the prototype for sceNetInetConnect is wrong or the struct for sockaddr_in is wrong