Mercurial > repos > blastem
annotate net.c @ 1876:96971b673f51
Only do full sync on VDP data port reads instead of all VDP port reads, provides a perf bump for games that busy wait on the status or HV registers
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 19 Aug 2019 19:15:52 -0700 |
parents | 78abbabfd58d |
children |
rev | line source |
---|---|
1514
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <sys/types.h> |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <ifaddrs.h> |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <netinet/in.h> |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "net.h" |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 static uint8_t is_loopback(struct sockaddr_in *addr) |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 return (addr->sin_addr.s_addr & 0xFF) == 127; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 static void format_address(uint8_t *dst, struct sockaddr_in *addr) |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 long ip = addr->sin_addr.s_addr; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 dst[0] = ip; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 dst[1] = ip >> 8; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 dst[2] = ip >> 16; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 dst[3] = ip >> 24; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 uint8_t get_host_address(iface_info *out) |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1514
diff
changeset
|
22 #ifdef __ANDROID__ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1514
diff
changeset
|
23 //TODO: write an implementation for Android |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1514
diff
changeset
|
24 return 0; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1514
diff
changeset
|
25 #else |
1514
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 struct ifaddrs *entries, *current, *localhost; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 if (getifaddrs(&entries)) { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 return 0; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 for (current = entries; current; current = current->ifa_next) |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 if (current->ifa_addr && current->ifa_addr->sa_family == AF_INET) { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 struct sockaddr_in *addr = (struct sockaddr_in *)current->ifa_addr; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 if (is_loopback(addr)) { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 localhost = current; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } else { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 break; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 if (!current && localhost) { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 current = localhost; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 uint8_t ret = 0; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 if (current) { |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 ret = 1; |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 format_address(out->ip, (struct sockaddr_in *)current->ifa_addr); |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 format_address(out->net_mask, (struct sockaddr_in *)current->ifa_netmask); |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 freeifaddrs(entries); |
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 return ret; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1514
diff
changeset
|
53 #endif |
1514
4f94e0f90c83
Added support for MegaWiFi command IP_CURRENT
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 } |