Bind to INADDR_LOOPBACK fails

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
monsti
Posts: 13
Joined: Sun Mar 04, 2007 3:21 am
Location: Germany

Bind to INADDR_LOOPBACK fails

Post by monsti »

Hi,

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&#40;sock < 0&#41;
    &#123;
        return;
    &#125;

    name.sin_port =  htons&#40;port&#41;;
    name.sin_family = AF_INET;
    //name.sin_addr.s_addr = htonl &#40;INADDR_LOOPBACK&#41;; // fails - why?
    name.sin_addr.s_addr = htonl&#40;INADDR_ANY&#41;; // works...

    ret = bind&#40;sock, &#40;struct sockaddr *&#41; &name, sizeof&#40;name&#41;&#41;;
    if&#40;ret < 0&#41;
    &#123;
       printf&#40; "bind failed...\n" &#41;;
        return;
    &#125;
Any idea?
Bye,
Monsti
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

The PSP is not Unix... AFAIK it has no loopback interface.
Post Reply