The communications protocol used with a socket controls low-level details of how data is exchanged. For example, the protocol implements things like checksums to detect errors in transmissions, and routing instructions for messages. Normal user programs have little reason to mess with these details directly.
The default communications protocol for the Internet namespace depends on the communication style. For stream communication, the default is TCP ("transmission control protocol"). For datagram communication, the default is UDP ("user datagram protocol"). For reliable datagram communication, the default is RDP ("reliable datagram protocol"). You should nearly always use the default.
Internet protocols are generally specified by a name instead of a
number. The network protocols that a host knows about are stored in a
database. This is usually either derived from the file
`/etc/protocols', or it may be an equivalent provided by a name
server. You look up the protocol number associated with a named
protocol in the database using the getprotobyname
function.
Here are detailed descriptions of the utilities for accessing the protocols database. These are declared in `netdb.h'.
char *p_name
char **p_aliases
int p_proto
socket
.
You can use getprotobyname
and getprotobynumber
to search
the protocols database for a specific protocol. The information is
returned in a statically-allocated structure; you must copy the
information if you need to save it across calls.
getprotobyname
function returns information about the
network protocol named name. If there is no such protocol, it
returns a null pointer.
getprotobynumber
function returns information about the
network protocol with number protocol. If there is no such
protocol, it returns a null pointer.
You can also scan the whole protocols database one protocol at a time by
using setprotoent
, getprotoent
, and endprotoent
.
Be careful in using these functions, because they are not reentrant.
If the stayopen argument is nonzero, this sets a flag so that
subsequent calls to getprotobyname
or getprotobynumber
will
not close the database (as they usually would). This makes for more
efficiency if you call those functions several times, by avoiding
reopening the database for each call.
Go to the first, previous, next, last section, table of contents.