From 2e85e746990db52059f98683845fd36af865414f Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Wed, 20 Nov 2013 09:13:27 -0800 Subject: [PATCH] SCP: Various cleanups. - Avoid assignments of void * values. Cast all memory allocation return values to appropriate types. - Add output to sim_log where missing in various places. - Fixed issue with lost file positions after a restore for devices which leverage the UNIT_SEQ flag. --- scp.c | 31 ++++++++++++++++-------------- scp.h | 1 + sim_BuildROMs.c | 8 ++++---- sim_console.c | 21 ++++++++++---------- sim_defs.h | 6 +++--- sim_disk.c | 51 ++++++++++++++++++++++++++++++++++++++++--------- sim_ether.c | 16 ++++++++-------- sim_serial.c | 6 +++--- sim_sock.c | 29 +++++++++++++++++++--------- sim_sock.h | 1 + sim_timer.h | 1 - 11 files changed, 110 insertions(+), 61 deletions(-) diff --git a/scp.c b/scp.c index 07f9bdcc..48b81f87 100644 --- a/scp.c +++ b/scp.c @@ -798,7 +798,7 @@ static CTAB cmd_table[] = { static int setenv(const char *envname, const char *envval, int overwrite) { -char *envstr = malloc(strlen(envname)+strlen(envval)+2); +char *envstr = (char *)malloc(strlen(envname)+strlen(envval)+2); int r; sprintf(envstr, "%s=%s", envname, envval); @@ -993,7 +993,7 @@ if (gbuf[0] == '\0') { /* Token started with qu if (cptr) *cptr = '\0'; } -sim_prompt = realloc (sim_prompt, strlen (gbuf) + 2); /* nul terminator and trailing blank */ +sim_prompt = (char *)realloc (sim_prompt, strlen (gbuf) + 2); /* nul terminator and trailing blank */ sprintf (sim_prompt, "%s ", gbuf); return SCPE_OK; } @@ -1073,7 +1073,7 @@ if (!found) { fprintf (st, "No register help is available for the %s device\n", dptr->name); } else { - namebuf = calloc (max_namelen + 1, sizeof (*namebuf)); + namebuf = (char *)calloc (max_namelen + 1, sizeof (*namebuf)); fprintf (st, "\nThe %s device implements these registers:\n\n", dptr->name); for (rptr = dptr->registers; rptr->name != NULL; rptr++) { if (rptr->flags & REG_HIDDEN) @@ -1577,7 +1577,7 @@ if (flag >= 0) { /* Only bump nesting fro sim_on_check[sim_do_depth] = sim_on_check[sim_do_depth-1]; /* inherit On mode */ for (i=0; i= 0) { free(sim_on_actions[sim_do_depth][i]); @@ -1782,7 +1782,7 @@ char *ip = instr, *op, *ap, *oend, *istart, *tmpbuf; char rbuf[CBUFSIZE]; int i; -tmpbuf = malloc(instr_size); +tmpbuf = (char *)malloc(instr_size); op = tmpbuf; oend = tmpbuf + instr_size - 2; while (isspace (*ip)) /* skip leading spaces */ @@ -2072,7 +2072,7 @@ if ((NULL == cptr) || ('\0' == *cptr)) { /* Empty Action */ sim_on_actions[sim_do_depth][cond] = NULL; } else { sim_on_actions[sim_do_depth][cond] = - realloc(sim_on_actions[sim_do_depth][cond], 1+strlen(cptr)); + (char *)realloc(sim_on_actions[sim_do_depth][cond], 1+strlen(cptr)); strcpy(sim_on_actions[sim_do_depth][cond], cptr); } return SCPE_OK; @@ -2112,13 +2112,13 @@ sim_on_check[sim_do_depth] = flag; if ((sim_do_depth != 0) && (NULL == sim_on_actions[sim_do_depth][0])) { /* default handler set? */ sim_on_actions[sim_do_depth][0] = /* No, so make "RETURN" */ - malloc(1+strlen("RETURN")); /* be the default action */ + (char *)malloc(1+strlen("RETURN")); /* be the default action */ strcpy(sim_on_actions[sim_do_depth][0], "RETURN"); } if ((sim_do_depth != 0) && (NULL == sim_on_actions[sim_do_depth][SCPE_AFAIL])) {/* handler set for AFAIL? */ sim_on_actions[sim_do_depth][SCPE_AFAIL] = /* No, so make "RETURN" */ - malloc(1+strlen("RETURN")); /* be the action */ + (char *)malloc(1+strlen("RETURN")); /* be the action */ strcpy(sim_on_actions[sim_do_depth][SCPE_AFAIL], "RETURN"); } return SCPE_OK; @@ -4288,12 +4288,12 @@ for ( ;; ) { /* device loop */ if (flg & UNIT_RO) /* [V2.10+] saved flgs & RO? */ sim_switches |= SWMASK ('R'); /* RO attach */ /* add unit to list of units to attach after registers are read */ - attunits = realloc (attunits, sizeof (*attunits)*(attcnt+1)); + attunits = (UNIT **)realloc (attunits, sizeof (*attunits)*(attcnt+1)); attunits[attcnt] = uptr; - attnames = realloc (attnames, sizeof (*attnames)*(attcnt+1)); - attnames[attcnt] = malloc(1+strlen(buf)); + attnames = (char **)realloc (attnames, sizeof (*attnames)*(attcnt+1)); + attnames[attcnt] = (char *)malloc(1+strlen(buf)); strcpy (attnames[attcnt], buf); - attswitches = realloc (attswitches, sizeof (*attswitches)*(attcnt+1)); + attswitches = (int32 *)realloc (attswitches, sizeof (*attswitches)*(attcnt+1)); attswitches[attcnt] = sim_switches; ++attcnt; } @@ -4397,6 +4397,7 @@ for ( ;; ) { /* device loop */ for (j=0, r = SCPE_OK; jpos; sim_switches = attswitches[j]; r = scp_attach_unit (dptr, attunits[j], attnames[j]);/* reattach unit */ + attunits[j]->pos = saved_pos; if (r != SCPE_OK) { printf ("Error Attaching %s to %s\n", sim_dname (dptr), attnames[j]); if (sim_log) @@ -5705,7 +5708,7 @@ for (i = 0; i < sim_internal_device_count; i++) if (sim_internal_devices[i] == dptr) return SCPE_OK; ++sim_internal_device_count; -sim_internal_devices = realloc(sim_internal_devices, (sim_internal_device_count+1)*sizeof(*sim_internal_devices)); +sim_internal_devices = (DEVICE **)realloc(sim_internal_devices, (sim_internal_device_count+1)*sizeof(*sim_internal_devices)); sim_internal_devices[sim_internal_device_count-1] = dptr; sim_internal_devices[sim_internal_device_count] = NULL; return SCPE_OK; @@ -7099,7 +7102,7 @@ if (sim_deb && (dptr->dctrl & dbits)) { /* Set unterminated flag for next time */ - debug_unterm = (len && (buf[len-1]=='\n')) ? 0 : 1; + debug_unterm = len ? (((buf[len-1]=='\n')) ? 0 : 1) : debug_unterm; if (buf != stackbuf) free (buf); } diff --git a/scp.h b/scp.h index a8aec6b2..5d4afad3 100644 --- a/scp.h +++ b/scp.h @@ -136,6 +136,7 @@ BRKTAB *sim_brk_fnd (t_addr loc); uint32 sim_brk_test (t_addr bloc, uint32 btyp); void sim_brk_clrspc (uint32 spc); char *match_ext (char *fnam, char *ext); +t_stat show_version (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr); t_stat set_dev_debug (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr); t_stat show_dev_debug (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr); const char *sim_error_text (t_stat stat); diff --git a/sim_BuildROMs.c b/sim_BuildROMs.c index 5f706cef..8e7eef21 100644 --- a/sim_BuildROMs.c +++ b/sim_BuildROMs.c @@ -104,7 +104,7 @@ while (fgets (line, sizeof(line)-1, iFile)) { case '\n': break; case 'u': /* unsigned char {array_name}[] */ - *prom_array_name = calloc(512, sizeof(char)); + *prom_array_name = (char *)calloc(512, sizeof(char)); if (1 == sscanf (line, "unsigned char %s[]", *prom_array_name)) { c = strchr (*prom_array_name, '['); if (c) @@ -116,7 +116,7 @@ while (fgets (line, sizeof(line)-1, iFile)) { while (1 == sscanf (c, "0x%2Xd,", &byte)) { if (bytes_written >= allocated_size) { allocated_size += 2048; - *pROMData = realloc(*pROMData, allocated_size); + *pROMData = (unsigned char *)realloc(*pROMData, allocated_size); } *(*pROMData + bytes_written++) = byte; c += 5; @@ -155,7 +155,7 @@ if (stat (rom_filename, &statb)) { fclose (rFile); return -1; } -ROMData = malloc (statb.st_size); +ROMData = (unsigned char *)malloc (statb.st_size); if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) { printf ("Error reading '%s': %s\n", rom_filename, strerror(errno)); fclose (rFile); @@ -242,7 +242,7 @@ if (statb.st_size != expected_size) { fclose (rFile); return -1; } -ROMData = malloc (statb.st_size); +ROMData = (unsigned char *)malloc (statb.st_size); if ((size_t)(statb.st_size) != fread (ROMData, sizeof(*ROMData), statb.st_size, rFile)) { printf ("Error reading '%s': %s\n", rom_filename, strerror(errno)); fclose (rFile); diff --git a/sim_console.c b/sim_console.c index 8d222a99..8f7c9caa 100644 --- a/sim_console.c +++ b/sim_console.c @@ -618,7 +618,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0); } if (sim_rem_buf_ptr[i]+80 >= sim_rem_buf_size[i]) { sim_rem_buf_size[i] += 1024; - sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); + sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]); } strcpy (sim_rem_buf[i], "CONTINUE ! Automatic continue due to timeout"); tmxr_linemsgf (lp, "%s\n", sim_rem_buf[i]); @@ -656,7 +656,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0); tmxr_linemsg (lp, "\r\n"); if (sim_rem_buf_ptr[i]+1 >= sim_rem_buf_size[i]) { sim_rem_buf_size[i] += 1024; - sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); + sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]); } sim_rem_buf[i][sim_rem_buf_ptr[i]++] = '\0'; got_command = TRUE; @@ -670,7 +670,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0); if (!sim_rem_single_mode[i]) { if (sim_rem_buf_ptr[i]+80 >= sim_rem_buf_size[i]) { sim_rem_buf_size[i] += 1024; - sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); + sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]); } strcpy (sim_rem_buf[i], "CONTINUE ! Automatic continue before close"); tmxr_linemsgf (lp, "%s\n", sim_rem_buf[i]); @@ -682,7 +682,7 @@ for (i=(was_stepping ? sim_rem_step_line : 0); tmxr_putc_ln (lp, c); if (sim_rem_buf_ptr[i]+2 >= sim_rem_buf_size[i]) { sim_rem_buf_size[i] += 1024; - sim_rem_buf[i] = realloc (sim_rem_buf[i], sim_rem_buf_size[i]); + sim_rem_buf[i] = (char *)realloc (sim_rem_buf[i], sim_rem_buf_size[i]); } sim_rem_buf[i][sim_rem_buf_ptr[i]++] = c; sim_rem_buf[i][sim_rem_buf_ptr[i]] = '\0'; @@ -895,15 +895,15 @@ if (sim_rem_con_tmxr.master) for (i=0; iunits), gbuf); + if (sim_log) + fprintf (sim_log, "%s%d: creating new virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); + } capac_factor = ((dptr->dwidth / dptr->aincr) == 16) ? 2 : 1; /* capacity units (word: 2, byte: 1) */ vhd = sim_vhd_disk_create (gbuf, ((t_offset)uptr->capac)*capac_factor*((dptr->flags & DEV_SECTORS) ? 512 : 1)); if (!vhd) { - if (!sim_quiet) + if (!sim_quiet) { printf ("%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); + if (sim_log) + fprintf (sim_log, "%s%d: can't create virtual disk '%s'\n", sim_dname (dptr), (int)(uptr-dptr->units), gbuf); + } return SCPE_OPENERR; } else { @@ -898,8 +904,11 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop return SCPE_MEM; } for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) { - if (!sim_quiet) + if (!sim_quiet) { printf ("%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); + if (sim_log) + fprintf (sim_log, "%s%d: Copied %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); + } sects = sectors_per_buffer; if (lba + sects > total_sectors) sects = total_sectors - lba; @@ -916,10 +925,16 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop } } if (!sim_quiet) { - if (r == SCPE_OK) + if (r == SCPE_OK) { printf ("\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); - else + if (sim_log) + fprintf (sim_log, "\n%s%d: Copied %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); + } + else { printf ("\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r)); + if (sim_log) + fprintf (sim_log, "\n%s%d: Error copying: %s.\n", sim_dname (dptr), (int)(uptr-dptr->units), sim_error_text (r)); + } } if ((r == SCPE_OK) && (sim_switches & SWMASK ('V'))) { uint8 *verify_buf = (uint8*) malloc (1024*1024); @@ -931,8 +946,11 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop return SCPE_MEM; } for (lba = 0; (lba < total_sectors) && (r == SCPE_OK); lba += sects) { - if (!sim_quiet) + if (!sim_quiet) { printf ("%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); + if (sim_log) + fprintf (sim_log, "%s%d: Verified %dMB. %d%% complete.\r", sim_dname (dptr), (int)(uptr-dptr->units), (int)((((float)lba)*sector_size)/1000000), (int)((((float)lba)*100)/total_sectors)); + } sects = sectors_per_buffer; if (lba + sects > total_sectors) sects = total_sectors - lba; @@ -953,8 +971,11 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop } } if (!sim_quiet) { - if (r == SCPE_OK) + if (r == SCPE_OK) { printf ("\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); + if (sim_log) + fprintf (sim_log, "\n%s%d: Verified %dMB. Done.\n", sim_dname (dptr), (int)(uptr-dptr->units), (int)(((t_offset)lba*sector_size)/1000000)); + } else { t_lba i; uint32 save_dctrl = dptr->dctrl; @@ -964,6 +985,8 @@ if (sim_switches & SWMASK ('C')) { /* create vhd disk & cop if (0 != memcmp (copy_buf+i*sector_size, verify_buf+i*sector_size, sector_size)) break; printf ("\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i); + if (sim_log) + fprintf (sim_log, "\n%s%d: Verification Error on lbn %d.\n", sim_dname (dptr), (int)(uptr-dptr->units), lba+i); dptr->dctrl = 0xFFFFFFFF; sim_deb = stdout; sim_disk_data_trace (uptr, copy_buf+i*sector_size, lba+i, sector_size, "Expected", TRUE, 1); @@ -1052,8 +1075,11 @@ if (sim_switches & SWMASK ('R')) { /* read only? */ if (uptr->fileref == NULL) /* open fail? */ return _err_return (uptr, SCPE_OPENERR); /* yes, error */ uptr->flags = uptr->flags | UNIT_RO; /* set rd only */ - if (!sim_quiet) + if (!sim_quiet) { printf ("%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); + if (sim_log) + fprintf (sim_log, "%s%d: unit is read only\n", sim_dname (dptr), (int)(uptr-dptr->units)); + } } else { /* normal */ uptr->fileref = open_function (cptr, "rb+"); /* open r/w */ @@ -1102,7 +1128,7 @@ if (storage_function) if ((created) && (!copied)) { t_stat r = SCPE_OK; - uint8 *secbuf = calloc (1, ctx->sector_size); /* alloc temp sector buf */ + uint8 *secbuf = (uint8 *)calloc (1, ctx->sector_size); /* alloc temp sector buf */ /* On a newly created disk, we write a zero sector to the last and the @@ -1141,6 +1167,13 @@ if (capac && (capac != (t_offset)-1)) { printf ("%s < ", (ctx->capac_factor == 2) ? "W" : ""); fprint_val (stdout, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT); printf ("%s)\n", (ctx->capac_factor == 2) ? "W" : ""); + if (sim_log) { + fprintf (sim_log, "%s%d: non expandable disk %s is smaller than simulated device (", sim_dname (dptr), (int)(uptr-dptr->units), cptr); + fprint_val (sim_log, (t_addr)(capac/ctx->capac_factor), 10, T_ADDR_W, PV_LEFT); + fprintf (sim_log, "%s < ", (ctx->capac_factor == 2) ? "W" : ""); + fprint_val (sim_log, uptr->capac*((dptr->flags & DEV_SECTORS) ? 512 : 1), 10, T_ADDR_W, PV_LEFT); + fprintf (sim_log, "%s)\n", (ctx->capac_factor == 2) ? "W" : ""); + } } } } diff --git a/sim_ether.c b/sim_ether.c index 85d24096..143ee168 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -670,7 +670,7 @@ static int eth_open_device_count = 0; #if defined (USE_NETWORK) || defined (USE_SHARED) static void _eth_add_to_open_list (ETH_DEV* dev) { -eth_open_devices = realloc(eth_open_devices, (eth_open_device_count+1)*sizeof(*eth_open_devices)); +eth_open_devices = (ETH_DEV**)realloc(eth_open_devices, (eth_open_device_count+1)*sizeof(*eth_open_devices)); eth_open_devices[eth_open_device_count++] = dev; } @@ -824,7 +824,7 @@ void ethq_insert_data(ETH_QUE* que, int32 type, const uint8 *data, int used, siz memcpy(&item->packet.msg[len], crc_data, ETH_CRC_SIZE); } else { - item->packet.oversize = realloc (item->packet.oversize, ((len > crc_len) ? len : crc_len)); + item->packet.oversize = (uint8 *)realloc (item->packet.oversize, ((len > crc_len) ? len : crc_len)); memcpy(item->packet.oversize, data, ((len > crc_len) ? len : crc_len)); if (crc_data && (crc_len > len)) memcpy(&item->packet.oversize[len], crc_data, ETH_CRC_SIZE); @@ -1282,7 +1282,7 @@ static int pcap_mac_if_win32(char *AdapterName, unsigned char MACAddress[6]) /* Allocate a buffer to get the MAC adress */ - OidData = malloc(6 + sizeof(PACKET_OID_DATA)); + OidData = (PACKET_OID_DATA *)malloc(6 + sizeof(PACKET_OID_DATA)); if (OidData == NULL) { p_PacketCloseAdapter(lpAdapter); #ifdef _WIN32 @@ -1845,7 +1845,7 @@ if (sim_log) fprintf (sim_log, msg, savname); eth_get_nic_hw_addr(dev, savname); /* save name of device */ -dev->name = malloc(strlen(savname)+1); +dev->name = (char *)malloc(strlen(savname)+1); strcpy(dev->name, savname); /* save debugging information */ @@ -2216,7 +2216,7 @@ if (NULL != (request = dev->write_buffers)) dev->write_buffers = request->next; pthread_mutex_unlock (&dev->writer_lock); if (NULL == request) - request = malloc(sizeof(*request)); + request = (struct write_request *)malloc(sizeof(*request)); /* Copy buffer contents */ request->packet.len = packet->len; @@ -2700,7 +2700,7 @@ int bpf_used; if ((dev->have_host_nic_phy_addr) && (LOOPBACK_PHYSICAL_RESPONSE(dev->host_nic_phy_hw_addr, dev->physical_addr, data))) { - u_char *datacopy = malloc(header->len); + u_char *datacopy = (u_char *)malloc(header->len); memcpy(datacopy, data, header->len); memcpy(datacopy, dev->physical_addr, sizeof(ETH_MAC)); @@ -2781,10 +2781,10 @@ if (bpf_used ? to_me : (to_me && !from_me)) { int crc_len = 0; uint8 crc_data[4]; uint32 len = header->len; - u_char* moved_data = NULL; + u_char *moved_data = NULL; if (header->len < ETH_MIN_PACKET) { /* Pad runt packets before CRC append */ - moved_data = malloc(ETH_MIN_PACKET); + moved_data = (u_char *)malloc(ETH_MIN_PACKET); memcpy(moved_data, data, len); memset(moved_data + len, 0, ETH_MIN_PACKET-len); len = ETH_MIN_PACKET; diff --git a/sim_serial.c b/sim_serial.c index 9cdd78ae..0959c4cd 100644 --- a/sim_serial.c +++ b/sim_serial.c @@ -182,7 +182,7 @@ return NULL; static struct open_serial_device *_serial_add_to_open_list (SERHANDLE port, TMLN *line, const char *name, const char *config) { -serial_open_devices = realloc(serial_open_devices, (++serial_open_device_count)*sizeof(*serial_open_devices)); +serial_open_devices = (struct open_serial_device *)realloc(serial_open_devices, (++serial_open_device_count)*sizeof(*serial_open_devices)); memset(&serial_open_devices[serial_open_device_count-1], 0, sizeof(serial_open_devices[serial_open_device_count-1])); serial_open_devices[serial_open_device_count-1].port = port; serial_open_devices[serial_open_device_count-1].line = line; @@ -455,7 +455,7 @@ if (status != SCPE_OK) { /* port configuration er } if ((port != INVALID_HANDLE) && (*config) && (lp)) { - lp->serconfig = realloc (lp->serconfig, 1 + strlen (config)); + lp->serconfig = (char *)realloc (lp->serconfig, 1 + strlen (config)); strcpy (lp->serconfig, config); } if (port != INVALID_HANDLE) @@ -506,7 +506,7 @@ if (strcmp (sptr, ".5") == 0) /* 1.5 stop bits request r = sim_config_os_serial (port, config); dev = _get_open_device (port); if (dev) { - dev->line->serconfig = realloc (dev->line->serconfig, 1 + strlen (sconfig)); + dev->line->serconfig = (char *)realloc (dev->line->serconfig, 1 + strlen (sconfig)); strcpy (dev->line->serconfig, sconfig); } return r; diff --git a/sim_sock.c b/sim_sock.c index 02be1bb2..0aa039cc 100644 --- a/sim_sock.c +++ b/sim_sock.c @@ -134,6 +134,7 @@ static struct sock_errors { {WSAEISCONN, "Transport endpoint is already connected"}, {WSAECONNRESET, "Connection reset by peer"}, {WSAECONNREFUSED, "Connection refused"}, + {WSAECONNABORTED, "Connection aborted"}, {WSAEHOSTUNREACH, "No route to host"}, {WSAEADDRINUSE, "Address already in use"}, #if defined (WSAEAFNOSUPPORT) @@ -154,14 +155,22 @@ int32 i; for (i=0; (sock_errors[i].text) && (sock_errors[i].value != err); i++) ; -if (sock_errors[i].value == err) +if (sock_errors[i].value == err) { printf ("Sockets: %s error %d - %s\n", emsg, err, sock_errors[i].text); -else + if (sim_log) + fprintf (sim_log, "Sockets: %s error %d - %s\n", emsg, err, sock_errors[i].text); + } +else { #if defined(_WIN32) printf ("Sockets: %s error %d\n", emsg, err); + if (sim_log) + fprintf (sim_log, "Sockets: %s error %d\n", emsg, err); #else printf ("Sockets: %s error %d - %s\n", emsg, err, strerror(err)); + if (sim_log) + fprintf (sim_log, "Sockets: %s error %d - %s\n", emsg, err, strerror(err)); #endif + } if (s != INVALID_SOCKET) sim_close_sock (s, flg); return INVALID_SOCKET; @@ -319,7 +328,7 @@ else { ips = fixed; } for (ip=ips; *ip != NULL; ++ip) { - ai = calloc(1, sizeof(*ai)); + ai = (struct addrinfo *)calloc(1, sizeof(*ai)); if (NULL == ai) { s_freeaddrinfo(result); return EAI_MEMORY; @@ -331,7 +340,7 @@ for (ip=ips; *ip != NULL; ++ip) { ai->ai_addrlen = sizeof(struct sockaddr_in); ai->ai_canonname = NULL; ai->ai_next = NULL; - ai->ai_addr = calloc(1, sizeof(struct sockaddr_in)); + ai->ai_addr = (struct sockaddr *)calloc(1, sizeof(struct sockaddr_in)); if (NULL == ai->ai_addr) { free(ai); s_freeaddrinfo(result); @@ -348,7 +357,7 @@ for (ip=ips; *ip != NULL; ++ip) { lai = ai; } if (cname) { - result->ai_canonname = calloc(1, strlen(cname)+1); + result->ai_canonname = (char *)calloc(1, strlen(cname)+1); if (NULL == result->ai_canonname) { s_freeaddrinfo(result); return EAI_MEMORY; @@ -446,7 +455,8 @@ static void load_function(char* function, _func* func_ptr) { char* msg = "Sockets: Failed to find function '%s' in %s\r\n"; printf (msg, function, lib_name); - if (sim_log) fprintf (sim_log, msg, function, lib_name); + if (sim_log) + fprintf (sim_log, msg, function, lib_name); lib_loaded = 3; } } @@ -881,7 +891,7 @@ if (newsock == INVALID_SOCKET) { /* error? */ return INVALID_SOCKET; } if (connectaddr != NULL) { - *connectaddr = calloc(1, NI_MAXHOST+1); + *connectaddr = (char *)calloc(1, NI_MAXHOST+1); #ifdef AF_INET6 p_getnameinfo((struct sockaddr *)&clientname, size, *connectaddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); if (0 == memcmp("::ffff:", *connectaddr, 7)) /* is this a IPv4-mapped IPv6 address? */ @@ -989,9 +999,9 @@ char hostbuf[NI_MAXHOST+1]; char portbuf[NI_MAXSERV+1]; if (socknamebuf) - *socknamebuf = calloc(1, NI_MAXHOST+NI_MAXSERV+4); + *socknamebuf = (char *)calloc(1, NI_MAXHOST+NI_MAXSERV+4); if (peernamebuf) - *peernamebuf = calloc(1, NI_MAXHOST+NI_MAXSERV+4); + *peernamebuf = (char *)calloc(1, NI_MAXHOST+NI_MAXSERV+4); getsockname (sock, (struct sockaddr *)&sockname, &socknamesize); getpeername (sock, (struct sockaddr *)&peername, &peernamesize); if (socknamebuf != NULL) { @@ -1024,6 +1034,7 @@ if (rbytes == SOCKET_ERROR) { if ((err != WSAETIMEDOUT) && /* expected errors after a connect failure */ (err != WSAEHOSTUNREACH) && (err != WSAECONNREFUSED) && + (err != WSAECONNABORTED) && (err != WSAECONNRESET)) sim_err_sock (INVALID_SOCKET, "read", 0); return -1; diff --git a/sim_sock.h b/sim_sock.h index 978730c8..44721c49 100644 --- a/sim_sock.h +++ b/sim_sock.h @@ -64,6 +64,7 @@ #define WSAEISCONN EISCONN #define WSAECONNRESET ECONNRESET #define WSAECONNREFUSED ECONNREFUSED +#define WSAECONNABORTED ECONNABORTED #define WSAEHOSTUNREACH EHOSTUNREACH #define WSAEADDRINUSE EADDRINUSE #if defined(EAFNOSUPPORT) diff --git a/sim_timer.h b/sim_timer.h index 8a56e696..4448567f 100644 --- a/sim_timer.h +++ b/sim_timer.h @@ -124,4 +124,3 @@ extern t_bool sim_asynch_timer; extern DEVICE sim_timer_dev; #endif - \ No newline at end of file