In article <5182db8a$0$12762$
bbae...@news.suddenlink.net>,
/etc/protocols lists the protocol numbers for protocols running on top of IP,
including UDP which is protocol 17.
/etc/services lists the port numbers for protocols running on top of TCP
and/or UDP, including bootp which is ports 67 and 68. (I'm not sure why it
needs two ports; I've never really looked at it.)
A bootp packet will have 17 in the protocol slot of its IP header,
identifying the next header as UDP, and 67 or 68 in the destination
and/or source port of the UDP header.
When you create a UDP socket, you do something like this:
s = socket(AF_INET, SOCK_DGRAM, 0);
and the kernel knows that the protocol will be UDP, because that's the
only protocol that can be used with the combination of AF_INET and
SOCK_DGRAM. You can pass IPPROTO_UDP as the third argument instead, if
you want to be explicit.
The point is... if you're not using raw sockets, you don't need to know
the protocol number. And even if you are making your own IP packets from
scratch, you don't need to use /etc/protocols or any of the the
getprotoby* functions. Just hardcode 17. Seriously, it's not like it can
ever change. If you want to make it look pretty use the IPPROTO_UDP
macro.
The same applies to port numbers you want to look up in /etc/services
with getservbyname(). They're all set in stone before they show up in
your /etc/services file.
You can call getprotobyname("udp") and getservbyname("bootps", "udp")
and you'll probably get structs with p_proto==17 and s_port==htons(67).
But you shouldn't do that. Just use the IPPROTO_UDP and 67. The get*by*
functions just add pointless overhead and an additional point of
potential failure.
--
Alan Curry