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
Here are detailed descriptions of the utilities for accessing the protocols database. These are declared in `netdb.h'.
You can use
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.
getprotobynamefunction returns information about the network protocol named name. If there is no such protocol, it returns a null pointer.
getprotobynumberfunction 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
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
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.