the following example code - gaken from samples/net/simple fails.
I want to bind only to INADDR_LOOPBACK.
Code: Select all
    uint16_t port = 10000;
    int sock;
    int ret;
    struct sockaddr_in name;
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if(sock < 0)
    {
        return;
    }
    name.sin_port =  htons(port);
    name.sin_family = AF_INET;
    //name.sin_addr.s_addr = htonl (INADDR_LOOPBACK); // fails - why?
    name.sin_addr.s_addr = htonl(INADDR_ANY); // works...
    ret = bind(sock, (struct sockaddr *) &name, sizeof(name));
    if(ret < 0)
    {
       printf( "bind failed...\n" );
        return;
    }