NetSim Source Code Help
Loading...
Searching...
No Matches
DNS.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "List.h"
16#include "IP.h"
17/** This function is to find the gateway */
19{
20 NETSIM_ID i,j;
21 for(i=0;i<NETWORK->ppstruDeviceList[nDeviceId-1]->nNumOfInterface;i++)
22 {
24 {
26 }
27 }
28 return nDeviceId;
29}
30/**
31The DOMAIN NAME SPACE and RESOURCE RECORDS, which are
32specifications for a tree structured name space and data
33associated with the names. Conceptually, each node and leaf
34of the domain name space tree names a set of information, and
35query operations are attempts to extract specific types of
36information from a particular set. A query names the domain
37name of interest and describes the type of resource
38information that is desired. For example, the Internet
39uses some of its domain names to identify hosts; queries for
40address resources return Internet host addresses.
41*/
43{
44 DNS* dns;
45 IP_DEVVAR* devVar;
46 NETSIM_ID ngatewayId=fnFindGateway(nDeviceId);
47 if(!ngatewayId)
48 {
49 fnNetSimError("Gateway is not configured for device %d",nDeviceId);
50 assert(false);
51 }
52 if(!DEVICE_NWLAYER(ngatewayId))
53 fnNetSimError("DNS-- Netwok layer is not configured for device %d",ngatewayId);
54 devVar=DEVICE_NWLAYER(ngatewayId)->ipVar;
55 dns=devVar->dnsList;
56 while(dns)
57 {
58 if(dns->deviceId==id)
59 return dns->ip;
60 dns=LIST_NEXT(dns);
61 }
62 dns=DNS_ALLOC();
63 dns->deviceId=id;
65 LIST_ADD_LAST(&(devVar->dnsList),dns);
66 return dns->ip;
67}
68/** This function is free the memory allocated for DNS */
69int freeDNS(DNS* dns)
70{
71 while(dns)
72 LIST_FREE(&dns,dns);
73 return 1;
74}
unsigned int NETSIM_ID
Definition: Animation.h:45
int freeDNS(DNS *dns)
Definition: DNS.c:69
NETSIM_ID fnFindGateway(NETSIM_ID nDeviceId)
Definition: DNS.c:18
NETSIM_IPAddress dns_query(NETSIM_ID nDeviceId, NETSIM_ID id)
Definition: DNS.c:42
#define DNS_ALLOC()
Definition: IP.h:299
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define LIST_ADD_LAST(ls, mem)
Definition: List.h:30
#define LIST_NEXT(ls)
Definition: List.h:29
#define LIST_FREE(ls, mem)
Definition: List.h:32
NETSIM_IPAddress fn_NetSim_Stack_GetFirstIPAddressAsId(NETSIM_ID nDeviceId, unsigned int type)
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
#define DEVICE_NWLAYER(DeviceId)
Definition: Stack.h:785
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asIP(NETSIM_IPAddress ip, NETSIM_ID *nInterfaceId)
Structure to store the device ip details.
Definition: IP.h:226
void * dnsList
Definition: IP.h:261
struct stru_NetSim_Interface ** ppstruInterfaceList
Definition: Stack.h:717
NETSIM_ID nNumOfInterface
Definition: Stack.h:714
NETSIM_IPAddress szDefaultGateWay
Definition: Stack.h:692
struct stru_NetSim_Device ** ppstruDeviceList
Definition: Stack.h:737
Data structure for dns.
Definition: IP.h:294
NETSIM_ID deviceId
Definition: IP.h:295
NETSIM_IPAddress ip
Definition: IP.h:296