Hi,
I am quite new to the world of Linux and have a little problem in understanding certain things about UNIX-Sockets (AF_LOCAL/PF_LOCAL) that are stored in the file system (respectivly looking for confirmation of some points which I believe to have finally understood).
I have two applications which runs on a local machine and are in a client-server relationship. The server bounds itself to the UNIX-Socket and waits for clients to connect it.
Then something happens which I am not very familiar with. It seems like it that the server creates a file descriptor in the virtual user space (according to the man pages) and afterwards sends the client this address to let him know where to send data that a directed to the server. After this informatio exchange client and server are communication directly with each other and it seems like the unix-socket is only used for the initial connection build up.
At least that is what I came up with trying to understand undocumented source code.
So das the above mentioned any sense? I found very few information regarding the use of those sockets which are created in the virtual namespache for local interprocess communication. So I hope i can get somewhat of a conformation or a guidence if the stuff I wrote above is totally wrong.
Here an example of the server where the address is set to the client:
Code:
struct sock_data {
int fd;
struct sockaddr_un sock;
};
static void send_sock(int fd, void *packet, int len, void *data)
{
struct sock_data *mine = data;
int err;
err = sendto(mine->fd, packet, len, 0, (struct sockaddr *) &mine->sock,
sizeof(mine->sock));
if(err != len){
fprintf(stderr, "send_sock sending to fd %d ", mine->fd);
perror("");
}
}
The client receives this "address"-message and then write (so it seems) to the file descriptor the server has created:
Code:
sendto(fd, &data, data_len, 0, (struct sockaddr*) dst_addr, sizeof(struct sockaddr_un));