Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

636 Advanced IPC Chapter 17


socket socket

server process client process

sun_path

Figure 17.6Client and server sockets beforeaconnect

Figure17.6 shows a client process and a server process beforeaconnection exists
between the two. The server has bound its socket to asockaddr_unaddress and is
listening for connection requests. Figure17.7 shows the unique connection between the
client and server after the server has accepted the client’s connection request.

socket socket socket

server process client process

sun_path

Figure 17.7 Client and server sockets after aconnect

We will now develop three functions that can be used to create unique connections
between unrelated processes running on the same machine. These functions mimic the
connection-oriented socket functions discussed in Section 16.4. We use UNIX domain
sockets for the underlying communication mechanism here.

#include "apue.h"
int serv_listen(const char *name);
Returns: file descriptor to listen on if OK, negative value on error
int serv_accept(int listenfd,uid_t *uidptr);

Returns: new file descriptor if OK, negative value on error
int cli_conn(const char *name);
Returns: file descriptor if OK, negative value on error
Free download pdf