Binding A Socket Address To The Server Process's Socket - HP Rp3440-4 - 9000 - 0 MB RAM Programmer's Manual

Bsd sockets interface programmer’s guide
Hide thumbs Also See for Rp3440-4 - 9000 - 0 MB RAM:
Table of Contents

Advertisement

Using Internet Stream Sockets
Writing the Server Process
When to Create Sockets
The server process should create a socket before any other BSD Sockets
system calls. Refer to the socket(2) man page for more information on
socket.
Binding a Socket Address to the Server
Process's Socket
After your server process has created a socket, it must call bind to bind a
socket address. Until an address is bound to the server socket, other
processes have no way to reference it.
The server process must bind a specific port address to this socket, which
is used for listening. Otherwise, a client process would not know what
port to connect to for the desired service.
Set up the address structure with a local address before you make a
bind call. Use a wildcard address so your server process does not have to
look up its own internet address. bind and its parameters are described
in the following table.
Include files:
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
System call:
bind (s, addr, addrlen)
int s;
struct sockaddr *addr;
int addrlen;
Parameter
s
socket descriptor of local
socket
addr
socket address
addrlen
length of socket address
Function result: 0 if bind is successful, –1 if failure occurs.
36
Description of
Contents
INPUT Value
socket descriptor of socket
to be bound
pointer to address to be
bound to s
size of struct
sockaddr_in
Chapter 2

Advertisement

Table of Contents
loading

Table of Contents