I am getting trouble comprehending the bind() function when it comes to Unix Domain Electrical sockets.
address.sun_family = AF_UNIX addrlen = sizeof(address.sun_family) + strlen(SOCK_PATH) . . . bind(socket_fd, (struct sockaddr *) &address, addrlen) != )
When I understand presently, this takes the socket_fd (situated within the processes namespace) which was produced with socket(), and "is applicable" the address information found in address towards the socket. Basically creating it to ensure that other processes may use it.... I believe that's correct.
Things I do not understand is the requirement for the addrlen argument. This is actually the entire address structure without leading/trailing null bytes. Correct? Is argument essential to tell bind() the number of bytes to see from address???
Simply put, bind states somewhere :
okay, to any extent further, any packet with destination ought to be submitted to my socket_fd, in order to read them.
addrlen argument identifies the size from the structure because various kinds of structure (of various dimensions) could be passed. For instance,
struct sockaddr_in*. A "common" structure is passed rather,
struct sockaddr*, so
bind doesn't know what's the real kind of your structure. For this reason you need to pass the space.
PS: I am sure you meant process address space instead of process namespace.
Unsure why your addrlen is placed such as this, the rightOrtypical technique is:
memset(&addr, , sizeof(struct sockaddr_not)) /* Obvious structure */ addr.sun_family = AF_UNIX strncpy(addr.sun_path, MY_SOCK_PATH, sizeof(addr.sun_path) - 1) if (bind(sfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_not)) == -1)
note using sizeof(), no strlen/addrlen expected