uocis  CIS 432/532 Introduction to Computer Networks - Fall 2003


Using socket(2)

The socket() call allocates a socket data structure within the kernel. It returns a descriptor that will be used to refer to the socket in later function calls.

PF_UNIX specifies that this will be a Unix Domain Socket, while SOCK_DGRAM specifies that this will be a connectionless, datagram socket.


#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>

...

int s;
s = socket (PF_UNIX, SOCK_DGRAM, 0);
if (s < 0) perror ("socket() failed");


Created by: Daniel Stutzbach December 15, 2003