tags:

views:

11

answers:

1

The following works without error on OSX 10.6, but fails in the iphone simulator using SDK 4.1

#include <arpa/inet.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/tcp.h>
#include <sys/un.h>
#include <string.h>

int main(void) {

    int sock = socket(AF_UNIX, SOCK_DGRAM, 0);

    struct sockaddr_un sock_addr;

    memset(&sock_addr, 0, sizeof(struct sockaddr_un));

    sock_addr.sun_family = AF_UNIX;
    strcpy(sock_addr.sun_path, "/tmp/sock");

    int err = bind(sock, (struct sockaddr*)&sock_addr, sizeof(struct sockaddr_un));
    if(err == -1) {
        perror("bind: ");
    }
}

Error is "Address family not supported by protocol family"

Any ideas?

A: 

You really need to check sock already - most likely, the socket creation is what failed already.

My guess is that AF_UNIX/SOCK_DGRAM is not supported; try SOCK_STREAM instead.

Martin v. Löwis
Thanks - I re-ran it checking "sock" and it was a valid socket. You're probably right that it isn't supported, given the restricted filesystem access. SOCK_STREAM failed same way.
jsheehy
I suggest to try socketpair(2). If that fails, you know that AF_UNIX likely isn't supported. If it succeeds, you can use getsockname to find out what legal names for AF_UNIX might be.
Martin v. Löwis