LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

IP address control

Hello,
I need to have a control that takes and validates IP address. Is there a predefined control type that I can use? (or I have to have a text control and do the validation by myself)
Thanks,

Edgar TH
0 Kudos
Message 1 of 5
(4,202 Views)

It might be easier to use 4 numeric fields.  That way, the data is forced to be numeric at least.

Then use a sprintf statement to put them into a string with the dots between the numbers.

sprintf(StringName, "%i.%i.%i.%i", IP_Addr1, IP_Addr2, IP_Addr3, IP_Addr4);

0 Kudos
Message 2 of 5
(4,185 Views)
Hi Edgar.

I had the same problem a few years back.

I used a string control, with some simple logic in the callback:
// String control callback
// - validate & reformat an IP address string
int CVICALLBACK IPAddressCB (int panel, int control, int event,
void *callbackData, int eventData1, int eventData2)
{
unsigned n1, n2, n3, n4;
int i, items;
char ip[20], IPAddress[20] = "Invalid!";

switch (event)
{
case EVENT_COMMIT:
GetCtrlVal (panel, control, ip);
// _Rough_ check for valid IP address string
items = Scan (ip, "%i[u].%i[u].%i[u].%i[u]",
&n1, &n2, &n3, &n4);
if ((items == 4) &&
(n1 <= 0xE0) && // Class A, B or C
(n2 <= 255) &&
(n3 <= 255) &&
(n4 <= 255))
Fmt (IPAddress, "%i.%i.%i.%i", n1, n2, n3, n4);

SetCtrlVal (panel, control, IPAddress);

break;
}

return 0;
}

Regards,
Colin.

Message Edited by cdk52 on 08-24-2006 06:15 PM

0 Kudos
Message 3 of 5
(4,167 Views)
Thank you very much. It works great. (I expected Labwindows to provide a specific control type for IP addresses like .NET)
0 Kudos
Message 4 of 5
(4,099 Views)
Especially since we paid for an "Internet library"  and ".NET library" capability.
0 Kudos
Message 5 of 5
(4,093 Views)