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

Committer:
andrewboyson
Date:
2019-04-10
Revision:
140:9000ea70b220
Parent:
116:60521b29e4c9
Child:
172:9bc3c7b2cca1

File content as of revision 140:9000ea70b220:

#include <stdbool.h>
#include     "eth.h"
#include     "ar4.h"
#include     "ar6.h"
#include     "mac.h"
#include     "nr4.h"
#include     "nr6.h"
#include "ip6addr.h"

static bool resolve4(char* server, uint32_t* pip)
{
    //Check if have IP, if not, then request it and stop
    Nr4NameToIp(server, pip);
    if (!*pip)
    {
        Nr4MakeRequestForIpFromName(server); //The request is only repeated if made after a freeze time - call as often as you want.
        return false;
    }

    //Check if have MAC and, if not, request it and stop
    char mac[6];
    Ar4IpToMac(*pip, mac);
    if (MacIsEmpty(mac))
    {
        Ar4MakeRequestForMacFromIp(*pip); //The request is only repeated if made after a freeze time - call as often as you want.
        return false;
    }
    
    return true;
}
static bool resolve6(char* server, char* pip)
{
    //Check if have IP, if not, then request it and stop
    Nr6NameToIp(server, pip);
    if (Ip6AddressIsEmpty(pip))
    {
        Nr6MakeRequestForIpFromName(server); //The request is only repeated if made after a freeze time - call as often as you want.
        return false;
    }

    //Check if have MAC and, if not, request it and stop
    char mac[6];
    Ar6IpToMac(pip, mac);
    if (MacIsEmpty(mac))
    {
        Ar6MakeRequestForMacFromIp(pip); //The request is only repeated if made after a freeze time - call as often as you want.
        return false;
    }
    
    return true;
}
bool Resolve(char* remoteHost, int type, uint32_t* pIp4Address, char* pIp6Address)
{
    if (type == IPV4) return resolve4(remoteHost, pIp4Address);
    if (type == IPV6) return resolve6(remoteHost, pIp6Address);
    return false;
}