kern/73852: Not htonl() but ntohl()

KIYOHARA Takashi kiyohara at
Thu Nov 11 21:10:28 PST 2004

>Number:         73852
>Category:       kern
>Synopsis:       Not htonl() but ntohl()
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          open
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Fri Nov 12 05:10:27 GMT 2004
>Originator:     KIYOHARA Takashi
see sys/net/if_fwsubr.c::firewire_input().
Why does it perform htonl() at the time of input of a packet?
An input packet is a network-byte-order. We should use ntohl().
firewire_input(struct ifnet *ifp, struct mbuf *m, uint16_t src)

      ... snip ...

	 * Byte swap the encapsulation header manually.
-	enc->ul[0] = htonl(enc->ul[0]);
+	enc->ul[0] = ntohl(enc->ul[0]);

	if (enc->unfrag.lf != 0) {
		m = m_pullup(m, 2*sizeof(uint32_t));
		if (!m)
		enc = mtod(m, union fw_encap *);
-		enc->ul[1] = htonl(enc->ul[1]);
+		enc->ul[1] = ntohl(enc->ul[1]);
		m = firewire_input_fragment(fc, m, src);


More information about the freebsd-bugs mailing list