Use uint32_t instead of n_long and n_time, and uint16_t instead of n_short.

Add a note next to fields in network format.

The n_* types are not enough for compiler checks on endianness, and their
use often requires an otherwise unnecessary #include <netinet/in_systm.h>

The typedef in in_systm.h are still there.
This commit is contained in:
Luigi Rizzo 2009-02-13 15:14:43 +00:00
parent 4f6b49338e
commit d685b6ee05
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=188578
7 changed files with 29 additions and 22 deletions

View File

@ -52,7 +52,7 @@ typedef u_int32_t n_long; /* long as received from the net */
typedef u_int32_t n_time; /* ms since 00:00 GMT, byte rev */
#ifdef _KERNEL
n_time iptime(void);
uint32_t iptime(void);
#endif
#endif

View File

@ -150,10 +150,10 @@ struct ip_timestamp {
ipt_flg:4; /* flags, see below */
#endif
union ipt_timestamp {
n_long ipt_time[1];
uint32_t ipt_time[1]; /* network format */
struct ipt_ta {
struct in_addr ipt_addr;
n_long ipt_time;
uint32_t ipt_time; /* network format */
} ipt_ta[1];
} ipt_timestamp;
};

View File

@ -165,7 +165,7 @@ icmp_init(void)
* in response to bad packet ip.
*/
void
icmp_error(struct mbuf *n, int type, int code, n_long dest, int mtu)
icmp_error(struct mbuf *n, int type, int code, uint32_t dest, int mtu)
{
INIT_VNET_INET(curvnet);
register struct ip *oip = mtod(n, struct ip *), *nip;
@ -852,7 +852,10 @@ icmp_send(struct mbuf *m, struct mbuf *opts)
(void) ip_output(m, opts, NULL, 0, NULL, NULL);
}
n_time
/*
* Return milliseconds since 00:00 GMT in network format.
*/
uint32_t
iptime(void)
{
struct timeval atv;

View File

@ -68,15 +68,15 @@ struct icmp {
u_char ih_pptr; /* ICMP_PARAMPROB */
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq {
n_short icd_id;
n_short icd_seq;
uint16_t icd_id; /* network format */
uint16_t icd_seq; /* network format */
} ih_idseq;
int ih_void;
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
struct ih_pmtu {
n_short ipm_void;
n_short ipm_nextmtu;
uint16_t ipm_void; /* network format */
uint16_t ipm_nextmtu; /* network format */
} ih_pmtu;
struct ih_rtradv {
@ -97,9 +97,13 @@ struct icmp {
#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
union {
struct id_ts { /* ICMP Timestamp */
n_time its_otime; /* Originate */
n_time its_rtime; /* Receive */
n_time its_ttime; /* Transmit */
/*
* The next 3 fields are in network format,
* milliseconds since 00:00 GMT
*/
uint32_t its_otime; /* Originate */
uint32_t its_rtime; /* Receive */
uint32_t its_ttime; /* Transmit */
} id_ts;
struct id_ip {
struct ip idi_ip;
@ -127,7 +131,7 @@ struct icmp {
* ip header length.
*/
#define ICMP_MINLEN 8 /* abs minimum */
#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */
#define ICMP_TSLEN (8 + 3 * sizeof (uint32_t)) /* timestamp */
#define ICMP_MASKLEN 12 /* address mask */
#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */
#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
@ -202,7 +206,7 @@ struct icmp {
(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
#ifdef _KERNEL
void icmp_error(struct mbuf *, int, int, n_long, int);
void icmp_error(struct mbuf *, int, int, uint32_t, int);
void icmp_input(struct mbuf *, int);
void icmp_init(void);
int ip_next_mtu(int, int);

View File

@ -105,7 +105,7 @@ ip_dooptions(struct mbuf *m, int pass)
struct in_ifaddr *ia;
int opt, optlen, cnt, off, code, type = ICMP_PARAMPROB, forward = 0;
struct in_addr *sin, dst;
n_time ntime;
uint32_t ntime;
struct sockaddr_in ipaddr = { sizeof(ipaddr), AF_INET };
/* Ignore or reject packets with IP options. */
@ -320,7 +320,7 @@ ip_dooptions(struct mbuf *m, int pass)
break;
case IPOPT_TS_TSANDADDR:
if (off + sizeof(n_time) +
if (off + sizeof(uint32_t) +
sizeof(struct in_addr) > optlen) {
code = &cp[IPOPT_OFFSET] - (u_char *)ip;
goto bad;
@ -337,7 +337,7 @@ ip_dooptions(struct mbuf *m, int pass)
break;
case IPOPT_TS_PRESPEC:
if (off + sizeof(n_time) +
if (off + sizeof(uint32_t) +
sizeof(struct in_addr) > optlen) {
code = &cp[IPOPT_OFFSET] - (u_char *)ip;
goto bad;
@ -355,8 +355,8 @@ ip_dooptions(struct mbuf *m, int pass)
goto bad;
}
ntime = iptime();
(void)memcpy(cp + off, &ntime, sizeof(n_time));
cp[IPOPT_OFFSET] += sizeof(n_time);
(void)memcpy(cp + off, &ntime, sizeof(uint32_t));
cp[IPOPT_OFFSET] += sizeof(uint32_t);
}
}
if (forward && V_ipforwarding) {

View File

@ -34,7 +34,7 @@
#define _NETINET_TCP_DEBUG_H_
struct tcp_debug {
n_time td_time;
uint32_t td_time; /* network format */
short td_act;
short td_ostate;
caddr_t td_tcb;

View File

@ -581,7 +581,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
} else
#endif /* INET6 */
{
xchg(ip->ip_dst.s_addr, ip->ip_src.s_addr, n_long);
xchg(ip->ip_dst.s_addr, ip->ip_src.s_addr, uint32_t);
nth = (struct tcphdr *)(ip + 1);
}
if (th != nth) {
@ -593,7 +593,7 @@ tcp_respond(struct tcpcb *tp, void *ipgen, struct tcphdr *th, struct mbuf *m,
nth->th_sport = th->th_sport;
nth->th_dport = th->th_dport;
}
xchg(nth->th_dport, nth->th_sport, n_short);
xchg(nth->th_dport, nth->th_sport, uint16_t);
#undef xchg
}
#ifdef INET6