1
0
mirror of https://github.com/simh/simh.git synced 2026-04-19 09:19:40 +00:00

ETHER, SOCK: Update latest from master branch

This commit is contained in:
Mark Pizzolato
2020-06-07 12:45:41 -07:00
parent bc2e8df1e1
commit 4289d79bbf
4 changed files with 52 additions and 41 deletions

View File

@@ -1,6 +1,6 @@
/* sim_sock.c: OS-dependent socket routines
Copyright (c) 2001-2019, Robert M Supnik
Copyright (c) 2001-2010, Robert M Supnik
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@@ -23,7 +23,6 @@
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Robert M Supnik.
22-Nov-19 MP Latest 4.X changes
15-Oct-12 MP Added definitions needed to detect possible tcp
connect failures
25-Sep-12 MP Reworked for RFC3493 interfaces supporting IPv6 and IPv4
@@ -263,6 +262,7 @@ if (service) {
char *c;
port = strtoul(service, &c, 10);
port = htons((unsigned short)port);
if ((port == 0) || (*c != '\0')) {
switch (hints->ai_socktype)
{
@@ -432,6 +432,10 @@ return 0;
#if !defined(IPV6_V6ONLY) /* Older XP environments may not define IPV6_V6ONLY */
#define IPV6_V6ONLY 27 /* Treat wildcard bind as AF_INET6-only. */
#endif
#if defined(TEST_INFO_STUBS)
#undef IPV6_V6ONLY
#undef AF_INET6
#endif
/* Dynamic DLL load variables */
#ifdef _WIN32
static HINSTANCE hLib = 0; /* handle to DLL */
@@ -684,7 +688,7 @@ return 0;
port = pointer to buffer for IP port (may be NULL), 0 = none
localport
= pointer to buffer for local IP port (may be NULL), 0 = none
result = status (SCPE_OK on complete success or SCPE_ARG if
result = status (0 on complete success or -1 if
parsing can't happen due to bad syntax, a value is
out of range, a result can't fit into a result buffer,
a service name doesn't exist, or a validation name
@@ -739,6 +743,12 @@ load_ws2 ();
#if defined (SIGPIPE)
signal (SIGPIPE, SIG_IGN); /* no pipe signals */
#endif
#if defined(TEST_INFO_STUBS)
/* force use of stubs */
p_getaddrinfo = (getaddrinfo_func)s_getaddrinfo;
p_getnameinfo = (getnameinfo_func)s_getnameinfo;
p_freeaddrinfo = (freeaddrinfo_func)s_freeaddrinfo;
#endif
}
void sim_cleanup_sock (void)
@@ -918,7 +928,7 @@ if (sta == SOCKET_ERROR) /* bind error? */
if (!(opt_flags & SIM_SOCK_OPT_BLOCKING)) {
sta = sim_setnonblock (newsock); /* set nonblocking */
if (sta == SOCKET_ERROR) /* fcntl error? */
return sim_err_sock (newsock, "fcntl");
return sim_err_sock (newsock, "setnonblock");
}
sta = listen (newsock, 1); /* listen on socket */
if (sta == SOCKET_ERROR) /* listen error? */
@@ -990,7 +1000,7 @@ if (!(opt_flags & SIM_SOCK_OPT_BLOCKING)) {
sta = sim_setnonblock (newsock); /* set nonblocking */
if (sta == SOCKET_ERROR) { /* fcntl error? */
p_freeaddrinfo (result);
return sim_err_sock (newsock, "fcntl");
return sim_err_sock (newsock, "setnonblock");
}
}
if ((!(opt_flags & SIM_SOCK_OPT_DATAGRAM)) && (opt_flags & SIM_SOCK_OPT_NODELAY)) {
@@ -1064,20 +1074,16 @@ if (newsock == INVALID_SOCKET) { /* error? */
}
if (connectaddr != NULL) {
*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? */
memmove(*connectaddr, 7+*connectaddr, /* prefer bare IPv4 address */
strlen(*connectaddr) - 7 + 1); /* length to include terminating \0 */
#else
strcpy(*connectaddr, inet_ntoa(((struct sockaddr_in *)&connectaddr)->s_addr));
#endif
}
if (!(opt_flags & SIM_SOCK_OPT_BLOCKING)) {
sta = sim_setnonblock (newsock); /* set nonblocking */
if (sta == SOCKET_ERROR) /* fcntl error? */
return sim_err_sock (newsock, "fcntl");
return sim_err_sock (newsock, "setnonblock");
}
if ((opt_flags & SIM_SOCK_OPT_NODELAY)) {
@@ -1152,7 +1158,6 @@ size_t size = addrsize;
#endif
int ret = 0;
#ifdef AF_INET6
*hostnamebuf = '\0';
*portnamebuf = '\0';
ret = p_getnameinfo(addr, size, hostnamebuf, NI_MAXHOST, NULL, 0, NI_NUMERICHOST);
@@ -1161,10 +1166,6 @@ if (0 == memcmp("::ffff:", hostnamebuf, 7)) /* is this a IPv4-mapped IPv6
strlen(hostnamebuf) + 7 - 1); /* length to include terminating \0 */
if (!ret)
ret = p_getnameinfo(addr, size, NULL, 0, portnamebuf, NI_MAXSERV, NI_NUMERICSERV);
#else
strcpy(hostnamebuf, inet_ntoa(((struct sockaddr_in *)addr)->s_addr));
sprintf(portnamebuf, "%d", (int)ntohs(((struct sockaddr_in *)addr)->s_port)));
#endif
return ret;
}