Skip to content

Commit

Permalink
slirp: Replace u_int8_t, u_int16_t, u_int32_t, u_int64_t by standard …
Browse files Browse the repository at this point in the history
…int types

There is no need to have a second set of integral types.
Replace them by the standard types from stdint.h.

Signed-off-by: Stefan Weil <[email protected]>
Signed-off-by: Aurelien Jarno <[email protected]>
  • Loading branch information
Stefan Weil authored and aurel32 committed Jul 25, 2010
1 parent 1fc3dc2 commit b6dce92
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 116 deletions.
20 changes: 10 additions & 10 deletions slirp/cksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,23 @@

int cksum(struct mbuf *m, int len)
{
register u_int16_t *w;
register uint16_t *w;
register int sum = 0;
register int mlen = 0;
int byte_swapped = 0;

union {
u_int8_t c[2];
u_int16_t s;
uint8_t c[2];
uint16_t s;
} s_util;
union {
u_int16_t s[2];
u_int32_t l;
uint16_t s[2];
uint32_t l;
} l_util;

if (m->m_len == 0)
goto cont;
w = mtod(m, u_int16_t *);
w = mtod(m, uint16_t *);

mlen = m->m_len;

Expand All @@ -78,8 +78,8 @@ int cksum(struct mbuf *m, int len)
if ((1 & (long) w) && (mlen > 0)) {
REDUCE;
sum <<= 8;
s_util.c[0] = *(u_int8_t *)w;
w = (u_int16_t *)((int8_t *)w + 1);
s_util.c[0] = *(uint8_t *)w;
w = (uint16_t *)((int8_t *)w + 1);
mlen--;
byte_swapped = 1;
}
Expand Down Expand Up @@ -111,14 +111,14 @@ int cksum(struct mbuf *m, int len)
REDUCE;
sum <<= 8;
if (mlen == -1) {
s_util.c[1] = *(u_int8_t *)w;
s_util.c[1] = *(uint8_t *)w;
sum += s_util.s;
mlen = 0;
} else

mlen = -1;
} else if (mlen == -1)
s_util.c[0] = *(u_int8_t *)w;
s_util.c[0] = *(uint8_t *)w;

cont:
#ifdef DEBUG
Expand Down
40 changes: 20 additions & 20 deletions slirp/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@
# define NTOHL(d) ((d) = ntohl((d)))
# endif
# ifndef NTOHS
# define NTOHS(d) ((d) = ntohs((u_int16_t)(d)))
# define NTOHS(d) ((d) = ntohs((uint16_t)(d)))
# endif
# ifndef HTONL
# define HTONL(d) ((d) = htonl((d)))
# endif
# ifndef HTONS
# define HTONS(d) ((d) = htons((u_int16_t)(d)))
# define HTONS(d) ((d) = htons((uint16_t)(d)))
# endif
#endif

typedef u_int32_t n_long; /* long as received from the net */
typedef uint32_t n_long; /* long as received from the net */

/*
* Definitions for internet protocol version 4.
Expand All @@ -80,16 +80,16 @@ struct ip {
u_int ip_hl:4, /* header length */
ip_v:4; /* version */
#endif
u_int8_t ip_tos; /* type of service */
u_int16_t ip_len; /* total length */
u_int16_t ip_id; /* identification */
u_int16_t ip_off; /* fragment offset field */
uint8_t ip_tos; /* type of service */
uint16_t ip_len; /* total length */
uint16_t ip_id; /* identification */
uint16_t ip_off; /* fragment offset field */
#define IP_DF 0x4000 /* don't fragment flag */
#define IP_MF 0x2000 /* more fragments flag */
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
u_int8_t ip_ttl; /* time to live */
u_int8_t ip_p; /* protocol */
u_int16_t ip_sum; /* checksum */
uint8_t ip_ttl; /* time to live */
uint8_t ip_p; /* protocol */
uint16_t ip_sum; /* checksum */
struct in_addr ip_src,ip_dst; /* source and dest address */
} __attribute__((packed));

Expand Down Expand Up @@ -136,9 +136,9 @@ struct ip {
* Time stamp option structure.
*/
struct ip_timestamp {
u_int8_t ipt_code; /* IPOPT_TS */
u_int8_t ipt_len; /* size of structure (variable) */
u_int8_t ipt_ptr; /* index of current entry */
uint8_t ipt_code; /* IPOPT_TS */
uint8_t ipt_len; /* size of structure (variable) */
uint8_t ipt_ptr; /* index of current entry */
#ifdef HOST_WORDS_BIGENDIAN
u_int ipt_oflw:4, /* overflow counter */
ipt_flg:4; /* flags, see below */
Expand Down Expand Up @@ -198,9 +198,9 @@ struct qlink {
*/
struct ipovly {
struct mbuf_ptr ih_mbuf; /* backpointer to mbuf */
u_int8_t ih_x1; /* (unused) */
u_int8_t ih_pr; /* protocol */
u_int16_t ih_len; /* protocol length */
uint8_t ih_x1; /* (unused) */
uint8_t ih_pr; /* protocol */
uint16_t ih_len; /* protocol length */
struct in_addr ih_src; /* source internet address */
struct in_addr ih_dst; /* destination internet address */
} __attribute__((packed));
Expand All @@ -215,9 +215,9 @@ struct ipovly {
struct ipq {
struct qlink frag_link; /* to ip headers of fragments */
struct qlink ip_link; /* to other reass headers */
u_int8_t ipq_ttl; /* time for reass q to live */
u_int8_t ipq_p; /* protocol of this fragment */
u_int16_t ipq_id; /* sequence id for reassembly */
uint8_t ipq_ttl; /* time for reass q to live */
uint8_t ipq_p; /* protocol of this fragment */
uint16_t ipq_id; /* sequence id for reassembly */
struct in_addr ipq_src,ipq_dst;
} __attribute__((packed));

Expand All @@ -235,7 +235,7 @@ struct ipasfrag {
#define ipf_tos ipf_ip.ip_tos
#define ipf_len ipf_ip.ip_len
#define ipf_next ipf_link.next
#define ipf_prev ipf_link.prev
#define ipf_prev ipf_link.prev

/*
* Structure stored in mbuf in inpcb.ip_options
Expand Down
2 changes: 1 addition & 1 deletion slirp/ip_icmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Per RFC 792, September 1981.
*/

typedef u_int32_t n_time;
typedef uint32_t n_time;

/*
* Structure of an icmp header.
Expand Down
2 changes: 1 addition & 1 deletion slirp/ip_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ ip_dooptions(m)
register struct in_ifaddr *ia;
int opt, optlen, cnt, off, code, type, forward = 0;
struct in_addr *sin, dst;
typedef u_int32_t n_time;
typedef uint32_t n_time;
n_time ntime;

dst = ip->ip_dst;
Expand Down
22 changes: 11 additions & 11 deletions slirp/ip_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ ip_output(struct socket *so, struct mbuf *m0)
/*
* If small enough for interface, can just send directly.
*/
if ((u_int16_t)ip->ip_len <= IF_MTU) {
ip->ip_len = htons((u_int16_t)ip->ip_len);
ip->ip_off = htons((u_int16_t)ip->ip_off);
if ((uint16_t)ip->ip_len <= IF_MTU) {
ip->ip_len = htons((uint16_t)ip->ip_len);
ip->ip_off = htons((uint16_t)ip->ip_off);
ip->ip_sum = 0;
ip->ip_sum = cksum(m, hlen);

Expand Down Expand Up @@ -110,7 +110,7 @@ ip_output(struct socket *so, struct mbuf *m0)
*/
m0 = m;
mhlen = sizeof (struct ip);
for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
for (off = hlen + len; off < (uint16_t)ip->ip_len; off += len) {
register struct ip *mhip;
m = m_get(slirp);
if (m == NULL) {
Expand All @@ -125,18 +125,18 @@ ip_output(struct socket *so, struct mbuf *m0)
mhip->ip_off = ((off - hlen) >> 3) + (ip->ip_off & ~IP_MF);
if (ip->ip_off & IP_MF)
mhip->ip_off |= IP_MF;
if (off + len >= (u_int16_t)ip->ip_len)
len = (u_int16_t)ip->ip_len - off;
if (off + len >= (uint16_t)ip->ip_len)
len = (uint16_t)ip->ip_len - off;
else
mhip->ip_off |= IP_MF;
mhip->ip_len = htons((u_int16_t)(len + mhlen));
mhip->ip_len = htons((uint16_t)(len + mhlen));

if (m_copy(m, m0, off, len) < 0) {
error = -1;
goto sendorfree;
}

mhip->ip_off = htons((u_int16_t)mhip->ip_off);
mhip->ip_off = htons((uint16_t)mhip->ip_off);
mhip->ip_sum = 0;
mhip->ip_sum = cksum(m, mhlen);
*mnext = m;
Expand All @@ -147,9 +147,9 @@ ip_output(struct socket *so, struct mbuf *m0)
* and updating header, then send each fragment (in order).
*/
m = m0;
m_adj(m, hlen + firstlen - (u_int16_t)ip->ip_len);
ip->ip_len = htons((u_int16_t)m->m_len);
ip->ip_off = htons((u_int16_t)(ip->ip_off | IP_MF));
m_adj(m, hlen + firstlen - (uint16_t)ip->ip_len);
ip->ip_len = htons((uint16_t)m->m_len);
ip->ip_off = htons((uint16_t)(ip->ip_off | IP_MF));
ip->ip_sum = 0;
ip->ip_sum = cksum(m, hlen);
sendorfree:
Expand Down
2 changes: 1 addition & 1 deletion slirp/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
extern int slirp_socket;
extern int slirp_socket_unit;
extern int slirp_socket_port;
extern u_int32_t slirp_socket_addr;
extern uint32_t slirp_socket_addr;
extern char *slirp_socket_passwd;
extern int ctty_closed;

Expand Down
20 changes: 10 additions & 10 deletions slirp/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ void do_wait(int);
#define EMU_NOCONNECT 0x10 /* Don't connect */

struct tos_t {
u_int16_t lport;
u_int16_t fport;
u_int8_t tos;
u_int8_t emu;
uint16_t lport;
uint16_t fport;
uint8_t tos;
uint8_t emu;
};

struct emu_t {
u_int16_t lport;
u_int16_t fport;
u_int8_t tos;
u_int8_t emu;
struct emu_t *next;
uint16_t lport;
uint16_t fport;
uint8_t tos;
uint8_t emu;
struct emu_t *next;
};

extern int x_port, x_server, x_display;

int show_x(char *, struct socket *);
void redir_x(u_int32_t, int, int, int);
void redir_x(uint32_t, int, int, int);
void slirp_insque(void *, void *);
void slirp_remque(void *);
int add_exec(struct ex_list **, int, char *, struct in_addr, int);
Expand Down
6 changes: 3 additions & 3 deletions slirp/slirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ struct Slirp {

/* ip states */
struct ipq ipq; /* ip reass. queue */
u_int16_t ip_id; /* ip packet ctr, for ids */
uint16_t ip_id; /* ip packet ctr, for ids */

/* bootp/dhcp states */
BOOTPClient bootp_clients[NB_BOOTP_CLIENTS];
Expand All @@ -243,7 +243,7 @@ struct Slirp {
struct socket tcb;
struct socket *tcp_last_so;
tcp_seq tcp_iss; /* tcp initial send seq # */
u_int32_t tcp_now; /* for RFC 1323 timestamps */
uint32_t tcp_now; /* for RFC 1323 timestamps */

/* udp states */
struct socket udb;
Expand Down Expand Up @@ -339,7 +339,7 @@ void tcp_sockclosed(struct tcpcb *);
int tcp_fconnect(struct socket *);
void tcp_connect(struct socket *);
int tcp_attach(struct socket *);
u_int8_t tcp_tos(struct socket *);
uint8_t tcp_tos(struct socket *);
int tcp_emu(struct socket *, struct mbuf *);
int tcp_ctl(struct socket *);
struct tcpcb *tcp_drop(struct tcpcb *tp, int err);
Expand Down
6 changes: 0 additions & 6 deletions slirp/slirp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,6 @@
/* Define if your compiler doesn't like prototypes */
#undef NO_PROTOTYPES

/* Define if you don't have u_int32_t etc. typedef'd */
#undef NEED_TYPEDEFS
#ifdef __sun__
#define NEED_TYPEDEFS
#endif

/* Define to sizeof(char) */
#define SIZEOF_CHAR 1

Expand Down
2 changes: 1 addition & 1 deletion slirp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ sosendto(struct socket *so, struct mbuf *m)
* Listen for incoming TCP connections
*/
struct socket *
tcp_listen(Slirp *slirp, u_int32_t haddr, u_int hport, u_int32_t laddr,
tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
u_int lport, int flags)
{
struct sockaddr_in addr;
Expand Down
10 changes: 5 additions & 5 deletions slirp/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ struct socket {
int so_urgc;
struct in_addr so_faddr; /* foreign host table entry */
struct in_addr so_laddr; /* local host table entry */
u_int16_t so_fport; /* foreign port */
u_int16_t so_lport; /* local port */
uint16_t so_fport; /* foreign port */
uint16_t so_lport; /* local port */

u_int8_t so_iptos; /* Type of service */
u_int8_t so_emu; /* Is the socket emulated? */
uint8_t so_iptos; /* Type of service */
uint8_t so_emu; /* Is the socket emulated? */

u_char so_type; /* Type of socket, UDP or TCP */
int so_state; /* internal state flags SS_*, below */
Expand Down Expand Up @@ -83,7 +83,7 @@ int sosendoob(struct socket *);
int sowrite(struct socket *);
void sorecvfrom(struct socket *);
int sosendto(struct socket *, struct mbuf *);
struct socket * tcp_listen(Slirp *, u_int32_t, u_int, u_int32_t, u_int,
struct socket * tcp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int,
int);
void soisfconnecting(register struct socket *);
void soisfconnected(register struct socket *);
Expand Down
14 changes: 7 additions & 7 deletions slirp/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#ifndef _TCP_H_
#define _TCP_H_

typedef u_int32_t tcp_seq;
typedef uint32_t tcp_seq;

#define PR_SLOWHZ 2 /* 2 slow timeouts per second (approx) */
#define PR_FASTHZ 5 /* 5 fast timeouts per second (not important) */
Expand All @@ -46,8 +46,8 @@ typedef u_int32_t tcp_seq;
* Per RFC 793, September, 1981.
*/
struct tcphdr {
u_int16_t th_sport; /* source port */
u_int16_t th_dport; /* destination port */
uint16_t th_sport; /* source port */
uint16_t th_dport; /* destination port */
tcp_seq th_seq; /* sequence number */
tcp_seq th_ack; /* acknowledgement number */
#ifdef HOST_WORDS_BIGENDIAN
Expand All @@ -57,16 +57,16 @@ struct tcphdr {
u_int th_x2:4, /* (unused) */
th_off:4; /* data offset */
#endif
u_int8_t th_flags;
uint8_t th_flags;
#define TH_FIN 0x01
#define TH_SYN 0x02
#define TH_RST 0x04
#define TH_PUSH 0x08
#define TH_ACK 0x10
#define TH_URG 0x20
u_int16_t th_win; /* window */
u_int16_t th_sum; /* checksum */
u_int16_t th_urp; /* urgent pointer */
uint16_t th_win; /* window */
uint16_t th_sum; /* checksum */
uint16_t th_urp; /* urgent pointer */
};

#include "tcp_var.h"
Expand Down
Loading

0 comments on commit b6dce92

Please sign in to comment.