1
0
mirror of https://github.com/rcornwell/sims.git synced 2026-04-18 00:47:50 +00:00

SCP: Updated SCP to current.

This commit is contained in:
Richard Cornwell
2021-09-25 21:06:49 -04:00
parent c571cb938d
commit 82aa1b1280
3 changed files with 66 additions and 46 deletions

42
scp.c
View File

@@ -6361,12 +6361,10 @@ void fprint_capac (FILE *st, DEVICE *dptr, UNIT *uptr)
fprintf (st, "%s", sprint_capac (dptr, uptr));
}
static const char *_get_tool_version (const char *tool)
const char *sim_get_tool_path (const char *tool)
{
char findcmd[PATH_MAX+1];
char toolpath[PATH_MAX+1];
char versioncmd[PATH_MAX+1];
static char toolversion[PATH_MAX+1];
static char toolpath[PATH_MAX+1];
FILE *f;
#if defined(_WIN32)
@@ -6376,27 +6374,37 @@ FILE *f;
#else
#define FIND_CMD "which"
#endif
toolversion[0] = '\0';
memset (toolpath, 0, sizeof(toolpath));
snprintf (findcmd, sizeof (findcmd), "%s %s", FIND_CMD, tool);
if ((f = popen (findcmd, "r"))) {
memset (toolpath, 0, sizeof(toolpath));
do {
if (NULL == fgets (toolpath, sizeof(toolpath)-1, f))
break;
sim_trim_endspc (toolpath);
} while (toolpath[0] == '\0');
pclose (f);
if (toolpath[0]) {
snprintf (versioncmd, sizeof (versioncmd), "%s --version", tool);
if ((f = popen (versioncmd, "r"))) {
memset (toolversion, 0, sizeof(toolversion));
do {
if (NULL == fgets (toolversion, sizeof(toolversion)-1, f))
break;
sim_trim_endspc (toolversion);
} while (toolversion[0] == '\0');
pclose (f);
}
}
return toolpath;
}
static const char *_get_tool_version (const char *tool)
{
const char *toolpath;
char versioncmd[PATH_MAX+1];
static char toolversion[PATH_MAX+1];
FILE *f;
memset (toolversion, 0, sizeof(toolversion));
toolpath = sim_get_tool_path (tool);
if (toolpath[0]) {
snprintf (versioncmd, sizeof (versioncmd), "%s --version", tool);
if ((f = popen (versioncmd, "r"))) {
do {
if (NULL == fgets (toolversion, sizeof(toolversion)-1, f))
break;
sim_trim_endspc (toolversion);
} while (toolversion[0] == '\0');
pclose (f);
}
}
return toolversion;

1
scp.h
View File

@@ -247,6 +247,7 @@ const char *sim_error_text (t_stat stat);
t_stat sim_string_to_stat (const char *cptr, t_stat *cond);
t_stat sim_sched_step (void);
t_stat sim_cancel_step (void);
const char *sim_get_tool_path (const char *tool);
void sim_printf (const char *fmt, ...) GCC_FMT_ATTR(1, 2);
void sim_perror (const char *msg);
t_stat sim_messagef (t_stat stat, const char *fmt, ...) GCC_FMT_ATTR(2, 3);

View File

@@ -1753,6 +1753,11 @@ static void eth_get_nic_hw_addr(ETH_DEV* dev, const char *devname)
char command[1024];
FILE *f;
int i;
char tool[CBUFSIZE];
const char *turnon[] = {
"ip link set dev %.*s up",
"ifconfig %.*s up",
NULL};
const char *patterns[] = {
"ip link show %.*s | grep [0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]:[0-9a-fA-F][0-9a-fA-F]",
"ip link show %.*s | egrep [0-9a-fA-F]?[0-9a-fA-F]:[0-9a-fA-F]?[0-9a-fA-F]:[0-9a-fA-F]?[0-9a-fA-F]:[0-9a-fA-F]?[0-9a-fA-F]:[0-9a-fA-F]?[0-9a-fA-F]:[0-9a-fA-F]?[0-9a-fA-F]",
@@ -1762,40 +1767,47 @@ static void eth_get_nic_hw_addr(ETH_DEV* dev, const char *devname)
memset(command, 0, sizeof(command));
/* try to force an otherwise unused interface to be turned on */
snprintf(command, sizeof(command)-1, "ip link set dev %.*s up", (int)(sizeof(command) - 21), devname);
if (system(command)) {};
snprintf(command, sizeof(command)-1, "ifconfig %.*s up", (int)(sizeof(command) - 14), devname);
if (system(command)) {};
for (i=0; turnon[i]; ++i) {
snprintf(command, sizeof(command), turnon[i], (int)(sizeof(command) - (2 + strlen(patterns[i]))), devname);
get_glyph_nc (command, tool, 0);
if (sim_get_tool_path (tool)[0]) {
if (NULL != (f = popen(command, "r")))
pclose(f);
}
}
for (i=0; patterns[i] && (0 == dev->have_host_nic_phy_addr); ++i) {
snprintf(command, sizeof(command)-1, patterns[i], (int)(sizeof(command) - (2 + strlen(patterns[i]))), devname);
if (NULL != (f = popen(command, "r"))) {
while (0 == dev->have_host_nic_phy_addr) {
if (fgets(command, sizeof(command)-1, f)) {
char *p1, *p2;
snprintf(command, sizeof(command), patterns[i], (int)(sizeof(command) - (2 + strlen(patterns[i]))), devname);
get_glyph_nc (command, tool, 0);
if (sim_get_tool_path (tool)[0]) {
if (NULL != (f = popen(command, "r"))) {
while (0 == dev->have_host_nic_phy_addr) {
if (fgets(command, sizeof(command)-1, f)) {
char *p1, *p2;
p1 = strchr(command, ':');
while (p1) {
p2 = strchr(p1+1, ':');
if (p2 <= p1+3) {
unsigned int mac_bytes[6];
if (6 == sscanf(p1-2, "%02x:%02x:%02x:%02x:%02x:%02x", &mac_bytes[0], &mac_bytes[1], &mac_bytes[2], &mac_bytes[3], &mac_bytes[4], &mac_bytes[5])) {
dev->host_nic_phy_hw_addr[0] = mac_bytes[0];
dev->host_nic_phy_hw_addr[1] = mac_bytes[1];
dev->host_nic_phy_hw_addr[2] = mac_bytes[2];
dev->host_nic_phy_hw_addr[3] = mac_bytes[3];
dev->host_nic_phy_hw_addr[4] = mac_bytes[4];
dev->host_nic_phy_hw_addr[5] = mac_bytes[5];
dev->have_host_nic_phy_addr = 1;
p1 = strchr(command, ':');
while (p1) {
p2 = strchr(p1+1, ':');
if (p2 <= p1+3) {
unsigned int mac_bytes[6];
if (6 == sscanf(p1-2, "%02x:%02x:%02x:%02x:%02x:%02x", &mac_bytes[0], &mac_bytes[1], &mac_bytes[2], &mac_bytes[3], &mac_bytes[4], &mac_bytes[5])) {
dev->host_nic_phy_hw_addr[0] = mac_bytes[0];
dev->host_nic_phy_hw_addr[1] = mac_bytes[1];
dev->host_nic_phy_hw_addr[2] = mac_bytes[2];
dev->host_nic_phy_hw_addr[3] = mac_bytes[3];
dev->host_nic_phy_hw_addr[4] = mac_bytes[4];
dev->host_nic_phy_hw_addr[5] = mac_bytes[5];
dev->have_host_nic_phy_addr = 1;
}
break;
}
break;
p1 = p2;
}
p1 = p2;
}
else
break;
}
else
break;
pclose(f);
}
pclose(f);
}
}
}
@@ -2382,8 +2394,7 @@ else { /* !tap: */
char command[1024];
/* try to force an otherwise unused interface to be turned on */
memset(command, 0, sizeof(command));
snprintf(command, sizeof(command)-1, "ifconfig %s up", savname);
snprintf(command, sizeof(command), (sim_get_tool_path ("ifconfig")[0] != '\0') ? "ifconfig %s up" : "ip link set dev %s up", savname);
if (system(command)) {};
errbuf[0] = '\0';
*handle = (void*) pcap_open_live(savname, bufsz, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf);