A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
resolve/resolve.c@200:5acbc41bf469, 2021-05-20 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu May 20 14:32:52 2021 +0000
- Revision:
- 200:5acbc41bf469
- Parent:
- 172:9bc3c7b2cca1
Increased number of arp entries from 20 to 30 to accommodate the number of WIZ devices plus a few incoming port 80 calls from the internet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewboyson | 116:60521b29e4c9 | 1 | #include <stdbool.h> |
andrewboyson | 116:60521b29e4c9 | 2 | #include "eth.h" |
andrewboyson | 116:60521b29e4c9 | 3 | #include "ar4.h" |
andrewboyson | 116:60521b29e4c9 | 4 | #include "ar6.h" |
andrewboyson | 116:60521b29e4c9 | 5 | #include "mac.h" |
andrewboyson | 172:9bc3c7b2cca1 | 6 | #include "nr.h" |
andrewboyson | 116:60521b29e4c9 | 7 | #include "ip6addr.h" |
andrewboyson | 116:60521b29e4c9 | 8 | |
andrewboyson | 116:60521b29e4c9 | 9 | static bool resolve4(char* server, uint32_t* pip) |
andrewboyson | 116:60521b29e4c9 | 10 | { |
andrewboyson | 116:60521b29e4c9 | 11 | //Check if have IP, if not, then request it and stop |
andrewboyson | 172:9bc3c7b2cca1 | 12 | NrNameToAddress4(server, pip); |
andrewboyson | 116:60521b29e4c9 | 13 | if (!*pip) |
andrewboyson | 116:60521b29e4c9 | 14 | { |
andrewboyson | 172:9bc3c7b2cca1 | 15 | NrMakeRequestForAddress4FromName(server); //The request is only repeated if made after a freeze time - call as often as you want. |
andrewboyson | 116:60521b29e4c9 | 16 | return false; |
andrewboyson | 116:60521b29e4c9 | 17 | } |
andrewboyson | 116:60521b29e4c9 | 18 | |
andrewboyson | 116:60521b29e4c9 | 19 | //Check if have MAC and, if not, request it and stop |
andrewboyson | 116:60521b29e4c9 | 20 | char mac[6]; |
andrewboyson | 116:60521b29e4c9 | 21 | Ar4IpToMac(*pip, mac); |
andrewboyson | 116:60521b29e4c9 | 22 | if (MacIsEmpty(mac)) |
andrewboyson | 116:60521b29e4c9 | 23 | { |
andrewboyson | 116:60521b29e4c9 | 24 | Ar4MakeRequestForMacFromIp(*pip); //The request is only repeated if made after a freeze time - call as often as you want. |
andrewboyson | 116:60521b29e4c9 | 25 | return false; |
andrewboyson | 116:60521b29e4c9 | 26 | } |
andrewboyson | 116:60521b29e4c9 | 27 | |
andrewboyson | 116:60521b29e4c9 | 28 | return true; |
andrewboyson | 116:60521b29e4c9 | 29 | } |
andrewboyson | 116:60521b29e4c9 | 30 | static bool resolve6(char* server, char* pip) |
andrewboyson | 116:60521b29e4c9 | 31 | { |
andrewboyson | 116:60521b29e4c9 | 32 | //Check if have IP, if not, then request it and stop |
andrewboyson | 172:9bc3c7b2cca1 | 33 | NrNameToAddress6(server, pip); |
andrewboyson | 172:9bc3c7b2cca1 | 34 | if (Ip6AddrIsEmpty(pip)) |
andrewboyson | 116:60521b29e4c9 | 35 | { |
andrewboyson | 172:9bc3c7b2cca1 | 36 | NrMakeRequestForAddress6FromName(server); //The request is only repeated if made after a freeze time - call as often as you want. |
andrewboyson | 116:60521b29e4c9 | 37 | return false; |
andrewboyson | 116:60521b29e4c9 | 38 | } |
andrewboyson | 116:60521b29e4c9 | 39 | |
andrewboyson | 116:60521b29e4c9 | 40 | //Check if have MAC and, if not, request it and stop |
andrewboyson | 116:60521b29e4c9 | 41 | char mac[6]; |
andrewboyson | 116:60521b29e4c9 | 42 | Ar6IpToMac(pip, mac); |
andrewboyson | 116:60521b29e4c9 | 43 | if (MacIsEmpty(mac)) |
andrewboyson | 116:60521b29e4c9 | 44 | { |
andrewboyson | 116:60521b29e4c9 | 45 | Ar6MakeRequestForMacFromIp(pip); //The request is only repeated if made after a freeze time - call as often as you want. |
andrewboyson | 116:60521b29e4c9 | 46 | return false; |
andrewboyson | 116:60521b29e4c9 | 47 | } |
andrewboyson | 116:60521b29e4c9 | 48 | |
andrewboyson | 116:60521b29e4c9 | 49 | return true; |
andrewboyson | 116:60521b29e4c9 | 50 | } |
andrewboyson | 116:60521b29e4c9 | 51 | bool Resolve(char* remoteHost, int type, uint32_t* pIp4Address, char* pIp6Address) |
andrewboyson | 116:60521b29e4c9 | 52 | { |
andrewboyson | 172:9bc3c7b2cca1 | 53 | if (type == ETH_IPV4) return resolve4(remoteHost, pIp4Address); |
andrewboyson | 172:9bc3c7b2cca1 | 54 | if (type == ETH_IPV6) return resolve6(remoteHost, pIp6Address); |
andrewboyson | 116:60521b29e4c9 | 55 | return false; |
andrewboyson | 116:60521b29e4c9 | 56 | } |