NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
NA_locality.cc File Reference
#include "../NA_aodv_uu_omnet.h"
#include "IPv4InterfaceData.h"

Go to the source code of this file.

Defines

#define NS_PORT
#define OMNETPP

Functions

int NS_CLASS locality (struct in_addr dest, unsigned int ifindex)

Define Documentation

#define NS_PORT

Definition at line 22 of file NA_locality.cc.

#define OMNETPP

Definition at line 23 of file NA_locality.cc.


Function Documentation

int NS_CLASS locality ( struct in_addr  dest,
unsigned int  ifindex 
)

Definition at line 44 of file NA_locality.cc.

{

#ifndef NS_PORT
    if (gw_prefix)
    {
        if ((dest.s_addr & DEV_IFINDEX(ifindex).netmask.s_addr) ==
                (DEV_IFINDEX(ifindex).ipaddr.s_addr & DEV_IFINDEX(ifindex).netmask.
                 s_addr))
            return HOST_ADHOC;
        else
            return HOST_INET;

    }
    else
    {
        struct hostent *hent;

        hent = gethostbyaddr(&dest, sizeof(struct in_addr), AF_INET);

        if (!hent)
        {
            switch (h_errno)
            {
            case HOST_NOT_FOUND:
                DEBUG(LOG_DEBUG, 0, "RREQ for Non-Internet dest %s",
                      ip_to_str(dest));
                return HOST_UNKNOWN;
            default:
                DEBUG(LOG_DEBUG, 0, "Unknown DNS error");
                break;

            }
        }
        else
            return HOST_INET;
    }
#else
#ifndef OMNETPP
    char *dstnet = Address::getInstance().get_subnetaddr(dest.s_addr);
    char *subnet =
        Address::getInstance().get_subnetaddr(DEV_NR(NS_DEV_NR).ipaddr.s_addr);
    DEBUG(LOG_DEBUG, 0, "myaddr=%d, dest=%d dstnet=%s subnet=%s",
          DEV_NR(NS_DEV_NR).ipaddr.s_addr, dest.s_addr, dstnet, subnet);
    if (subnet != NULL)
    {
        if (dstnet != NULL)
        {
            if (strcmp(dstnet, subnet) != 0)
            {
                delete[]dstnet;
                return HOST_INET;
            }
            delete[]dstnet;
        }
        delete[]subnet;
    }
    assert(dstnet == NULL);
    return HOST_UNKNOWN;
#else
    InterfaceEntry *   ie;
    ie = getInterfaceEntry (ifindex);
    struct in_addr dstnet;
    struct in_addr subnet;
    struct in_addr interface;

    int masklen = ie->ipv4Data()->getNetmask().getNetmaskLength();
    dstnet.s_addr = ManetAddress(dest.s_addr); dstnet.s_addr.setPrefix(masklen);   // dstnet.s_addr = dest.s_addr & mask.s_addr;
    interface.s_addr = ManetAddress(ie->ipv4Data()->getIPAddress());
    subnet.s_addr = interface.s_addr; subnet.s_addr.setPrefix(masklen);    //interface.s_addr & mask.s_addr;
    if (!subnet.s_addr.isUnspecified())
    {
        if (!dstnet.s_addr.isUnspecified())
        {
            if (subnet.s_addr==dstnet.s_addr)
                return HOST_ADHOC;
            else
                return HOST_INET;
        }
    }
    return HOST_UNKNOWN;
#endif
#endif
    return HOST_UNKNOWN;
}
 All Classes Files Functions Variables Typedefs Enumerator Defines