-
Notifications
You must be signed in to change notification settings - Fork 128
Added Linux support to qc_handle_{accept,bind,connect} functions. #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
0839660
59a223a
1377261
df08c4c
1f63f61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -40,6 +40,74 @@ static int32_t find_free_socket(void) { | |||||||||||||||||||||||||||||
return -1; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
/* NETWORK_HACK: | ||||||||||||||||||||||||||||||
See `guest-services/socket.h`: | ||||||||||||||||||||||||||||||
Darwin still uses `sin_len` in sockaddr, | ||||||||||||||||||||||||||||||
causing errors when copying memory from iOS. | ||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||
#ifdef __APPLE__ | ||||||||||||||||||||||||||||||
# define ADDR addr | ||||||||||||||||||||||||||||||
# undef NETWORK_HACK | ||||||||||||||||||||||||||||||
#else /* Linux, etc. */ | ||||||||||||||||||||||||||||||
# define ADDR darwin_addr | ||||||||||||||||||||||||||||||
# define NETWORK_HACK 1 | ||||||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
static int convert_error(int err) { | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
#ifndef NETWORK_HACK | ||||||||||||||||||||||||||||||
|
#ifndef NETWORK_HACK | |
#ifdef __APPLE__ |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice that you only call this function when NETWORK_HACK
is defined, which means the following:
- The
#ifndef
inside the function is redundant - The name of the function can be more explicit, such as
convert_sockaddr_darwin_to_gnu
- It should receive
darwin_sockaddr_in
explicitly (and theS_SOCKADDR_IN
define can be dropped)
static struct sockaddr_in convert_sockaddr_to(S_SOCKADDR_IN from) { | |
static struct sockaddr_in convert_sockaddr_darwin_to_gnu(darwin_sockaddr_in from) { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant...
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can use modern features (compound literals and struct initialization) to make code more compact, something like:
struct sockaddr_in to; | |
to.sin_family = from.sin_family; | |
to.sin_port = from.sin_port; | |
to.sin_addr = from.sin_addr; | |
memset(&to.sin_zero, 0, sizeof(to.sin_zero)); | |
return to; | |
return (sockaddr_in) { | |
from.sin_family, | |
from.sin_port, | |
from.sin_addr, | |
{ [0 ... sizeof(from.sin_zero) - 1] = 0 } }; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above...
static S_SOCKADDR_IN convert_sockaddr_from(struct sockaddr_in from) { | |
static struct darwin_sockaddr_in convert_sockaddr_gnu_to_darwin(sockaddr_in from) { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant...
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above...
S_SOCKADDR_IN to; | |
to.sin_family = from.sin_family; | |
to.sin_port = from.sin_port; | |
to.sin_addr = from.sin_addr; | |
to.sin_len = sizeof(to); | |
memset(&to.sin_zero, 0, sizeof(to.sin_zero)); | |
return to; | |
return (darwin_sockaddr_in) { | |
sizeof(struct darwin_sockaddr_in), | |
from.sin_family, | |
from.sin_port, | |
from.sin_addr, | |
{ [0 ... sizeof(from.sin_zero) - 1] = 0 } }; |
I know I'm using sizeof(from.sin_zero)
instead of sizeof(to.sin_zero)
, but luckily, those sizes are the same.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S_SOCKADDR can always be darwin_sockaddr
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SOCKLEN_T addrlen; | |
addrlen = sizeof(addr); | |
socklen_t addrlen = sizeof(addr); |
aronsky marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef NETWORK_HACK | |
S_SOCKADDR_IN ADDR = convert_sockaddr_from(addr); | |
#endif | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &ADDR, | |
sizeof(ADDR), 1); | |
#ifndef __APPLE__ | |
darwin_sockaddr_in darwin_addr = convert_sockaddr_gnu_to_darwin(addr); | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &darwin_addr, | |
sizeof(darwin_addr), 1); | |
#else | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &addr, | |
sizeof(addr), 1); | |
#endif |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will necessarily be darwin_sockaddr_in darwin_addr
, if __APPLE__
is defined...
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the change in accept
:
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &ADDR, | |
sizeof(ADDR), 0); | |
#ifdef NETWORK_HACK | |
addr = convert_sockaddr_to(ADDR); | |
#endif | |
#ifndef __APPLE__ | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &darwin_addr, | |
sizeof(darwin_addr), 0); | |
addr = convert_sockaddr_to(darwin_addr); | |
#else | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &addr, | |
sizeof(addr), 0); | |
#endif |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#ifdef NETWORK_HACK | |
ADDR = convert_sockaddr_from(addr); | |
#endif | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &ADDR, | |
sizeof(ADDR), 1); | |
#ifndef __APPLE__ | |
darwin_addr = convert_sockaddr_from(addr); | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &addr, | |
sizeof(addr), 1); | |
#else | |
cpu_memory_rw_debug(cpu, (target_ulong) g_addr, (uint8_t*) &addr, | |
sizeof(addr), 1); | |
#endif |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to bind
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason for the
NETWORK_HACK
andADDR
defines, we can condition the functions based on__APPLE__
only.