CITS3002 Computer Networks  
prev
next CITS3002 help3002 CITS3002 schedule  

Naming Sockets

When initially created a socket is unbound (it has no addresses associated with it).

Communication cannot occur on an unbound socket - without a name for the process owning the socket, the kernel cannot demultiplex packets to the correct socket. The bind() routine provides an address (a name) to the local end of the socket.

sockaddr

// Socket address, UNIX style.  
struct sockaddr {
     u_short sa_family;        // address family 
     char    sa_data[108];     // up to 108 bytes of addr 
};

// Socket address, internet style.  
struct sockaddr_in {
     short   sin_family;       // AF_INET 
     u_short sin_port;         // 16-bit port number 
     struct  in_addr sin_addr; // 32-bit netid/hostid 
     char    sin_zero[8];      // unused 
};

    ....
    bind(sd, socket_addr, sizeof(socket_addr));
    ....




CITS3002 Computer Networks, Lecture 8, Transport layer protocols and APIs, p12, 24th April 2024.