aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-01-17 15:43:53 +0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-02-07 15:49:08 +0200
commitb1c71bcaf795e78cf3523f75768564bc715a58bd (patch)
tree2c320dbb6f916354e3b21ad3aed441ad306b6873
parent1162ea7f9ea221caf874cda68574b75fe3259404 (diff)
downloadslirp-b1c71bcaf795e78cf3523f75768564bc715a58bd.zip
slirp-b1c71bcaf795e78cf3523f75768564bc715a58bd.tar.gz
slirp-b1c71bcaf795e78cf3523f75768564bc715a58bd.tar.bz2
slirp: prefer c99 types over BSD kind
Replace: - u_char -> uint8_t - u_short -> uint16_t - u_long -> uint32_t - u_int -> unsigned - caddr_t -> char * Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--ip_icmp.c6
-rw-r--r--ip_icmp.h18
-rw-r--r--ip_input.c4
-rw-r--r--main.h2
-rw-r--r--mbuf.h2
-rw-r--r--slirp.c12
-rw-r--r--slirp.h8
-rw-r--r--socket.c6
-rw-r--r--socket.h4
-rw-r--r--tcp_input.c22
-rw-r--r--tcp_output.c12
-rw-r--r--tcp_subr.c16
-rw-r--r--tcp_timer.c2
-rw-r--r--tcp_var.h14
-rw-r--r--udp.c6
-rw-r--r--udp.h2
16 files changed, 67 insertions, 69 deletions
diff --git a/ip_icmp.c b/ip_icmp.c
index 089a535..33d77e7 100644
--- a/ip_icmp.c
+++ b/ip_icmp.c
@@ -240,7 +240,7 @@ end_error:
*/
#define ICMP_MAXDATALEN (IP_MSS - 28)
-void icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
+void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
const char *message)
{
unsigned hlen, shlen, s_ip_len;
@@ -396,7 +396,7 @@ void icmp_reflect(struct mbuf *m)
* Strip out original options by copying rest of first
* mbuf's data back, and adjust the IP length.
*/
- memmove((caddr_t)(ip + 1), (caddr_t)ip + hlen,
+ memmove((char *)(ip + 1), (char *)ip + hlen,
(unsigned)(m->m_len - hlen));
hlen -= optlen;
ip->ip_hl = hlen >> 2;
@@ -420,7 +420,7 @@ void icmp_receive(struct socket *so)
struct mbuf *m = so->so_m;
struct ip *ip = mtod(m, struct ip *);
int hlen = ip->ip_hl << 2;
- u_char error_code;
+ uint8_t error_code;
struct icmp *icp;
int id, len;
diff --git a/ip_icmp.h b/ip_icmp.h
index 754fa25..dcd6f96 100644
--- a/ip_icmp.h
+++ b/ip_icmp.h
@@ -44,22 +44,22 @@ typedef uint32_t n_time;
* Structure of an icmp header.
*/
struct icmp {
- u_char icmp_type; /* type of message, see below */
- u_char icmp_code; /* type sub code */
- u_short icmp_cksum; /* ones complement cksum of struct */
+ uint8_t icmp_type; /* type of message, see below */
+ uint8_t icmp_code; /* type sub code */
+ uint16_t icmp_cksum; /* ones complement cksum of struct */
union {
- u_char ih_pptr; /* ICMP_PARAMPROB */
+ uint8_t ih_pptr; /* ICMP_PARAMPROB */
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
struct ih_idseq {
- u_short icd_id;
- u_short icd_seq;
+ uint16_t icd_id;
+ uint16_t icd_seq;
} ih_idseq;
int ih_void;
/* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
struct ih_pmtu {
- u_short ipm_void;
- u_short ipm_nextmtu;
+ uint16_t ipm_void;
+ uint16_t ipm_nextmtu;
} ih_pmtu;
} icmp_hun;
#define icmp_pptr icmp_hun.ih_pptr
@@ -156,7 +156,7 @@ struct icmp {
void icmp_init(Slirp *slirp);
void icmp_cleanup(Slirp *slirp);
void icmp_input(struct mbuf *, int);
-void icmp_send_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
+void icmp_send_error(struct mbuf *msrc, uint8_t type, uint8_t code, int minsize,
const char *message);
void icmp_reflect(struct mbuf *);
void icmp_receive(struct socket *so);
diff --git a/ip_input.c b/ip_input.c
index 18338bc..a9b2f8d 100644
--- a/ip_input.c
+++ b/ip_input.c
@@ -449,11 +449,11 @@ void ip_stripoptions(register struct mbuf *m, struct mbuf *mopt)
{
register int i;
struct ip *ip = mtod(m, struct ip *);
- register caddr_t opts;
+ register char *opts;
int olen;
olen = (ip->ip_hl << 2) - sizeof(struct ip);
- opts = (caddr_t)(ip + 1);
+ opts = (char *)(ip + 1);
i = m->m_len - (sizeof(struct ip) + olen);
memcpy(opts, opts + olen, (unsigned)i);
m->m_len -= olen;
diff --git a/main.h b/main.h
index 4bc05fb..f11d457 100644
--- a/main.h
+++ b/main.h
@@ -8,7 +8,7 @@
#ifndef SLIRP_MAIN_H
#define SLIRP_MAIN_H
-extern u_int curtime;
+extern unsigned curtime;
extern struct in_addr loopback_addr;
extern unsigned long loopback_mask;
diff --git a/mbuf.h b/mbuf.h
index adb4eb6..7137c14 100644
--- a/mbuf.h
+++ b/mbuf.h
@@ -84,7 +84,7 @@ struct mbuf {
int m_size; /* Size of mbuf, from m_dat or m_ext */
struct socket *m_so;
- caddr_t m_data; /* Current location of data */
+ char *m_data; /* Current location of data */
int m_len; /* Amount of data in this mbuf, from m_data */
Slirp *slirp;
diff --git a/slirp.c b/slirp.c
index 7ff7ac9..60b6834 100644
--- a/slirp.c
+++ b/slirp.c
@@ -45,7 +45,7 @@ unsigned long loopback_mask;
static const uint8_t special_ethaddr[ETH_ALEN] = { 0x52, 0x55, 0x00,
0x00, 0x00, 0x00 };
-u_int curtime;
+unsigned curtime;
static QTAILQ_HEAD(, Slirp)
slirp_instances = QTAILQ_HEAD_INITIALIZER(slirp_instances);
@@ -54,9 +54,9 @@ static struct in_addr dns_addr;
#ifndef _WIN32
static struct in6_addr dns6_addr;
#endif
-static u_int dns_addr_time;
+static unsigned dns_addr_time;
#ifndef _WIN32
-static u_int dns6_addr_time;
+static unsigned dns6_addr_time;
#endif
#define TIMEOUT_FAST 2 /* milliseconds */
@@ -91,7 +91,7 @@ int get_dns_addr(struct in_addr *pdns_addr)
}
if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) {
- printf("GetNetworkParams failed. ret = %08x\n", (u_int)ret);
+ printf("GetNetworkParams failed. ret = %08x\n", (unsigned)ret);
if (FixedInfo) {
GlobalFree(FixedInfo);
FixedInfo = NULL;
@@ -125,7 +125,7 @@ static void winsock_cleanup(void)
static int get_dns_addr_cached(void *pdns_addr, void *cached_addr,
socklen_t addrlen, struct stat *cached_stat,
- u_int *cached_time)
+ unsigned *cached_time)
{
struct stat old_stat;
if (curtime - *cached_time < TIMEOUT_DEFAULT) {
@@ -148,7 +148,7 @@ static int get_dns_addr_cached(void *pdns_addr, void *cached_addr,
static int get_dns_addr_resolv_conf(int af, void *pdns_addr, void *cached_addr,
socklen_t addrlen, uint32_t *scope_id,
- u_int *cached_time)
+ unsigned *cached_time)
{
char buff[512];
char buff2[257];
diff --git a/slirp.h b/slirp.h
index 5d479fe..1d92de4 100644
--- a/slirp.h
+++ b/slirp.h
@@ -12,8 +12,6 @@
#define WIN32_LEAN_AND_MEAN
#endif
-typedef char *caddr_t;
-
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
@@ -124,8 +122,8 @@ bool ndp_table_search(Slirp *slirp, struct in6_addr ip_addr,
struct Slirp {
QTAILQ_ENTRY(Slirp) entry;
- u_int time_fasttimo;
- u_int last_slowtimo;
+ unsigned time_fasttimo;
+ unsigned last_slowtimo;
bool do_slowtimo;
bool in_enabled, in6_enabled;
@@ -245,7 +243,7 @@ int ip6_output(struct socket *, struct mbuf *, int fast);
/* tcp_input.c */
void tcp_input(register struct mbuf *, int, struct socket *, unsigned short af);
-int tcp_mss(register struct tcpcb *, u_int);
+int tcp_mss(register struct tcpcb *, unsigned);
/* tcp_output.c */
int tcp_output(register struct tcpcb *);
diff --git a/socket.c b/socket.c
index 12046d8..88f9437 100644
--- a/socket.c
+++ b/socket.c
@@ -502,7 +502,7 @@ void sorecvfrom(struct socket *so)
/* XXX Check if reply is "correct"? */
if (len == -1 || len == 0) {
- u_char code = ICMP_UNREACH_PORT;
+ uint8_t code = ICMP_UNREACH_PORT;
if (errno == EHOSTUNREACH)
code = ICMP_UNREACH_HOST;
@@ -671,8 +671,8 @@ int sosendto(struct socket *so, struct mbuf *m)
/*
* Listen for incoming TCP connections
*/
-struct socket *tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport,
- uint32_t laddr, u_int lport, int flags)
+struct socket *tcp_listen(Slirp *slirp, uint32_t haddr, unsigned hport,
+ uint32_t laddr, unsigned lport, int flags)
{
struct sockaddr_in addr;
struct socket *so;
diff --git a/socket.h b/socket.h
index 015300c..bd5feb6 100644
--- a/socket.h
+++ b/socket.h
@@ -61,7 +61,7 @@ struct socket {
int32_t so_state; /* internal state flags SS_*, below */
struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */
- u_int so_expire; /* When the socket will expire */
+ unsigned so_expire; /* When the socket will expire */
int so_queued; /* Number of packets queued from this socket */
int so_nqueued; /* Number of packets queued in a row
@@ -149,7 +149,7 @@ int sosendoob(struct socket *);
int sowrite(struct socket *);
void sorecvfrom(struct socket *);
int sosendto(struct socket *, struct mbuf *);
-struct socket *tcp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int, int);
+struct socket *tcp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int);
void soisfconnecting(register struct socket *);
void soisfconnected(register struct socket *);
void sofwdrain(struct socket *);
diff --git a/tcp_input.c b/tcp_input.c
index efd64c2..e91a22e 100644
--- a/tcp_input.c
+++ b/tcp_input.c
@@ -77,7 +77,7 @@
} \
}
-static void tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt,
+static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt,
struct tcpiphdr *ti);
static void tcp_xmit_timer(register struct tcpcb *tp, int rtt);
@@ -198,7 +198,7 @@ void tcp_input(struct mbuf *m, int iphlen, struct socket *inso,
struct ip save_ip, *ip;
struct ip6 save_ip6, *ip6;
register struct tcpiphdr *ti;
- caddr_t optp = NULL;
+ char *optp = NULL;
int optlen = 0;
int len, tlen, off;
register struct tcpcb *tp = NULL;
@@ -206,7 +206,7 @@ void tcp_input(struct mbuf *m, int iphlen, struct socket *inso,
struct socket *so = NULL;
int todrop, acked, ourfinisacked, needoutput = 0;
int iss = 0;
- u_long tiwin;
+ uint32_t tiwin;
int ret;
struct sockaddr_storage lhost, fhost;
struct sockaddr_in *lhost4, *fhost4;
@@ -327,7 +327,7 @@ void tcp_input(struct mbuf *m, int iphlen, struct socket *inso,
ti->ti_len = tlen;
if (off > sizeof(struct tcphdr)) {
optlen = off - sizeof(struct tcphdr);
- optp = mtod(m, caddr_t) + sizeof(struct tcpiphdr);
+ optp = mtod(m, char *) + sizeof(struct tcpiphdr);
}
tiflags = ti->ti_flags;
@@ -470,7 +470,7 @@ findso:
* else do it below (after getting remote address).
*/
if (optp && tp->t_state != TCPS_LISTEN)
- tcp_dooptions(tp, (u_char *)optp, optlen, ti);
+ tcp_dooptions(tp, (uint8_t *)optp, optlen, ti);
/*
* Header prediction: check for the two common cases
@@ -722,7 +722,7 @@ findso:
tcp_template(tp);
if (optp)
- tcp_dooptions(tp, (u_char *)optp, optlen, ti);
+ tcp_dooptions(tp, (uint8_t *)optp, optlen, ti);
if (iss)
tp->iss = iss;
@@ -1033,7 +1033,7 @@ findso:
tp->t_dupacks = 0;
else if (++tp->t_dupacks == TCPREXMTTHRESH) {
tcp_seq onxt = tp->snd_nxt;
- u_int win =
+ unsigned win =
MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
if (win < 2)
@@ -1100,8 +1100,8 @@ findso:
* (maxseg^2 / cwnd per packet).
*/
{
- register u_int cw = tp->snd_cwnd;
- register u_int incr = tp->t_maxseg;
+ register unsigned cw = tp->snd_cwnd;
+ register unsigned incr = tp->t_maxseg;
if (cw > tp->snd_ssthresh)
incr = incr * incr / cw;
@@ -1371,7 +1371,7 @@ drop:
m_free(m);
}
-static void tcp_dooptions(struct tcpcb *tp, u_char *cp, int cnt,
+static void tcp_dooptions(struct tcpcb *tp, uint8_t *cp, int cnt,
struct tcpiphdr *ti)
{
uint16_t mss;
@@ -1499,7 +1499,7 @@ static void tcp_xmit_timer(register struct tcpcb *tp, int rtt)
* parameters from pre-set or cached values in the routing entry.
*/
-int tcp_mss(struct tcpcb *tp, u_int offer)
+int tcp_mss(struct tcpcb *tp, unsigned offer)
{
struct socket *so = tp->t_socket;
int mss;
diff --git a/tcp_output.c b/tcp_output.c
index 502c014..37c82f3 100644
--- a/tcp_output.c
+++ b/tcp_output.c
@@ -40,7 +40,7 @@
#include "slirp.h"
-static const u_char tcp_outflags[TCP_NSTATES] = {
+static const uint8_t tcp_outflags[TCP_NSTATES] = {
TH_RST | TH_ACK, 0, TH_SYN, TH_SYN | TH_ACK,
TH_ACK, TH_ACK, TH_FIN | TH_ACK, TH_FIN | TH_ACK,
TH_FIN | TH_ACK, TH_ACK, TH_ACK,
@@ -62,7 +62,7 @@ int tcp_output(struct tcpcb *tp)
register struct tcpiphdr *ti, tcpiph_save;
struct ip *ip;
struct ip6 *ip6;
- u_char opt[MAX_TCPOPTLEN];
+ uint8_t opt[MAX_TCPOPTLEN];
unsigned optlen, hdrlen;
int idle, sendalot;
@@ -270,7 +270,7 @@ send:
opt[0] = TCPOPT_MAXSEG;
opt[1] = 4;
mss = htons((uint16_t)tcp_mss(tp, 0));
- memcpy((caddr_t)(opt + 2), (caddr_t)&mss, sizeof(mss));
+ memcpy((char *)(opt + 2), (char *)&mss, sizeof(mss));
optlen = 4;
}
}
@@ -300,7 +300,7 @@ send:
m->m_data += IF_MAXLINKHDR;
m->m_len = hdrlen;
- sbcopy(&so->so_snd, off, (int)len, mtod(m, caddr_t) + hdrlen);
+ sbcopy(&so->so_snd, off, (int)len, mtod(m, char *) + hdrlen);
m->m_len += len;
/*
@@ -323,7 +323,7 @@ send:
ti = mtod(m, struct tcpiphdr *);
- memcpy((caddr_t)ti, &tp->t_template, sizeof(struct tcpiphdr));
+ memcpy((char *)ti, &tp->t_template, sizeof(struct tcpiphdr));
/*
* Fill in fields, remembering maximum advertised
@@ -352,7 +352,7 @@ send:
ti->ti_seq = htonl(tp->snd_max);
ti->ti_ack = htonl(tp->rcv_nxt);
if (optlen) {
- memcpy((caddr_t)(ti + 1), (caddr_t)opt, optlen);
+ memcpy((char *)(ti + 1), (char *)opt, optlen);
ti->ti_off = (sizeof(struct tcphdr) + optlen) >> 2;
}
ti->ti_flags = flags;
diff --git a/tcp_subr.c b/tcp_subr.c
index a931526..2fad18d 100644
--- a/tcp_subr.c
+++ b/tcp_subr.c
@@ -160,7 +160,7 @@ void tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m,
* ti points into m so the next line is just making
* the mbuf point to ti
*/
- m->m_data = (caddr_t)ti;
+ m->m_data = (char *)ti;
m->m_len = sizeof(struct tcpiphdr);
tlen = 0;
@@ -185,7 +185,7 @@ void tcp_respond(struct tcpcb *tp, struct tcpiphdr *ti, struct mbuf *m,
}
#undef xchg
}
- ti->ti_len = htons((u_short)(sizeof(struct tcphdr) + tlen));
+ ti->ti_len = htons((uint16_t)(sizeof(struct tcphdr) + tlen));
tlen += sizeof(struct tcpiphdr);
m->m_len = tlen;
@@ -608,10 +608,10 @@ uint8_t tcp_tos(struct socket *so)
int tcp_emu(struct socket *so, struct mbuf *m)
{
Slirp *slirp = so->slirp;
- u_int n1, n2, n3, n4, n5, n6;
+ unsigned n1, n2, n3, n4, n5, n6;
char buff[257];
uint32_t laddr;
- u_int lport;
+ unsigned lport;
char *bptr;
DEBUG_CALL("tcp_emu");
@@ -847,7 +847,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
bptr = m->m_data;
while (bptr < m->m_data + m->m_len) {
- u_short p;
+ uint16_t p;
static int ra = 0;
char ra_tbl[4];
@@ -903,7 +903,7 @@ int tcp_emu(struct socket *so, struct mbuf *m)
/* This is the field containing the port
* number that RA-player is listening to.
*/
- lport = (((u_char *)bptr)[0] << 8) + ((u_char *)bptr)[1];
+ lport = (((uint8_t *)bptr)[0] << 8) + ((uint8_t *)bptr)[1];
if (lport < 6970)
lport += 256; /* don't know why */
if (lport < 6970 || lport > 7170)
@@ -919,8 +919,8 @@ int tcp_emu(struct socket *so, struct mbuf *m)
}
if (p == 7071)
p = 0;
- *(u_char *)bptr++ = (p >> 8) & 0xff;
- *(u_char *)bptr = p & 0xff;
+ *(uint8_t *)bptr++ = (p >> 8) & 0xff;
+ *(uint8_t *)bptr = p & 0xff;
ra = 0;
return 1; /* port redirected, we're done */
break;
diff --git a/tcp_timer.c b/tcp_timer.c
index 1e701c9..f048d64 100644
--- a/tcp_timer.c
+++ b/tcp_timer.c
@@ -225,7 +225,7 @@ static struct tcpcb *tcp_timers(register struct tcpcb *tp, int timer)
* to go below this.)
*/
{
- u_int win = MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
+ unsigned win = MIN(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_maxseg;
if (win < 2)
win = 2;
tp->snd_cwnd = tp->t_maxseg;
diff --git a/tcp_var.h b/tcp_var.h
index 03b51ea..357abe8 100644
--- a/tcp_var.h
+++ b/tcp_var.h
@@ -47,9 +47,9 @@ struct tcpcb {
short t_rxtshift; /* log(2) of rexmt exp. backoff */
short t_rxtcur; /* current retransmit value */
short t_dupacks; /* consecutive dup acks recd */
- u_short t_maxseg; /* maximum segment size */
+ uint16_t t_maxseg; /* maximum segment size */
uint8_t t_force; /* 1 if forcing out a byte */
- u_short t_flags;
+ uint16_t t_flags;
#define TF_ACKNOW 0x0001 /* ack peer immediately */
#define TF_DELACK 0x0002 /* ack, but try to delay it */
#define TF_NODELAY 0x0004 /* don't delay packets to coalesce */
@@ -106,7 +106,7 @@ struct tcpcb {
tcp_seq t_rtseq; /* sequence number being timed */
short t_srtt; /* smoothed round-trip time */
short t_rttvar; /* variance in round-trip time */
- u_short t_rttmin; /* minimum rtt allowed */
+ uint16_t t_rttmin; /* minimum rtt allowed */
uint32_t max_sndwnd; /* largest window peer has offered */
/* out-of-band data */
@@ -117,10 +117,10 @@ struct tcpcb {
short t_softerror; /* possible error not yet reported */
/* RFC 1323 variables */
- u_char snd_scale; /* window scaling for send window */
- u_char rcv_scale; /* window scaling for recv window */
- u_char request_r_scale; /* pending window scaling */
- u_char requested_s_scale;
+ uint8_t snd_scale; /* window scaling for send window */
+ uint8_t rcv_scale; /* window scaling for recv window */
+ uint8_t request_r_scale; /* pending window scaling */
+ uint8_t requested_s_scale;
uint32_t ts_recent; /* timestamp echo data */
uint32_t ts_recent_age; /* when last updated */
tcp_seq last_ack_sent;
diff --git a/udp.c b/udp.c
index 6707c2a..0165209 100644
--- a/udp.c
+++ b/udp.c
@@ -90,7 +90,7 @@ void udp_input(register struct mbuf *m, int iphlen)
* Get IP and UDP header together in first mbuf.
*/
ip = mtod(m, struct ip *);
- uh = (struct udphdr *)((caddr_t)ip + iphlen);
+ uh = (struct udphdr *)((char *)ip + iphlen);
/*
* Make mbuf data length reflect UDP length.
@@ -310,8 +310,8 @@ static uint8_t udp_tos(struct socket *so)
return 0;
}
-struct socket *udp_listen(Slirp *slirp, uint32_t haddr, u_int hport,
- uint32_t laddr, u_int lport, int flags)
+struct socket *udp_listen(Slirp *slirp, uint32_t haddr, unsigned hport,
+ uint32_t laddr, unsigned lport, int flags)
{
struct sockaddr_in addr;
struct socket *so;
diff --git a/udp.h b/udp.h
index 95800d0..95b4f2a 100644
--- a/udp.h
+++ b/udp.h
@@ -78,7 +78,7 @@ void udp_cleanup(Slirp *);
void udp_input(register struct mbuf *, int);
int udp_attach(struct socket *, unsigned short af);
void udp_detach(struct socket *);
-struct socket *udp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int, int);
+struct socket *udp_listen(Slirp *, uint32_t, unsigned, uint32_t, unsigned, int);
int udp_output(struct socket *so, struct mbuf *m, struct sockaddr_in *saddr,
struct sockaddr_in *daddr, int iptos);