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

Committer:
andrewboyson
Date:
Wed Apr 10 10:07:06 2019 +0000
Revision:
140:9000ea70b220
Parent:
116:60521b29e4c9
Child:
172:9bc3c7b2cca1
Added ajax functions to AR4, AR6, NR4, NR6 modules

Who changed what in which revision?

UserRevisionLine numberNew 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 116:60521b29e4c9 6 #include "nr4.h"
andrewboyson 116:60521b29e4c9 7 #include "nr6.h"
andrewboyson 116:60521b29e4c9 8 #include "ip6addr.h"
andrewboyson 116:60521b29e4c9 9
andrewboyson 116:60521b29e4c9 10 static bool resolve4(char* server, uint32_t* pip)
andrewboyson 116:60521b29e4c9 11 {
andrewboyson 116:60521b29e4c9 12 //Check if have IP, if not, then request it and stop
andrewboyson 116:60521b29e4c9 13 Nr4NameToIp(server, pip);
andrewboyson 116:60521b29e4c9 14 if (!*pip)
andrewboyson 116:60521b29e4c9 15 {
andrewboyson 116:60521b29e4c9 16 Nr4MakeRequestForIpFromName(server); //The request is only repeated if made after a freeze time - call as often as you want.
andrewboyson 116:60521b29e4c9 17 return false;
andrewboyson 116:60521b29e4c9 18 }
andrewboyson 116:60521b29e4c9 19
andrewboyson 116:60521b29e4c9 20 //Check if have MAC and, if not, request it and stop
andrewboyson 116:60521b29e4c9 21 char mac[6];
andrewboyson 116:60521b29e4c9 22 Ar4IpToMac(*pip, mac);
andrewboyson 116:60521b29e4c9 23 if (MacIsEmpty(mac))
andrewboyson 116:60521b29e4c9 24 {
andrewboyson 116:60521b29e4c9 25 Ar4MakeRequestForMacFromIp(*pip); //The request is only repeated if made after a freeze time - call as often as you want.
andrewboyson 116:60521b29e4c9 26 return false;
andrewboyson 116:60521b29e4c9 27 }
andrewboyson 116:60521b29e4c9 28
andrewboyson 116:60521b29e4c9 29 return true;
andrewboyson 116:60521b29e4c9 30 }
andrewboyson 116:60521b29e4c9 31 static bool resolve6(char* server, char* pip)
andrewboyson 116:60521b29e4c9 32 {
andrewboyson 116:60521b29e4c9 33 //Check if have IP, if not, then request it and stop
andrewboyson 116:60521b29e4c9 34 Nr6NameToIp(server, pip);
andrewboyson 116:60521b29e4c9 35 if (Ip6AddressIsEmpty(pip))
andrewboyson 116:60521b29e4c9 36 {
andrewboyson 116:60521b29e4c9 37 Nr6MakeRequestForIpFromName(server); //The request is only repeated if made after a freeze time - call as often as you want.
andrewboyson 116:60521b29e4c9 38 return false;
andrewboyson 116:60521b29e4c9 39 }
andrewboyson 116:60521b29e4c9 40
andrewboyson 116:60521b29e4c9 41 //Check if have MAC and, if not, request it and stop
andrewboyson 116:60521b29e4c9 42 char mac[6];
andrewboyson 116:60521b29e4c9 43 Ar6IpToMac(pip, mac);
andrewboyson 116:60521b29e4c9 44 if (MacIsEmpty(mac))
andrewboyson 116:60521b29e4c9 45 {
andrewboyson 116:60521b29e4c9 46 Ar6MakeRequestForMacFromIp(pip); //The request is only repeated if made after a freeze time - call as often as you want.
andrewboyson 116:60521b29e4c9 47 return false;
andrewboyson 116:60521b29e4c9 48 }
andrewboyson 116:60521b29e4c9 49
andrewboyson 116:60521b29e4c9 50 return true;
andrewboyson 116:60521b29e4c9 51 }
andrewboyson 116:60521b29e4c9 52 bool Resolve(char* remoteHost, int type, uint32_t* pIp4Address, char* pIp6Address)
andrewboyson 116:60521b29e4c9 53 {
andrewboyson 116:60521b29e4c9 54 if (type == IPV4) return resolve4(remoteHost, pIp4Address);
andrewboyson 116:60521b29e4c9 55 if (type == IPV6) return resolve6(remoteHost, pIp6Address);
andrewboyson 116:60521b29e4c9 56 return false;
andrewboyson 116:60521b29e4c9 57 }