- Be more careful with type sizes (many u_long -> u_int32_t in protocol

structures).
- Use NTOH*() and HTON*() where appropriate.
- Some slight formatting cleanup in a few places.
This commit is contained in:
thorpej 1997-07-18 19:30:33 +00:00
parent d891aff808
commit c5dab54215
14 changed files with 98 additions and 98 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: idp.h,v 1.5 1994/06/29 06:41:28 cgd Exp $ */
/* $NetBSD: idp.h,v 1.6 1997/07/18 19:30:33 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -39,10 +39,10 @@
* Definitions for NS(tm) Internet Datagram Protocol
*/
struct idp {
u_short idp_sum; /* Checksum */
u_short idp_len; /* Length, in bytes, including header */
u_char idp_tc; /* Transport Crontrol (i.e. hop count) */
u_char idp_pt; /* Packet Type (i.e. level 2 protocol) */
u_int16_t idp_sum; /* Checksum */
u_int16_t idp_len; /* Length, in bytes, including header */
u_int8_t idp_tc; /* Transport Crontrol (i.e. hop count) */
u_int8_t idp_pt; /* Packet Type (i.e. level 2 protocol) */
struct ns_addr idp_dna; /* Destination Network Address */
struct ns_addr idp_sna; /* Source Network Address */
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: idp_usrreq.c,v 1.12 1996/10/10 23:25:50 christos Exp $ */
/* $NetBSD: idp_usrreq.c,v 1.13 1997/07/18 19:30:34 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -218,7 +218,7 @@ idp_output(m0, va_alist)
len += sizeof (struct idp);
}
idp->idp_len = htons((u_short)len);
idp->idp_len = htons((u_int16_t)len);
if (idpcksum) {
idp->idp_sum = 0;
@ -251,7 +251,6 @@ idp_ctloutput(req, so, level, name, value)
register struct mbuf *m;
struct nspcb *nsp = sotonspcb(so);
int mask, error = 0;
extern long ns_pexseq;
if (nsp == NULL)
return (EINVAL);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns.h,v 1.9 1996/09/08 14:50:31 mycroft Exp $ */
/* $NetBSD: ns.h,v 1.10 1997/07/18 19:30:35 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -89,24 +89,24 @@
* NS addressing
*/
union ns_host {
u_char c_host[6];
u_short s_host[3];
u_int8_t c_host[6];
u_int16_t s_host[3];
};
union ns_net {
u_char c_net[4];
u_short s_net[2];
u_int8_t c_net[4];
u_int16_t s_net[2];
};
union ns_net_u {
union ns_net net_e;
u_long long_e;
u_int32_t long_e;
};
struct ns_addr {
union ns_net x_net;
union ns_host x_host;
u_short x_port;
u_int16_t x_port;
};
/*
@ -121,7 +121,7 @@ struct sockaddr_ns {
#define sns_port sns_addr.x_port
#ifdef vax
#define ns_netof(a) (*(long *) & ((a).x_net)) /* XXX - not needed */
#define ns_netof(a) (*(int32_t *) & ((a).x_net)) /* XXX - not needed */
#endif
#define ns_neteqnn(a,b) (((a).s_net[0]==(b).s_net[0]) && \
((a).s_net[1]==(b).s_net[1]))

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_cksum.c,v 1.4 1996/03/14 18:44:41 christos Exp $ */
/* $NetBSD: ns_cksum.c,v 1.5 1997/07/18 19:30:36 thorpej Exp $ */
/*
* Copyright (c) 1982, 1992, 1993
@ -49,7 +49,7 @@
#define ADDCARRY(x) { if ((x) > 65535) (x) -= 65535; }
#define FOLD(x) {l_util.l = (x); (x) = l_util.s[0] + l_util.s[1]; ADDCARRY(x);}
u_short
u_int16_t
ns_cksum(m, len)
register struct mbuf *m;
register int len;
@ -78,9 +78,9 @@ ns_cksum(m, len)
* ones-complement add it into the checksum.
*/
#if BYTE_ORDER == BIG_ENDIAN
sum += *(u_char *)w;
sum += *(u_int8_t *)w;
#else
sum += *(u_char *)w << 8;
sum += *(u_int8_t *)w << 8;
#endif
sum += sum;
w = (u_int16_t *)(1 + (char *)w);
@ -131,12 +131,12 @@ ns_cksum(m, len)
goto commoncase;
uuuuglyy:
#if BYTE_ORDER == BIG_ENDIAN
#define ww(n) (((u_char *)w)[n + n + 1])
#define vv(n) (((u_char *)w)[n + n])
#define ww(n) (((u_int8_t *)w)[n + n + 1])
#define vv(n) (((u_int8_t *)w)[n + n])
#else
#if BYTE_ORDER == LITTLE_ENDIAN
#define vv(n) (((u_char *)w)[n + n + 1])
#define ww(n) (((u_char *)w)[n + n])
#define vv(n) (((u_int8_t *)w)[n + n + 1])
#define ww(n) (((u_int8_t *)w)[n + n])
#endif
#endif
sum2 = 0;
@ -185,9 +185,9 @@ uuuuglyy:
commoncase:
if (mlen == -1) {
#if BYTE_ORDER == BIG_ENDIAN
sum += *(u_char *)w << 8;
sum += *(u_int8_t *)w << 8;
#else
sum += *(u_char *)w;
sum += *(u_int8_t *)w;
#endif
}
FOLD(sum);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_error.c,v 1.8 1996/10/13 01:59:55 christos Exp $ */
/* $NetBSD: ns_error.c,v 1.9 1997/07/18 19:30:37 thorpej Exp $ */
/*
* Copyright (c) 1984, 1988, 1993
@ -75,8 +75,8 @@ int
ns_err_x(c)
int c;
{
register u_short *w, *lim, *base = ns_errstat.ns_es_codes;
u_short x = c;
register u_int16_t *w, *lim, *base = ns_errstat.ns_es_codes;
u_int16_t x = c;
/*
* zero is a legit error code, handle specially
@ -156,12 +156,12 @@ ns_error(om, type, param)
if ((u_int)type > NS_ERR_TOO_BIG)
panic("ns_err_error");
ns_errstat.ns_es_outhist[ns_err_x(type)]++;
ep->ns_ep_errp.ns_err_num = htons((u_short)type);
ep->ns_ep_errp.ns_err_param = htons((u_short)param);
ep->ns_ep_errp.ns_err_num = htons((u_int16_t)type);
ep->ns_ep_errp.ns_err_param = htons((u_int16_t)param);
bcopy((caddr_t)oip, (caddr_t)&ep->ns_ep_errp.ns_err_idp, 42);
nip = &ep->ns_ep_idp;
nip->idp_len = sizeof(*ep);
nip->idp_len = htons((u_short)nip->idp_len);
nip->idp_len = htons((u_int16_t)nip->idp_len);
nip->idp_pt = NSPROTO_ERROR;
nip->idp_tc = 0;
nip->idp_dna = oip->idp_sna;
@ -299,11 +299,11 @@ freeit:
}
#ifdef notdef
u_long
u_int32_t
nstime()
{
int s = splclock();
u_long t;
u_int32_t t;
t = (time.tv_sec % (24*60*60)) * 1000 + time.tv_usec / 1000;
splx(s);
@ -318,7 +318,7 @@ struct mbuf *m;
register struct idp *idp = mtod(m, struct idp *);
register struct echo {
struct idp ec_idp;
u_short ec_op; /* Operation, 1 = request, 2 = reply */
u_int16_t ec_op; /* Operation, 1 = request, 2 = reply */
} *ec = (struct echo *)idp;
struct ns_addr temp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_error.h,v 1.6 1995/03/26 20:36:20 jtc Exp $ */
/* $NetBSD: ns_error.h,v 1.7 1997/07/18 19:30:38 thorpej Exp $ */
/*
* Copyright (c) 1984, 1988, 1993
@ -40,11 +40,11 @@
*/
struct ns_errp {
u_short ns_err_num; /* Error Number */
u_short ns_err_param; /* Error Parameter */
u_int16_t ns_err_num; /* Error Number */
u_int16_t ns_err_param; /* Error Parameter */
struct idp ns_err_idp; /* Initial segment of offending
packet */
u_char ns_err_lev2[12]; /* at least this much higher
u_int8_t ns_err_lev2[12]; /* at least this much higher
level protocol */
};
struct ns_epidp {
@ -83,7 +83,7 @@ struct ns_errstat {
int ns_es_badlen; /* calculated bound mismatch */
int ns_es_reflect; /* number of responses */
int ns_es_inhist[NS_ERR_MAX];
u_short ns_es_codes[NS_ERR_MAX];/* which error code for outhist
u_int16_t ns_es_codes[NS_ERR_MAX];/* which error code for outhist
since we might not know all */
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_input.c,v 1.12 1996/10/13 01:59:55 christos Exp $ */
/* $NetBSD: ns_input.c,v 1.13 1997/07/18 19:30:38 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -73,7 +73,7 @@ union ns_net ns_zeronet;
union ns_net ns_broadnet;
struct sockaddr_ns ns_netmask, ns_hostmask;
static u_short allones[] = {-1, -1, -1};
static u_int16_t allones[] = {-1, -1, -1};
struct nspcb nspcb;
struct nspcb nsrawpcb;
@ -285,7 +285,7 @@ idp_ctlinput(cmd, sa, arg)
errp = arg;
ns = &errp->ns_err_idp.idp_dna;
type = errp->ns_err_num;
type = ntohs((u_short)type);
type = ntohs((u_int16_t)type);
}
switch (type) {
@ -315,7 +315,7 @@ struct route idp_sroute;
void
idp_forward(m)
struct mbuf *m;
struct mbuf *m;
{
register struct idp *idp = mtod(m, struct idp *);
register int error, type, code;
@ -383,11 +383,11 @@ struct mbuf *m;
}
}
/* need to adjust checksum */
if (idp->idp_sum!=0xffff) {
if (idp->idp_sum != 0xffff) {
union bytes {
u_char c[4];
u_short s[2];
long l;
u_int8_t c[4];
u_int16_t s[2];
u_int32_t l;
} x;
register int shift;
x.l = 0; x.c[0] = agedelta;
@ -435,8 +435,8 @@ cleanup:
int
idp_do_route(src, ro)
struct ns_addr *src;
struct route *ro;
struct ns_addr *src;
struct route *ro;
{
struct sockaddr_ns *dst;
@ -458,15 +458,15 @@ struct route *ro;
void
idp_undo_route(ro)
register struct route *ro;
register struct route *ro;
{
if (ro->ro_rt) {RTFREE(ro->ro_rt);}
}
void
ns_watch_output(m, ifp)
struct mbuf *m;
struct ifnet *ifp;
struct mbuf *m;
struct ifnet *ifp;
{
register struct nspcb *nsp;
register struct ifaddr *ifa;
@ -492,7 +492,7 @@ struct ifnet *ifp;
break;
}
}
idp->idp_len = ntohl(m0->m_pkthdr.len);
idp->idp_len = ntohs((u_int16_t)m0->m_pkthdr.len);
idp_input(m0, nsp);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_ip.c,v 1.19 1996/10/13 01:59:56 christos Exp $ */
/* $NetBSD: ns_ip.c,v 1.20 1997/07/18 19:30:39 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -289,7 +289,7 @@ nsipoutput(ifp, m, dst, rt)
* Calculate data length and make space
* for IP header.
*/
len = ntohs(idp->idp_len);
len = ntohs(idp->idp_len);
if (len & 1) len++; /* Preserve Garbage Byte */
/* following clause not necessary on vax */
if (3 & (int)m->m_data) {
@ -314,11 +314,11 @@ nsipoutput(ifp, m, dst, rt)
* Fill in IP header.
*/
ip = mtod(m, struct ip *);
*(long *)ip = 0;
*(int32_t *)ip = 0;
ip->ip_p = IPPROTO_IDP;
ip->ip_src = ifn->ifen_src;
ip->ip_dst = ifn->ifen_dst;
ip->ip_len = (u_short)len + sizeof (struct ip);
ip->ip_len = (u_int16_t)len + sizeof (struct ip);
ip->ip_ttl = MAXTTL;
/*
@ -420,7 +420,7 @@ nsip_route(m)
int
nsip_free(ifp)
struct ifnet *ifp;
struct ifnet *ifp;
{
register struct ifnet_en *ifn = (struct ifnet_en *)ifp;
struct route *ro = & ifn->ifen_route;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_output.c,v 1.8 1996/02/13 22:14:01 christos Exp $ */
/* $NetBSD: ns_output.c,v 1.9 1997/07/18 19:30:40 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -149,7 +149,7 @@ gotif:
}
}
if (htons(idp->idp_len) <= ifp->if_mtu) {
if (ntohs(idp->idp_len) <= ifp->if_mtu) {
ns_output_cnt++;
if (ns_copy_output) {
ns_watch_output(m0, ifp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_pcb.c,v 1.11 1996/05/22 13:56:23 mycroft Exp $ */
/* $NetBSD: ns_pcb.c,v 1.12 1997/07/18 19:30:41 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -78,7 +78,7 @@ ns_pcbbind(nsp, nam, p)
struct proc *p;
{
register struct sockaddr_ns *sns;
u_short lport = 0;
u_int16_t lport = 0;
int error;
if (nsp->nsp_lport || !ns_nullhost(nsp->nsp_laddr))
@ -198,7 +198,7 @@ ns_pcbconnect(nsp, nam)
if (ia->ia_ifp == ifp)
break;
if (ia == 0) {
u_short fport = sns->sns_addr.x_port;
u_int16_t fport = sns->sns_addr.x_port;
sns->sns_addr.x_port = 0;
ia = (struct ns_ifaddr *)
ifa_ifwithdstaddr(snstosa(sns));
@ -336,12 +336,12 @@ ns_rtchange(nsp)
struct nspcb *
ns_pcblookup(faddr, lport, wildp)
struct ns_addr *faddr;
u_short lport;
u_int16_t lport;
int wildp;
{
register struct nspcb *nsp, *match = 0;
int matchwild = 3, wildcard;
u_short fport;
u_int16_t fport;
fport = faddr->x_port;
for (nsp = (&nspcb)->nsp_next; nsp != (&nspcb); nsp = nsp->nsp_next) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_pcb.h,v 1.7 1996/02/13 22:14:05 christos Exp $ */
/* $NetBSD: ns_pcb.h,v 1.8 1997/07/18 19:30:42 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -50,8 +50,8 @@ struct nspcb {
struct ns_addr nsp_lastdst; /* validate cached route for dg socks*/
long nsp_notify_param; /* extra info passed via ns_pcbnotify*/
short nsp_flags;
u_char nsp_dpt; /* default packet type for idp_output*/
u_char nsp_rpt; /* last received packet type by
u_int8_t nsp_dpt; /* default packet type for idp_output*/
u_int8_t nsp_rpt; /* last received packet type by
idp_input() */
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: ns_var.h,v 1.5 1996/10/10 23:22:58 christos Exp $ */
/* $NetBSD: ns_var.h,v 1.6 1997/07/18 19:30:43 thorpej Exp $ */
/*
* Copyright (c) 1995 Christos Zoulas. All rights reserved.
@ -30,6 +30,9 @@
*/
#ifdef _KERNEL
extern long ns_pexseq;
extern u_char nsctlerrmap[];
struct socket;
struct nspcb;
struct ifnet;
@ -51,14 +54,14 @@ int ns_ifinit __P((struct ifnet *, struct ns_ifaddr *, struct sockaddr_ns *,
struct ns_ifaddr *ns_iaonnetof __P((struct ns_addr *));
/* ns_cksum.c */
u_short ns_cksum __P((struct mbuf *, int));
u_int16_t ns_cksum __P((struct mbuf *, int));
/* ns_error.c */
int ns_err_x __P((int));
void ns_error __P((struct mbuf *, int, int ));
void ns_printhost __P((struct ns_addr *));
void ns_err_input __P((struct mbuf *));
u_long nstime __P((void));
u_int32_t nstime __P((void));
int ns_echo __P((struct mbuf *));
/* ns_input.c */

View File

@ -1,4 +1,4 @@
/* $NetBSD: sp.h,v 1.5 1994/06/29 06:41:50 cgd Exp $ */
/* $NetBSD: sp.h,v 1.6 1997/07/18 19:30:44 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -40,15 +40,15 @@
*/
struct sphdr {
u_char sp_cc; /* connection control */
u_char sp_dt; /* datastream type */
u_int8_t sp_cc; /* connection control */
u_int8_t sp_dt; /* datastream type */
#define SP_SP 0x80 /* system packet */
#define SP_SA 0x40 /* send acknowledgement */
#define SP_OB 0x20 /* attention (out of band data) */
#define SP_EM 0x10 /* end of message */
u_short sp_sid; /* source connection identifier */
u_short sp_did; /* destination connection identifier */
u_short sp_seq; /* sequence number */
u_short sp_ack; /* acknowledge number */
u_short sp_alo; /* allocation number */
u_int16_t sp_sid; /* source connection identifier */
u_int16_t sp_did; /* destination connection identifier */
u_int16_t sp_seq; /* sequence number */
u_int16_t sp_ack; /* acknowledge number */
u_int16_t sp_alo; /* allocation number */
};

View File

@ -1,4 +1,4 @@
/* $NetBSD: spp_usrreq.c,v 1.17 1997/06/24 02:26:13 thorpej Exp $ */
/* $NetBSD: spp_usrreq.c,v 1.18 1997/07/18 19:30:44 thorpej Exp $ */
/*
* Copyright (c) 1984, 1985, 1986, 1987, 1993
@ -116,9 +116,11 @@ spp_input(m, va_alist)
}
si = mtod(m, struct spidp *);
}
si->si_seq = ntohs(si->si_seq);
si->si_ack = ntohs(si->si_ack);
si->si_alo = ntohs(si->si_alo);
/* Convert some header fields to host format. */
NTOHS(si->si_seq);
NTOHS(si->si_ack);
NTOHS(si->si_alo);
so = nsp->nsp_socket;
if (so->so_options & SO_DEBUG || traceallspps) {
@ -279,9 +281,10 @@ spp_input(m, va_alist)
dropwithreset:
if (dropsocket)
(void) soabort(so);
si->si_seq = ntohs(si->si_seq);
si->si_ack = ntohs(si->si_ack);
si->si_alo = ntohs(si->si_alo);
/* Convert back to network format. */
HTONS(si->si_seq);
HTONS(si->si_ack);
HTONS(si->si_alo);
ns_error(m, NS_ERR_NOSOCK, 0);
if (cb->s_nspcb->nsp_socket->so_options & SO_DEBUG || traceallspps)
spp_trace(SA_DROP, (u_char)ostate, cb, &spp_savesi, 0);
@ -304,9 +307,9 @@ int spprexmtthresh = 3;
*/
int
spp_reass(cb, si, m0)
register struct sppcb *cb;
register struct spidp *si;
register struct mbuf *m0;
register struct sppcb *cb;
register struct spidp *si;
register struct mbuf *m0;
{
register struct spidp_q *p, *q, *si_q;
register struct mbuf *m;
@ -610,7 +613,6 @@ spp_ctlinput(cmd, sa, arg)
void *arg;
{
struct ns_addr *na;
extern u_char nsctlerrmap[];
struct ns_errp *errp = NULL;
struct nspcb *nsp;
struct sockaddr_ns *sns;
@ -656,7 +658,7 @@ spp_ctlinput(cmd, sa, arg)
errp = arg;
na = &errp->ns_err_idp.idp_dna;
type = errp->ns_err_num;
type = ntohs((u_short)type);
type = ntohs((u_int16_t)type);
break;
}
@ -897,7 +899,7 @@ spp_output(m0, va_alist)
len = (1 + sizeof(*si));
}
}
si->si_len = htons((u_short)len);
si->si_len = htons((u_int16_t)len);
m->m_pkthdr.len = ((len - 1) | 1) + 1;
/*
* queue stuff up for output
@ -977,7 +979,7 @@ again:
* then want to send a window update to peer.
*/
if (rcv_win > 0) {
u_short delta = 1 + cb->s_alo - cb->s_ack;
u_int16_t delta = 1 + cb->s_alo - cb->s_ack;
int adv = rcv_win - (delta * cb->s_mtu);
if ((so->so_rcv.sb_cc == 0 && adv >= (2 * cb->s_mtu)) ||
@ -1042,11 +1044,7 @@ send:
* must make a copy of this packet for
* idp_output to monkey with
*/
#if 0
m = m_copy(dtom(si), 0, (int)M_COPYALL);
#else
m = m_copy(m, 0, (int)M_COPYALL);
#endif
if (m == NULL) {
return (ENOBUFS);
}