NetSim Source Code Help
Loading...
Searching...
No Matches
ICMP.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
15/***********************************************************************
16
17Network Working Group J. Postel
18Request for Comments: 792 ISI
19 September 1981
20Updates: RFCs 777, 760
21Updates: IENs 109, 128
22
23 INTERNET CONTROL MESSAGE PROTOCOL
24
25 DARPA INTERNET PROGRAM
26 PROTOCOL SPECIFICATION
27
28*************************************************************************/
29#include "main.h"
30#include "List.h"
31#include "IP.h"
32#include "ICMP.h"
33
34typedef struct stru_ICMP_Data
35{
37 void* payload;
39_declspec(dllexport) NetSim_PACKET* fn_NetSim_IP_ICMP_GenerateEchoRequest(NETSIM_ID source,
40 NETSIM_ID dest,
41 NETSIM_IPAddress srcIP,
42 NETSIM_IPAddress destIP,
43 double time,
44 void* data,
45 unsigned int size,
46 unsigned int ttl,
47 void(*callback)(NetSim_PACKET*));
48/** This function is to initialize the ICMP parameters */
49_declspec(dllexport) int fn_NetSim_IP_ICMP_Init()
50{
51 NETSIM_ID i;
52 for(i=0;i<NETWORK->nDeviceCount;i++)
53 {
55 {
57
58 if (!devVar->isICMP)
59 continue; //ICMP is not configured
60
61 if(devVar && devVar->nICMPPollingTime)
62 {
63 //Create timer event for poll
64 memset(pstruEventDetails,0,sizeof* pstruEventDetails);
72 }
73 if(devVar && devVar->nRouterAdvertisementFlag)
74 {
75 //Create timer event for router advertisement
76 memset(pstruEventDetails,0,sizeof* pstruEventDetails);
84 }
85 }
86 }
87 return 1;
88}
89/**
90 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91 Operations Manager uses a high-performance, asynchronous ICMP poller.
92 The ICMP poller performs at a consistent rate that is independent of poll response times.
93 Operations Manager achieves this using two asynchronous threads:
94 one that sends polls and one that receives polls. Because the send and receive threads
95 operate asynchronously, slow response times or excessive timeouts do not affect the polling rate.
96 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
97*/
98_declspec(dllexport) int fn_NetSim_IP_ICMP_POLL()
99{
100 unsigned int i;
101 double time=pstruEventDetails->dEventTime;
103 //Add the next ICMP poll event
106 for(i=0;i<devVar->nGatewayCount;i++)
107 {
108 NetSim_PACKET* packet;
110 devVar->nGatewayState[i] = GATEWAYSTATE_DOWN;
111 else if(devVar->nGatewayState[i] == GATEWAYSTATE_UP)
113 //Send ICMP echo request to gateway
114 packet = fn_NetSim_IP_ICMP_GenerateEchoRequest(pstruEventDetails->nDeviceId,
115 devVar->nGatewayId[i],
117 devVar->GatewayIPAddress[i],
119 NULL,
120 0,
121 1,
122 NULL);
123 //Generate Network out event to transmit
128 pstruEventDetails->pPacket = packet;
130 }
131
132 return 1;
133}
134/** This function is used to generate echo request */
135_declspec(dllexport) NetSim_PACKET* fn_NetSim_IP_ICMP_GenerateEchoRequest(NETSIM_ID source,
136 NETSIM_ID dest,
137 NETSIM_IPAddress srcIP,
138 NETSIM_IPAddress destIP,
139 double time,
140 void* data,
141 unsigned int size,
142 unsigned int ttl,
143 void(*callback)(NetSim_PACKET*))
144{
145 static UINT64 seqNumber = 1;
146 ICMP_ECHO* echo = calloc(1, sizeof* echo);
148 add_dest_to_packet(packet, dest);
150 strcpy(packet->szPacketType, "ICMP_EchoRequest");
151 packet->nPacketId = 0;
154 packet->nSourceId = source;
155 packet->pstruNetworkData->dArrivalTime = time;
156 packet->pstruNetworkData->dStartTime = time;
157 packet->pstruNetworkData->dEndTime = time;
158 packet->pstruNetworkData->dOverhead = 8;
159 packet->pstruNetworkData->dPayload = size;
160 packet->pstruNetworkData->dPacketSize = 8 + (double)size;
162 packet->pstruNetworkData->nTTL = ttl + 1;
163 packet->pstruNetworkData->szDestIP = IP_COPY(destIP);
164 packet->pstruNetworkData->szSourceIP = IP_COPY(srcIP);
167 echo->Type = 8;
168 echo->SequenceNumber = (UINT16)(seqNumber);
169 seqNumber++;
170 if (data)
171 {
172 ptrICMPDATA ic = calloc(1, sizeof* ic);
173 ic->callBack = callback;
174 ic->payload = data;
175 echo->Data = ic;
176 }
177 return packet;
178}
179
180/// This function is to process the echo request.
182{
183 //generate echo reply packet
186 ICMP_ECHO* echo = calloc(1,sizeof* echo);
188 strcpy(reply->szPacketType, "ICMP_EchoReply");
189 add_dest_to_packet(reply, request->nSourceId);
194 reply->pstruNetworkData->dOverhead = 8;
199 reply->pstruNetworkData->nTTL = 255;
204 echo->Type=0;
205 echo->Data = ((ICMP_ECHO*)request->pstruNetworkData->Packet_NetworkProtocol)->Data;
206 echo->SequenceNumber = ((ICMP_ECHO*)request->pstruNetworkData->Packet_NetworkProtocol)->SequenceNumber;
210 //Free the request packet
212 return 1;
213}
214
215/// The data received in the echo message must be returned in the echo reply message.
217{
219 unsigned int i;
220 for(i=0;i<devVar->nGatewayCount;i++)
221 {
223 {
224 devVar->nGatewayState[i] = GATEWAYSTATE_UP;
225 break;
226 }
227 }
229 if (echo->Data)
230 {
231 ptrICMPDATA ic = echo->Data;
232 if (ic->callBack)
234 }
235 //free the reply packet
238 return 1;
239}
240/** This function is to check the gateway state */
242{
244 unsigned int i;
245 for(i=0;ip && i<devVar->nGatewayCount;i++)
246 if(!IP_COMPARE(devVar->GatewayIPAddress[i],ip))
247 {
248 if(devVar->nGatewayState[i] == GATEWAYSTATE_DOWN)
249 return 0;
250 break;
251 }
252 return 1;
253}
254unsigned long advertiseseed1=12345678;
255unsigned long advertiseseed2=23456789;
256/**
257 The ICMP router discovery messages are called "Router Advertisements"
258 and "Router Solicitations". Each router periodically multicasts a
259 Router Advertisement from each of its multicast interfaces,
260 announcing the IP address(es) of that interface. Hosts discover the
261 addresses of their neighboring routers simply by listening for
262 advertisements. When a host attached to a multicast link starts up,
263 it may multicast a Router Solicitation to ask for immediate
264 advertisements, rather than waiting for the next periodic ones to
265 arrive; if (and only if) no advertisements are forthcoming, the host
266 may retransmit the solicitation a small number of times, but then
267 must desist from sending any more solicitations. Any routers that
268 subsequently start up, or that were not discovered because of packet
269 loss or temporary link partitioning, are eventually discovered by
270 reception of their periodic (unsolicited) advertisements. (Links
271 that suffer high packet loss rates or frequent partitioning are
272 accommodated by increasing the rate of advertisements, rather than
273 increasing the number of solicitations that hosts are permitted to
274 send.)
275 */
277{
278 ICMP_RouterAdvertisement* adver=calloc(1,sizeof* adver);
279 double time=pstruEventDetails->dEventTime;
280 NetSim_PACKET* packet;
282 NETSIM_ID i;
283 IP_DEVVAR* devVar = DEVICE_NWLAYER(nDeviceId)->ipVar;
284 //Add next event for router advertisement
287 //Generate router advertisement
289 packet->dEventTime = time;
291 strcpy(packet->szPacketType, "ICMP_RouterAdvertisement");
292 add_dest_to_packet(packet, 0);
294 packet->nReceiverId=0;
297 packet->pstruNetworkData->dArrivalTime =time;
298 packet->pstruNetworkData->dEndTime=time;
299 packet->pstruNetworkData->dStartTime=time;
300 packet->pstruNetworkData->dOverhead=16;
301 packet->pstruNetworkData->dPacketSize=16;
302 packet->pstruNetworkData->dPayload=0;
304 packet->pstruNetworkData->nTTL=2;
305 packet->pstruNetworkData->szDestIP=STR_TO_IP4("255.255.255.255");
308 adver->Type=9;
309 adver->AddrEntrySize=2;
310 adver->Lifetime = devVar->nRouterAdverLifeTime;
311 //count the num of address
312 for(i=0;i<NETWORK->ppstruDeviceList[nDeviceId-1]->nNumOfInterface;i++)
313 {
314 if(NETWORK->ppstruDeviceList[nDeviceId-1]->ppstruInterfaceList[i])
315 {
317 {
318 adver->NumAddrs++;
319 adver->RouterAddress = realloc(adver->RouterAddress,(sizeof* adver->RouterAddress)*adver->NumAddrs);
320 adver->RouterAddress[adver->NumAddrs-1] = IP_COPY(DEVICE_NWADDRESS(nDeviceId,i+1));
321 }
322 }
323 }
324 for(i=0;i<NETWORK->ppstruDeviceList[nDeviceId-1]->nNumOfInterface;i++)
325 {
326 if(NETWORK->ppstruDeviceList[nDeviceId-1]->ppstruInterfaceList[i])
327 {
329 {
331 //Create network out event to transmit
332 temp->pstruNetworkData->szGatewayIP = IP_COPY(DEVICE_NWADDRESS(nDeviceId,i+1));
333 temp->pstruNetworkData->szSourceIP = IP_COPY(DEVICE_NWADDRESS(nDeviceId,i+1));
342 }
343 }
344 }
345 return 1;
346}
347/**
348 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
349 The router discovery messages do not constitute a routing protocol:
350 they enable hosts to discover the existence of neighboring routers,
351 but not which router is best to reach a particular destination. If a
352 host chooses a poor first-hop router for a particular destination, it
353 should receive an ICMP Redirect from that router, identifying a
354 better one.
355 A Router Advertisement includes a "preference level" for each
356 advertised router address. When a host must choose a default router
357 address (i.e., when, for a particular destination, the host has not
358 been redirected or configured to use a specific router address), it
359 is expected to choose from those router addresses that have the
360 highest preference level.
361 A Router Advertisement also includes a "lifetime" field, specifying
362 the maximum length of time that the advertised addresses are to be
363 considered as valid router addresses by hosts, in the absence of
364 further advertisements. This is used to ensure that hosts eventually
365 forget about routers that fail, become unreachable, or stop acting as
366 routers.
367 The default advertising rate is once every 7 to 10 minutes, and the
368 default lifetime is 30 minutes.
369 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
370*/
372{
373 int flag=0;
375 ptrIP_ROUTINGTABLE table = IP_TABLE_GET(nDeviceId);
378 //Get the source IP
379 NETSIM_IPAddress src=PACKET_NWDATA(packet)->szSourceIP;
380 NETSIM_IPAddress ip=STR_TO_IP4("0.0.0.0");
381 while(table)
382 {
383 if(table->gateway)
384 if(!IP_COMPARE(src,table->gateway) && !IP_COMPARE(table->networkDestination,ip) && !IP_COMPARE(table->netMask,ip))
385 {
386 //entry found
387 flag=1;
388 break;
389 }
390 table=LIST_NEXT(table);
391 }
392 if(!table)
393 {
394 //Create new entry
395 iptable_add(IP_WRAPPER_GET(nDeviceId),
396 ip, ip, 0, src, 1, &DEVICE_NWADDRESS(nDeviceId, pstruEventDetails->nInterfaceId),
398
399 }
402 return 1;
403}
404/**
405 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406 If, according to the information in the gateway's routing tables,
407 the network specified in the internet destination field of a
408 datagram is unreachable, e.g., the distance to the network is
409 infinity, the gateway sends a destination unreachable message to
410 the internet source host of the datagram. In addition, in some
411 networks, the gateway may be able to determine if the internet
412 destination host is unreachable. Gateways in these networks may
413 send destination unreachable messages to the source host when the
414 destination host is unreachable.
415
416 If, in the destination host, the IP module cannot deliver the
417 datagram because the indicated protocol module or process port is
418 not active, the destination host may send a destination
419 unreachable message to the source host.
420
421 Another case is when a datagram must be fragmented to be forwarded
422 by a gateway yet the Don't Fragment flag is on. In this case the
423 gateway must discard the datagram and return a destination
424 unreachable message.
425 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
426*/
428{
430 if (isMulticastPacket(orgPacket))
431 return -1;
432
434 ICMP_DestinationUnreachableMessage* message=calloc(1,sizeof* message);
435 message->Type=3;
436 message->code=1;//host unreachable
437 message->InternetHeader=orgPacket;
440 strcpy(packet->szPacketType, "ICMP_DstUnreachableMsg");
441 add_dest_to_packet(packet, orgPacket->nSourceId);
450 packet->pstruNetworkData->dPayload=0;
452 packet->pstruNetworkData->nTTL=255;
455 // Added by PV on 11-11-20 to resolve ICMP related issue 3495
458 // End
460
461 //Add the network in event
472 return 1;
473}
474/**
475 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
476 If, according to the information in the gateway's routing tables,
477 the network specified in the internet destination field of a
478 datagram is unreachable, e.g., the distance to the network is
479 infinity, the gateway sends a destination unreachable message to
480 the internet source host of the datagram. In addition, in some
481 networks, the gateway may be able to determine if the internet
482 destination host is unreachable. Gateways in these networks may
483 send destination unreachable messages to the source host when the
484 destination host is unreachable.
485
486 If, in the destination host, the IP module cannot deliver the
487 datagram because the indicated protocol module or process port is
488 not active, the destination host may send a destination
489 unreachable message to the source host.
490
491 Another case is when a datagram must be fragmented to be forwarded
492 by a gateway yet the Don't Fragment flag is on. In this case the
493 gateway must discard the datagram and return a destination
494 unreachable message.
495 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
496*/
498{
501
502 NetSim_PACKET* p = message->InternetHeader;
505
508 {
509 NetSim_PACKET* p=message->InternetHeader;
512 free(message);
514 }
515 return 0;
516}
517
519{
520 switch(s->nControlDataType)
521 {
523 {
526 memcpy(dm,sm,sizeof* dm);
528 }
529 break;
530 }
531}
532
534{
537 IP_DEVVAR* ipVar = GET_IP_DEVVAR(d);
538 if (ipVar && !ipVar->isICMP)
539 {
540 fnNetSimError("ICMP packet %d is arrives to device %d from device %d.\n ICMP is not configured in this device.\n",
541 packet->nControlDataType,
542 d,
543 packet->nSourceId);
544 return;
545 }
546
547 switch (packet->nControlDataType)
548 {
551 break;
554 break;
557 break;
560 break;
561 default:
562 fnNetSimError("Unknown ICMP packet %d in %s\n",
563 packet->nControlDataType,
564 __FUNCTION__);
565 break;
566 }
567}
568
569typedef struct stru_pingHandle
570{
576 bool(*ResponseHandler)(void* arg, char* msg, bool isMore);
582 void* arg;
584
586 NETSIM_IPAddress* sIP,
587 NETSIM_IPAddress* dIP)
588{
589 int prev = 0;
590 NETSIM_ID si;
591 NETSIM_ID di;
592
593 *sIP = DEVICE_NWADDRESS(s, 1);
594 *dIP = DEVICE_NWADDRESS(d, 1);
595
596 for (si = 1; si <= DEVICE(s)->nNumOfInterface; si++)
597 {
599 if (DEVICE_INTERFACE(s, si)->nInterfaceType == INTERFACE_WAN_ROUTER)
600 *sIP = sip;
601 for (di = 1; di <= DEVICE(d)->nNumOfInterface; di++)
602 {
604 if (DEVICE_INTERFACE(d, di)->nInterfaceType == INTERFACE_WAN_ROUTER)
605 *dIP = dip;
608 if (!IP_COMPARE4(dnw, snw))
609 {
610 *sIP = sip;
611 *dIP = dip;
612 return;
613 }
614 }
615 }
616}
617
619{
621 ptrICMPDATA data = echo->Data;
622 ptrPINGHANDLER ping = data->payload;
623 if (echo->SequenceNumber == ping->seqNumber)
624 {
625 ping->replyRecvCount++;
626 ping->retryCount = 0;
627 char msg[BUFSIZ];
628 sprintf(msg, "Reply from %s: bytes %d time=%dus TTL=%d\n",
630 (int)packet->pstruNetworkData->dPayload,
632 MAX_TTL);
633 ping->ResponseHandler(ping->arg, msg, ping->count != ping->currentCount);
634 }
635}
636
637_declspec(dllexport) void* ICMP_StartPingRequest(NETSIM_ID src,
638 NETSIM_ID dest,
639 UINT count,
640 bool(*resp)(void*, char*, bool),
641 void* arg)
642{
643 ptrPINGHANDLER handle = calloc(1, sizeof* handle);
644 handle->count = count;
645 handle->dest = dest;
646 handle->ResponseHandler = resp;
647 handle->src = src;
648 handle->arg = arg;
649 IP_find_best_IP(src,
650 dest,
651 &handle->srcIP,
652 &handle->destIP);
653
654 //Start timer event to send ping
655 NetSim_EVENTDETAILS pevent;
656 memset(&pevent, 0, sizeof pevent);
657 pevent.dEventTime = ldEventTime + 1000;
658 pevent.nDeviceId = src;
659 pevent.nDeviceType = DEVICE_TYPE(src);
660 pevent.nEventType = TIMER_EVENT;
663 pevent.szOtherDetails = handle;
664 fnpAddEvent(&pevent);
665 return handle;
666}
667
669{
671 if (handle->currentCount == handle->replyRecvCount)
672 goto SEND_ECHO_REQUEST;
673 else
674 {
675 if (handle->retryCount == ICMP_MAX_RETRY)
676 {
677 handle->seqNumber = 0;
678 handle->replyRecvCount++;
679 handle->ResponseHandler(handle->arg, "Request timed out!\n", handle->count != handle->currentCount);
680 if (handle->currentCount != handle->count)
681 goto SEND_ECHO_REQUEST;
682 else
683 return;
684 }
685 else
686 {
687 handle->retryCount++;
688 goto ADD_NEXT_SEND_REQUEST;
689 }
690 }
691
692SEND_ECHO_REQUEST:
693 if (handle->currentCount != handle->count)
694 {
695 handle->retryCount = 0;
696 handle->currentCount++;
697 handle->echoSendTime = pstruEventDetails->dEventTime;
698 NetSim_PACKET* packet = fn_NetSim_IP_ICMP_GenerateEchoRequest(handle->src,
699 handle->dest,
700 handle->srcIP,
701 handle->destIP,
703 handle,
704 32,
705 MAX_TTL - 1,
707 handle->seqNumber = ((ICMP_ECHO*)(packet->pstruNetworkData->Packet_NetworkProtocol))->SequenceNumber;
708
709 NetSim_EVENTDETAILS pevent;
710 memset(&pevent, 0, sizeof pevent);
712 pevent.dPacketSize = fnGetPacketSize(packet);
717 pevent.pPacket = packet;
718 fnpAddEvent(&pevent);
719 }
720
721ADD_NEXT_SEND_REQUEST:
722 //Add next send event
723 if (handle->currentCount != handle->count + 2)
724 {
727 }
728}
unsigned int NETSIM_ID
Definition: Animation.h:45
#define MAX_TTL
Definition: Application.h:34
static ANIM_HANDLE handle
Definition: BatteryModel.c:197
void process_icmp_packet()
Definition: ICMP.c:533
struct stru_ICMP_Data * ptrICMPDATA
void ICMP_copyPacket(NetSim_PACKET *d, NetSim_PACKET *s)
Definition: ICMP.c:518
unsigned long advertiseseed2
Definition: ICMP.c:255
void replyRecevied(NetSim_PACKET *packet)
Definition: ICMP.c:618
void icmp_send_echo_request()
Definition: ICMP.c:668
struct stru_pingHandle PINGHANDLER
void IP_find_best_IP(NETSIM_ID s, NETSIM_ID d, NETSIM_IPAddress *sIP, NETSIM_IPAddress *dIP)
Definition: ICMP.c:585
struct stru_ICMP_Data ICMPDATA
unsigned long advertiseseed1
Definition: ICMP.c:254
struct stru_pingHandle * ptrPINGHANDLER
#define ICMP_SEND_TIME
Definition: ICMP.h:37
#define ICMP_MAX_RETRY
Definition: ICMP.h:36
int fn_NetSim_IP_ICMP_GenerateDstUnreachableMsg()
int fn_NetSim_IP_ICMP_EchoReply()
int fn_NetSim_IP_ICMP_POLL()
int fn_NetSim_IP_ICMP_ProcessRouterAdvertisement()
int fn_NetSim_IP_ICMP_Init()
int fn_NetSim_IP_ICMP_AdvertiseRouter()
int fn_NetSim_IP_ICMP_ProcessDestUnreachableMsg()
int fn_NetSim_IP_ICMP_EchoRequest()
@ GATEWAYSTATE_NOTIFICATION_PENDING
Definition: IP.h:126
@ GATEWAYSTATE_UP
Definition: IP.h:124
@ GATEWAYSTATE_DOWN
Definition: IP.h:125
int ICMP_CHECKSTATE(NETSIM_IPAddress ip)
#define IPV4_HEADER_SIZE
Definition: IP.h:45
#define GET_IP_DEVVAR(d)
Definition: IP.h:49
int iptable_delete(ptrIP_WRAPPER wrapper, NETSIM_IPAddress dest, NETSIM_IPAddress in, char *type)
ptrIP_ROUTINGTABLE iptable_add(ptrIP_WRAPPER wrapper, NETSIM_IPAddress dest, NETSIM_IPAddress subnet, unsigned int prefix_len, NETSIM_IPAddress gateway, UINT interfaceCount, NETSIM_IPAddress *interfaceIp, NETSIM_ID *interfaceId, unsigned int metric, char *type)
@ EVENT_ADVERTISE_ROUTER
Definition: IP.h:95
@ EVENT_ICMP_POLL
Definition: IP.h:94
@ EVENT_ICMP_SEND_ECHO
Definition: IP.h:114
#define DEFAULT_METRIC
Definition: IP.h:42
@ PACKET_ICMP_DstUnreachableMsg
Definition: IP.h:64
@ PACKET_ICMP_ECHOReply
Definition: IP.h:66
@ PACKET_ROUTER_ADVERTISEMENT
Definition: IP.h:67
@ PACKET_ICMP_ECHORequest
Definition: IP.h:65
void * ICMP_StartPingRequest(NETSIM_ID src, NETSIM_ID dest, UINT count, bool(*resp)(void *, char *, bool), void *arg)
NETSIM_IPAddress IP_COPY(NETSIM_IPAddress ip)
#define IP_NETWORK_ADDRESS_IPV4(ip, subnet)
#define IP_COMPARE4(ip1, ip2)
Definition: IP_Addressing.h:65
#define IP_COMPARE(ip1, ip2)
Definition: IP_Addressing.h:67
#define STR_TO_IP4(ipstr)
Definition: IP_Addressing.h:94
#define UINT64
Definition: Linux.h:37
#define UINT
Definition: Linux.h:38
#define _declspec(dllexport)
This function is used to trigger the update.
Definition: Linux.h:41
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define UINT16
Definition: Linux.h:33
#define LIST_NEXT(ls)
Definition: List.h:29
#define realloc(p, s)
Definition: Memory.h:32
#define free(p)
Definition: Memory.h:31
#define calloc(c, s)
Definition: Memory.h:29
double fnGetPacketSize(NetSim_PACKET *pstruData)
#define PACKET_NWPROTOCOLDATA(pPacket)
Definition: Packet.h:301
@ PacketType_Control
Definition: Packet.h:66
bool isMulticastPacket(NetSim_PACKET *packet)
#define PACKET_NWDATA(pPacket)
Definition: Packet.h:296
NETSIM_ID get_first_dest_from_packet(NetSim_PACKET *packet)
@ IPPROTOCOL_ICMP
Definition: Packet.h:127
void add_dest_to_packet(NetSim_PACKET *packet, NETSIM_ID dest)
@ Priority_Low
Definition: Packet.h:79
bool resp(ptrCLIENTINFO info, char *msg, bool isMore)
Definition: Ping.c:44
EXPORTED double ldEventTime
Definition: Stack.h:838
int fn_NetSim_Stack_CallICMPErrorFun(NetSim_PACKET *packet, NETSIM_ID nDeviceId, unsigned int nICMPErr)
#define DEVICE(DeviceId)
Definition: Stack.h:769
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
#define DEVICE_NWADDRESS(DeviceId, InterfaceId)
Definition: Stack.h:805
@ NW_PROTOCOL_IPV4
Definition: Stack.h:189
NETSIM_IPAddress fn_NetSim_Stack_GetFirstIPAddressAsId(NETSIM_ID nDeviceId, unsigned int type)
#define DEVICE_SUBNETMASK(DeviceId, InterfaceId)
Definition: Stack.h:807
double fn_NetSim_Utilities_GenerateRandomNo(unsigned long *uSeed, unsigned long *uSeed1)
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
#define SECOND
Definition: Stack.h:60
@ NETWORK_OUT_EVENT
Definition: Stack.h:108
@ TIMER_EVENT
Definition: Stack.h:114
@ NETWORK_IN_EVENT
Definition: Stack.h:109
@ NETWORK_LAYER
Definition: Stack.h:96
#define NETSIM_RAND_MAX
Definition: Stack.h:849
#define DEVICE_NWLAYER(DeviceId)
Definition: Stack.h:785
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define DEVICE_INTERFACE(DeviceId, InterfaceId)
Definition: Stack.h:780
@ INTERFACE_VIRTUAL
Definition: Stack.h:255
@ INTERFACE_WAN_ROUTER
Definition: Stack.h:254
#define IP_WRAPPER_GET(DeviceId)
Definition: Stack.h:801
#define IP_TABLE_GET(DeviceId)
Definition: Stack.h:802
#define fn_NetSim_Packet_CopyPacket(pstruPacket)
Definition: main.h:182
#define fn_NetSim_Packet_CreatePacket(layer)
Definition: main.h:186
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
void * payload
Definition: ICMP.c:37
void(* callBack)(NetSim_PACKET *)
Definition: ICMP.c:36
Structure to store the device ip details.
Definition: IP.h:226
NETSIM_IPAddress * GatewayIPAddress
Definition: IP.h:245
unsigned int nRouterAdverLifeTime
Definition: IP.h:241
unsigned int nRouterAdverMaxInterval
Definition: IP.h:240
bool isICMP
Definition: IP.h:236
IP_GATEWAYSTATE * nGatewayState
Definition: IP.h:248
NETSIM_ID * nGatewayId
Definition: IP.h:246
unsigned int nRouterAdvertisementFlag
Definition: IP.h:238
unsigned int nICMPPollingTime
Definition: IP.h:243
unsigned int nRouterAdverMinInterval
Definition: IP.h:239
NETSIM_ID * nInterfaceId
Definition: IP.h:247
unsigned int nGatewayCount
Definition: IP.h:244
struct stru_NetSim_NetworkLayer * pstruNetworkLayer
Definition: Stack.h:721
NETSIM_ID nDeviceId
Definition: Stack.h:710
struct stru_NetSim_Interface ** ppstruInterfaceList
Definition: Stack.h:717
NETSIM_ID nNumOfInterface
Definition: Stack.h:714
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:711
NETSIM_ID nApplicationId
Definition: Stack.h:752
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
long long int nPacketId
Definition: Stack.h:755
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
NETSIM_ID nInterfaceId
Definition: Stack.h:751
unsigned short int SequenceNumber
If code = 0, a sequence number to aid in matching echos and replies, may be zero.
Definition: ICMP.h:123
unsigned short int Lifetime
Definition: ICMP.h:207
NETSIM_IPAddress * RouterAddress
Definition: ICMP.h:208
Structure to store ip routing table.
Definition: IP.h:157
NETSIM_IPAddress networkDestination
Definition: IP.h:158
NETSIM_IPAddress gateway
Definition: IP.h:160
NETSIM_IPAddress netMask
Definition: IP.h:159
INTERFACE_TYPE nInterfaceType
Definition: Stack.h:677
NETSIM_IPAddress szAddress
Definition: Stack.h:688
struct stru_NetSim_Device ** ppstruDeviceList
Definition: Stack.h:737
NETSIM_IPAddress szGatewayIP
Definition: Packet.h:200
IP_PROTOCOL_NUMBER IPProtocol
Definition: Packet.h:203
NETWORK_LAYER_PROTOCOL nNetworkProtocol
Definition: Packet.h:204
NETSIM_IPAddress szDestIP
Definition: Packet.h:199
NETSIM_IPAddress szNextHopIp
Definition: Packet.h:201
NETSIM_IPAddress szSourceIP
Definition: Packet.h:198
long long int nPacketId
Definition: Packet.h:256
char szPacketType[MAX_PACKET_TYPE_LEN]
Definition: Packet.h:271
struct stru_NetSim_Packet_NetworkLayer * pstruNetworkData
Definition: Packet.h:275
double dEventTime
Definition: Packet.h:262
NETSIM_ID nReceiverId
Definition: Packet.h:266
unsigned int nControlDataType
Definition: Packet.h:258
NETSIM_ID nTransmitterId
Definition: Packet.h:265
PACKET_TYPE nPacketType
Definition: Packet.h:257
PACKET_PRIORITY nPacketPriority
Definition: Packet.h:260
NETSIM_ID nSourceId
Definition: Packet.h:263
char str_ip[_NETSIM_IP_LEN]
Definition: IP_Addressing.h:54
UINT16 seqNumber
Definition: ICMP.c:581
UINT currentCount
Definition: ICMP.c:578
UINT retryCount
Definition: ICMP.c:580
UINT count
Definition: ICMP.c:575
double echoSendTime
Definition: ICMP.c:577
NETSIM_ID src
Definition: ICMP.c:571
void * arg
Definition: ICMP.c:582
NETSIM_ID dest
Definition: ICMP.c:572
NETSIM_IPAddress srcIP
Definition: ICMP.c:573
UINT replyRecvCount
Definition: ICMP.c:579
bool(* ResponseHandler)(void *arg, char *msg, bool isMore)
Definition: ICMP.c:576
NETSIM_IPAddress destIP
Definition: ICMP.c:574