mirror of
https://github.com/simh/simh.git
synced 2026-04-15 16:11:13 +00:00
ALL: Massive 'const' cleanup
These changes facilitate more robust parameter type checking and helps to identify unexpected coding errors. Most simulators can now also be compiled with a C++ compiler without warnings. Additionally, these changes have also been configured to facilitate easier backporting of simulator and device simulation modules to run under the simh v3.9+ SCP framework.
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "slirp.h"
|
||||
|
||||
void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN])
|
||||
void arp_table_add(Slirp *slirp, uint32_t ip_addr, const uint8_t ethaddr[ETH_ALEN])
|
||||
{
|
||||
const uint32_t broadcast_addr =
|
||||
~slirp->vnetwork_mask.s_addr | slirp->vnetwork_addr.s_addr;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#ifndef SLIRP_DEBUG_H
|
||||
#define SLIRP_DEBUG_H
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 Danny Gasparovski.
|
||||
*
|
||||
@@ -42,10 +43,13 @@ extern int slirp_debug;
|
||||
#include <stdio.h>
|
||||
#define DEVICE void
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
extern void *slirp_dptr;
|
||||
extern unsigned int slirp_dbit;
|
||||
|
||||
extern void _sim_debug (int dbits, DEVICE* dptr, const char* fmt, ...);
|
||||
extern void _sim_debug (unsigned int dbits, DEVICE* dptr, const char* fmt, ...);
|
||||
|
||||
#define DEBUG_CALL(x) do {if (slirp_debug & DBG_CALL) { _sim_debug (slirp_dbit, slirp_dptr, "%s...\n", x); };} while (0)
|
||||
#define DEBUG_ARG(x, y) do {if (slirp_debug & DBG_CALL) {_sim_debug (slirp_dbit, slirp_dptr, x, y); _sim_debug (slirp_dbit, slirp_dptr, "\n"); };} while (0)
|
||||
@@ -54,6 +58,10 @@ extern void _sim_debug (int dbits, DEVICE* dptr, const char* fmt, ...);
|
||||
#define DEBUG_ERROR(...) do {if (slirp_debug & DBG_ERROR) { _sim_debug (slirp_dbit, slirp_dptr, ## __VA_ARGS__); };} while (0)
|
||||
#define DPRINTF(fmt, ...) do {if (slirp_debug & DBG_CALL) { _sim_debug (slirp_dbit, slirp_dptr, fmt, ## __VA_ARGS__); };} while (0)
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -61,7 +61,7 @@ domain_suffix_diffoff(const CompactDomain *a, const CompactDomain *b)
|
||||
|
||||
static int domain_suffix_ord(const void *cva, const void *cvb)
|
||||
{
|
||||
const CompactDomain *a = cva, *b = cvb;
|
||||
const CompactDomain *a = (const CompactDomain *)cva, *b = (const CompactDomain *)cvb;
|
||||
size_t la = a->len, lb = b->len;
|
||||
size_t doff = domain_suffix_diffoff(a, b);
|
||||
uint8_t ca = a->labels[la - doff];
|
||||
@@ -252,7 +252,7 @@ int translate_dnssearch(Slirp *s, const char **names)
|
||||
return -2;
|
||||
}
|
||||
|
||||
domains = g_malloc(num_domains * sizeof(*domains));
|
||||
domains = (CompactDomain *)g_malloc(num_domains * sizeof(*domains));
|
||||
|
||||
for (i = 0; i < num_domains; i++) {
|
||||
size_t nlen = strlen(names[i]);
|
||||
@@ -265,7 +265,7 @@ int translate_dnssearch(Slirp *s, const char **names)
|
||||
|
||||
/* reserve extra 2 header bytes for each 255 bytes of output */
|
||||
memreq += ((memreq + MAX_OPT_LEN - 1) / MAX_OPT_LEN) * OPT_HEADER_LEN;
|
||||
result = g_malloc(memreq * sizeof(*result));
|
||||
result = (uint8_t *)g_malloc(memreq * sizeof(*result));
|
||||
|
||||
outptr = result;
|
||||
for (i = 0; i < num_domains; i++) {
|
||||
|
||||
@@ -152,8 +152,8 @@ ip_input(struct mbuf *m)
|
||||
* Look for queue of fragments
|
||||
* of this datagram.
|
||||
*/
|
||||
for (l = slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
|
||||
l = l->next) {
|
||||
for (l = (struct qlink *)slirp->ipq.ip_link.next; l != &slirp->ipq.ip_link;
|
||||
l = (struct qlink *)l->next) {
|
||||
fp = container_of(l, struct ipq, ip_link);
|
||||
if (ip->ip_id == fp->ipq_id &&
|
||||
ip->ip_src.s_addr == fp->ipq_src.s_addr &&
|
||||
@@ -268,8 +268,8 @@ ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
|
||||
/*
|
||||
* Find a segment which begins after this one does.
|
||||
*/
|
||||
for (q = fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link;
|
||||
q = q->ipf_next)
|
||||
for (q = (struct ipasfrag *)fp->frag_link.next; q != (struct ipasfrag *)&fp->frag_link;
|
||||
q = (struct ipasfrag *)q->ipf_next)
|
||||
if (q->ipf_off > ip->ip_off)
|
||||
break;
|
||||
|
||||
@@ -279,7 +279,7 @@ ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
|
||||
* segment. If it provides all of our data, drop us.
|
||||
*/
|
||||
if (q->ipf_prev != &fp->frag_link) {
|
||||
struct ipasfrag *pq = q->ipf_prev;
|
||||
struct ipasfrag *pq = (struct ipasfrag *)q->ipf_prev;
|
||||
i = pq->ipf_off + pq->ipf_len - ip->ip_off;
|
||||
if (i > 0) {
|
||||
if (i >= ip->ip_len)
|
||||
@@ -303,9 +303,9 @@ ip_reass(Slirp *slirp, struct ip *ip, struct ipq *fp)
|
||||
m_adj(dtom(slirp, q), i);
|
||||
break;
|
||||
}
|
||||
q = q->ipf_next;
|
||||
q = (struct ipasfrag *)q->ipf_next;
|
||||
m_free(dtom(slirp, q->ipf_prev));
|
||||
ip_deq(q->ipf_prev);
|
||||
ip_deq((struct ipasfrag*)q->ipf_prev);
|
||||
}
|
||||
|
||||
insert:
|
||||
@@ -313,10 +313,10 @@ insert:
|
||||
* Stick new segment in its place;
|
||||
* check for complete reassembly.
|
||||
*/
|
||||
ip_enq(iptofrag(ip), q->ipf_prev);
|
||||
ip_enq(iptofrag(ip), (struct ipasfrag*)q->ipf_prev);
|
||||
next = 0;
|
||||
for (q = fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link;
|
||||
q = q->ipf_next) {
|
||||
for (q = (struct ipasfrag*)fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link;
|
||||
q = (struct ipasfrag*)q->ipf_next) {
|
||||
if (q->ipf_off != next)
|
||||
return NULL;
|
||||
next += q->ipf_len;
|
||||
@@ -327,7 +327,7 @@ insert:
|
||||
/*
|
||||
* Reassembly is complete; concatenate fragments.
|
||||
*/
|
||||
q = fp->frag_link.next;
|
||||
q = (struct ipasfrag*)fp->frag_link.next;
|
||||
m = dtom(slirp, q);
|
||||
|
||||
q = (struct ipasfrag *) q->ipf_next;
|
||||
@@ -343,7 +343,7 @@ insert:
|
||||
* dequeue and discard fragment reassembly header.
|
||||
* Make header visible.
|
||||
*/
|
||||
q = fp->frag_link.next;
|
||||
q = (struct ipasfrag*)fp->frag_link.next;
|
||||
|
||||
/*
|
||||
* If the fragments concatenated to an mbuf that's
|
||||
@@ -383,8 +383,8 @@ ip_freef(Slirp *slirp, struct ipq *fp)
|
||||
{
|
||||
register struct ipasfrag *q, *p;
|
||||
|
||||
for (q = fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link; q = p) {
|
||||
p = q->ipf_next;
|
||||
for (q = (struct ipasfrag*)fp->frag_link.next; q != (struct ipasfrag*)&fp->frag_link; q = p) {
|
||||
p = (struct ipasfrag*)q->ipf_next;
|
||||
ip_deq(q);
|
||||
m_free(dtom(slirp, q));
|
||||
}
|
||||
@@ -429,14 +429,14 @@ ip_slowtimo(Slirp *slirp)
|
||||
|
||||
DEBUG_CALL("ip_slowtimo");
|
||||
|
||||
l = slirp->ipq.ip_link.next;
|
||||
l = (struct qlink*)slirp->ipq.ip_link.next;
|
||||
|
||||
if (l == NULL)
|
||||
return;
|
||||
|
||||
while (l != &slirp->ipq.ip_link) {
|
||||
struct ipq *fp = container_of(l, struct ipq, ip_link);
|
||||
l = l->next;
|
||||
l = (struct qlink*)l->next;
|
||||
if (--fp->ipq_ttl == 0) {
|
||||
ip_freef(slirp, fp);
|
||||
}
|
||||
|
||||
10
slirp/misc.c
10
slirp/misc.c
@@ -24,7 +24,7 @@ struct quehead {
|
||||
struct quehead *qh_rlink;
|
||||
};
|
||||
|
||||
inline void
|
||||
void
|
||||
insque(void *a, void *b)
|
||||
{
|
||||
register struct quehead *element = (struct quehead *) a;
|
||||
@@ -36,7 +36,7 @@ insque(void *a, void *b)
|
||||
= (struct quehead *)element;
|
||||
}
|
||||
|
||||
inline void
|
||||
void
|
||||
remque(void *a)
|
||||
{
|
||||
register struct quehead *element = (struct quehead *) a;
|
||||
@@ -45,7 +45,7 @@ remque(void *a)
|
||||
element->qh_rlink = NULL;
|
||||
}
|
||||
|
||||
int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
|
||||
int add_exec(struct ex_list **ex_ptr, int do_pty, const char *exec,
|
||||
struct in_addr addr, int port)
|
||||
{
|
||||
struct ex_list *tmp_ptr;
|
||||
@@ -58,7 +58,7 @@ int add_exec(struct ex_list **ex_ptr, int do_pty, char *exec,
|
||||
}
|
||||
|
||||
tmp_ptr = *ex_ptr;
|
||||
*ex_ptr = g_new(struct ex_list, 1);
|
||||
*ex_ptr = (struct ex_list *)g_new(struct ex_list, 1);
|
||||
(*ex_ptr)->ex_fport = port;
|
||||
(*ex_ptr)->ex_addr = addr;
|
||||
(*ex_ptr)->ex_pty = do_pty;
|
||||
@@ -195,7 +195,7 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
|
||||
} while (c);
|
||||
|
||||
argv[i] = NULL;
|
||||
execvp(argv[0], (char **)argv);
|
||||
execvp(argv[0], (char * const *)argv);
|
||||
|
||||
/* Ooops, failed, let's tell the user why */
|
||||
fprintf(stderr, "Error: execvp of %s failed: %s\n",
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#ifndef _MISC_H_
|
||||
#define _MISC_H_
|
||||
|
||||
#include "socket.h"
|
||||
|
||||
struct ex_list {
|
||||
int ex_pty; /* Do we want a pty? */
|
||||
struct in_addr ex_addr; /* Server address */
|
||||
@@ -47,7 +49,7 @@ struct emu_t {
|
||||
|
||||
void slirp_insque(void *, void *);
|
||||
void slirp_remque(void *);
|
||||
int add_exec(struct ex_list **, int, char *, struct in_addr, int);
|
||||
int add_exec(struct ex_list **, int, const char *, struct in_addr, int);
|
||||
int fork_exec(struct socket *so, const char *ex, int do_pty);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -73,7 +73,7 @@ int get_dns_addr(struct in_addr *pdns_addr)
|
||||
GlobalFree(FixedInfo);
|
||||
FixedInfo = NULL;
|
||||
}
|
||||
FixedInfo = GlobalAlloc(GPTR, BufLen);
|
||||
FixedInfo = (FIXED_INFO *)GlobalAlloc(GPTR, BufLen);
|
||||
}
|
||||
|
||||
if ((ret = GetNetworkParams(FixedInfo, &BufLen)) != ERROR_SUCCESS) {
|
||||
@@ -204,7 +204,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
|
||||
struct in_addr vnameserver, const char **vdnssearch,
|
||||
void *opaque)
|
||||
{
|
||||
Slirp *slirp = g_malloc0(sizeof(Slirp));
|
||||
Slirp *slirp = (Slirp *)g_malloc0(sizeof(Slirp));
|
||||
|
||||
slirp_init_once();
|
||||
|
||||
@@ -544,7 +544,7 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
|
||||
/* Connected */
|
||||
so->so_state &= ~SS_ISFCONNECTING;
|
||||
|
||||
ret = send(so->s, (const void *) &ret, 0, 0);
|
||||
ret = send(so->s, (const char *) &ret, 0, 0);
|
||||
if (ret < 0) {
|
||||
/* XXXXX Must fix, zero bytes is a NOP */
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK ||
|
||||
@@ -666,7 +666,7 @@ void slirp_pollfds_poll(GArray *pollfds, int select_error)
|
||||
|
||||
static void arp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
|
||||
{
|
||||
struct arphdr *ah = (struct arphdr *)(pkt + ETH_HLEN);
|
||||
const struct arphdr *ah = (const struct arphdr *)(pkt + ETH_HLEN);
|
||||
uint8_t arp_reply[max(ETH_HLEN + sizeof(struct arphdr), 64)];
|
||||
struct ethhdr *reh = (struct ethhdr *)arp_reply;
|
||||
struct arphdr *rah = (struct arphdr *)(arp_reply + ETH_HLEN);
|
||||
@@ -731,7 +731,7 @@ void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len)
|
||||
if (pkt_len < ETH_HLEN)
|
||||
return;
|
||||
|
||||
proto = ntohs(*(uint16_t *)(pkt + 12));
|
||||
proto = ntohs(*(const uint16_t *)(pkt + 12));
|
||||
switch(proto) {
|
||||
case ETH_P_ARP:
|
||||
arp_input(slirp, pkt, pkt_len);
|
||||
@@ -888,11 +888,11 @@ int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
|
||||
ssize_t slirp_send(struct socket *so, const void *buf, size_t len, int flags)
|
||||
{
|
||||
if (so->s == -1 && so->extra) {
|
||||
qemu_chr_fe_write(so->extra, buf, len);
|
||||
qemu_chr_fe_write((CharDriverState*)so->extra, (const uint8_t *)buf, len);
|
||||
return len;
|
||||
}
|
||||
|
||||
return send(so->s, buf, len, flags);
|
||||
return send(so->s, (const char *)buf, len, flags);
|
||||
}
|
||||
|
||||
static struct socket *
|
||||
@@ -1031,7 +1031,7 @@ static void slirp_bootp_save(QEMUFile *f, Slirp *slirp)
|
||||
|
||||
static void slirp_state_save(QEMUFile *f, void *opaque)
|
||||
{
|
||||
Slirp *slirp = opaque;
|
||||
Slirp *slirp = (Slirp *)opaque;
|
||||
struct ex_list *ex_ptr;
|
||||
|
||||
for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
|
||||
@@ -1158,7 +1158,7 @@ static void slirp_bootp_load(QEMUFile *f, Slirp *slirp)
|
||||
|
||||
static int slirp_state_load(QEMUFile *f, void *opaque, int version_id)
|
||||
{
|
||||
Slirp *slirp = opaque;
|
||||
Slirp *slirp = (Slirp *)opaque;
|
||||
struct ex_list *ex_ptr;
|
||||
|
||||
while (qemu_get_byte(f)) {
|
||||
|
||||
@@ -200,7 +200,7 @@ typedef struct ArpTable {
|
||||
int next_victim;
|
||||
} ArpTable;
|
||||
|
||||
void arp_table_add(Slirp *slirp, uint32_t ip_addr, uint8_t ethaddr[ETH_ALEN]);
|
||||
void arp_table_add(Slirp *slirp, uint32_t ip_addr, const uint8_t ethaddr[ETH_ALEN]);
|
||||
|
||||
bool arp_table_search(Slirp *slirp, uint32_t ip_addr,
|
||||
uint8_t out_ethaddr[ETH_ALEN]);
|
||||
|
||||
@@ -65,7 +65,7 @@ sofree(struct socket *so)
|
||||
Slirp *slirp = so->slirp;
|
||||
|
||||
if (so->so_emu==EMU_RSH && so->extra) {
|
||||
sofree(so->extra);
|
||||
sofree((struct socket *)so->extra);
|
||||
so->extra=NULL;
|
||||
}
|
||||
if (so == slirp->tcp_last_so) {
|
||||
|
||||
@@ -136,7 +136,7 @@ static int tftp_send_oack(struct tftp_session *spt,
|
||||
memset(m->m_data, 0, m->m_size);
|
||||
|
||||
m->m_data += IF_MAXLINKHDR;
|
||||
tp = (void *)m->m_data;
|
||||
tp = (struct tftp_t *)m->m_data;
|
||||
m->m_data += sizeof(struct udpiphdr);
|
||||
|
||||
tp->tp_op = htons(TFTP_OACK);
|
||||
@@ -177,7 +177,7 @@ static void tftp_send_error(struct tftp_session *spt,
|
||||
memset(m->m_data, 0, m->m_size);
|
||||
|
||||
m->m_data += IF_MAXLINKHDR;
|
||||
tp = (void *)m->m_data;
|
||||
tp = (struct tftp_t *)m->m_data;
|
||||
m->m_data += sizeof(struct udpiphdr);
|
||||
|
||||
tp->tp_op = htons(TFTP_ERROR);
|
||||
@@ -216,7 +216,7 @@ static void tftp_send_next_block(struct tftp_session *spt,
|
||||
memset(m->m_data, 0, m->m_size);
|
||||
|
||||
m->m_data += IF_MAXLINKHDR;
|
||||
tp = (void *)m->m_data;
|
||||
tp = (struct tftp_t *)m->m_data;
|
||||
m->m_data += sizeof(struct udpiphdr);
|
||||
|
||||
tp->tp_op = htons(TFTP_DATA);
|
||||
@@ -291,7 +291,7 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t *tp, int pktlen)
|
||||
|
||||
/* prepend tftp_prefix */
|
||||
prefix_len = strlen(slirp->tftp_prefix);
|
||||
spt->filename = g_malloc(prefix_len + TFTP_FILENAME_MAX + 2);
|
||||
spt->filename = (char *)g_malloc(prefix_len + TFTP_FILENAME_MAX + 2);
|
||||
memcpy(spt->filename, slirp->tftp_prefix, prefix_len);
|
||||
spt->filename[prefix_len] = '/';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user