19#pragma comment(lib,"libIP.lib")
21bool validate_ping_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index)
23 if (command->length - index < 2)
25 send_message(info,
"USAGE: ping deviceName or ping IPAddress\n");
29 if (_stricmp(command->commands[index],
"ping"))
32 if (!isCommandAsDeviceName(command->commands[index + 1]))
34 if (!isValidIPAddress(command->commands[index + 1]))
36 send_message(info,
"%s is not a valid IP address or valid device name.\n",
37 command->commands[index + 1]);
44bool resp(ptrCLIENTINFO info,
char* msg,
bool isMore)
46 if(info->clientType != CLIENTTYPE_STRING)
47 send_message(info, msg);
48 if (info->clientType == CLIENTTYPE_SOCKET && !isMore)
50 info->CLIENT.sockClient.iswait =
false;
51 WakeByAddressSingle(&info->CLIENT.sockClient.iswait);
53 else if(info->multResp)
55 int len = (int)strlen(msg);
56 info->multResp(info->multRespArg,
64void execute_ping_command(ptrCLIENTINFO info, ptrCOMMANDARRAY command,
int index, NETSIM_ID d)
67 if (isCommandAsDeviceName(command->commands[index + 1]))
69 dest = fn_NetSim_Stack_GetDeviceId_asName(command->commands[index + 1]);
73 NETSIM_IPAddress ip = STR_TO_IP(command->commands[index + 1],
74 STR_GET_IP_TYPE(command->commands[index + 1]));
76 dest = fn_NetSim_Stack_GetDeviceId_asIP(ip, &in);
79 send_message(info,
"%s IP is not associated with any device.\n",
80 command->commands[index + 1]);
84 IP_DEVVAR* ipVar = GET_IP_DEVVAR(d);
85 if (ipVar && !ipVar->isICMP)
87 send_message(info,
"ICMP is not configured for device %d.\n", d);
91 ipVar = GET_IP_DEVVAR(dest);
92 if (ipVar && !ipVar->isICMP)
94 send_message(info,
"ICMP is not configured for device %d.\n", dest);
98 ICMP_StartPingRequest(d, dest, 4, resp, info);
99 if (info->clientType == CLIENTTYPE_SOCKET)
101 info->CLIENT.sockClient.iswait =
true;
102 WaitOnAddress(&info->CLIENT.sockClient.iswait,
103 &info->CLIENT.sockClient.dontUseMe,
104 sizeof info->CLIENT.sockClient.iswait,
109 info->isMultResp =
true;