DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Programming with sockets

Selecting specific protocols

If the third argument to the socket call is 0, socket will select a default protocol to use with the returned socket of the type requested. The default protocol is usually correct, and alternate choices are not usually available. However, when using ``raw'' sockets to communicate directly with lower-level protocols or hardware interfaces, the protocol argument may be important for setting up demultiplexing. For example, raw sockets in the Internet domain may be used to implement a new protocol above IP, and the socket will receive packets only for the protocol specified. To obtain a particular protocol, determine the protocol number defined within the protocol domain. For the Internet domain, use one of the library routines such as getprotobyname (discussed in ``Supporting routines''):

   #include <sys/types.h>
   #include <sys/socket.h>
   #include <netinet/in.h>
   #include <netdb.h>
    ...
   pp = getprotobyname("newtcp");
   s = socket(AF_INET, SOCK_STREAM, pp->p_proto);
This would result in a socket s using a stream based connection, but with protocol type of ``newtcp'' instead of the default ``tcp''.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004