a0209881bf376d8dc056b4a18a816fc0ac0dc18c
[stouyapi.git] / src / push-to-my-ouya-helpers.php
1 <?php
2 /**
3  * Helper methods for the push-to-my-ouya download queue
4  */
5
6 /**
7  * Map local IPs to a single IP so that this the queue can be used
8  * in the home network.
9  *
10  * @see RFC 3330: Special-Use IPv4 Addresses
11  */
12 function mapIp($ip)
13 {
14     $private = substr($ip, 0, 3) == '10.'
15         || substr($ip, 0, 7) == '172.16.'
16         || substr($ip, 0, 7) == '172.17.'
17         || substr($ip, 0, 7) == '172.18.'
18         || substr($ip, 0, 7) == '172.19.'
19         || substr($ip, 0, 7) == '172.20.'
20         || substr($ip, 0, 7) == '172.21.'
21         || substr($ip, 0, 7) == '172.22.'
22         || substr($ip, 0, 7) == '172.23.'
23         || substr($ip, 0, 7) == '172.24.'
24         || substr($ip, 0, 7) == '172.25.'
25         || substr($ip, 0, 7) == '172.26.'
26         || substr($ip, 0, 7) == '172.27.'
27         || substr($ip, 0, 7) == '172.28.'
28         || substr($ip, 0, 7) == '172.29.'
29         || substr($ip, 0, 7) == '172.30.'
30         || substr($ip, 0, 7) == '172.31.'
31         || substr($ip, 0, 8) == '192.168.'
32         || substr($ip, 0, 8) == '169.254.';
33     $local = substr($ip, 0, 4) == '127.';
34
35     if ($private || $local) {
36         return 'local';
37     }
38     return $ip;
39 }