LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

wrong IP address but no zero after "string to IP "

Hi,

I have the problem, that the VI "string to IP " doesn´t give me zero, if I set a wrong IP address.
In windows I get the the right value "0", but in Linux the VI doesn't work.

I hope somebody can help me

Thomas



"If the node fails to convert the string, the result is a value of zero"
0 Kudos
Message 1 of 13
(4,608 Views)
What does it return if not zero?

Regards,

Wiebe.


0 Kudos
Message 2 of 13
(4,573 Views)
Hi Wiebe:
 
just answering for my colleague. I have added some pictures I made using LV8.01 for Windows and Suse Linux.
 
Thank you very much for your help.
 
emn
 
0 Kudos
Message 3 of 13
(4,550 Views)
I think there's not much you can do besides making your own StringToIp vi.

It can be simple though. Select the StringToIp node in your diagram. Make a
sub VI from it.

Then, use a Scan From String with "%d.%d.%d.%d" (without the quotes) to
check if the input string matches the required format. You can add a check
to see if the string is empty. You can use a case to pass the string to the
normal StringToIp node, or to output a zero.

So: You'll have one case that checks if the string is empty. In the true
case, put the StringToIp node with the empty string wired to it. In the
false case, put the Scan From String. In it's error case, wire a 0 to the
output. In the no error case, put the StringToIp done.

You could do this only on Linux, by using a Conditional Disable structure,
but it doesn't harm to do it on windows either (it will be a bit slower).

Regards,

Wiebe.


0 Kudos
Message 4 of 13
(4,536 Views)
Wiebe,
in the general case, StringToIP would also convert valid host names, that are not in the x.x.x.x format, so a custom vi would not be SO simple.
One suggestion would be to check for the existence of dots in the (non-empty) string, then if dots are found treat the string as suggested by you, if not use the standard function.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 5 of 13
(4,531 Views)
Hi Wiebe:
 
Thank you for your help. But I think Paolo is right. Parsing only for %d.%d.%d.%d will not do it. On the other hand names may contain dots too.
 
I will try to find a solution.
 
Thank you both very much for your help.
 
emn
0 Kudos
Message 6 of 13
(4,527 Views)
Okay,
 
this is the solution I found. The invisible frame of the case structure handles the empty string.
 
emn
0 Kudos
Message 7 of 13
(4,522 Views)
This vi (LV 7.1) I wrote some times ago to check if a string is a x.x.x.x IP address may help.
It's based on regular expressions.


Message Edited by pincpanter on 10-12-2007 01:58 PM

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Download All
0 Kudos
Message 8 of 13
(4,516 Views)

hi there

the point is NOT to convert a "1.2.3.4" string to a U32 integer, the thing is to resolve an arbitrary network name like "thisismylabcomp" to its IP-number "1.2.3.4". That involves DHCP etc. In BachelorPT first post

127.0.0.1 : 2130706433 = 127.0.0.1
127.0.0    : 2130706433 = 127.0.0.1
127.0.      : 2130706433 = 127.0.0.1
127          : 2130706433 = 127.0.0.1

                : 3232238286 = 192.168.10.206

Is 192.168.10.206 some special address in your network?

Test "ping" with the addresses and the network names, are there any errors?

If nothing helps you could create your own hosts file and then parse this file with LabVIEW.

 

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 9 of 13
(4,508 Views)
From what I understood, the point is how incomplete IP addresses (in dot notation) should be handled.
It seems that under Linux (unlike Windows):
- a string like "127.0" is arbitrarily "zero-padded" and converted to 127.0.0.0 (chrisger: not to 127.0.0.1), although this is not a valid address, in general
- a string like "127" is converted to address 127, clearly not a valid one
Furthermore, in both Linux and Windows, an empty string is converted to what seems to be the localhost address, but this is not evidently wrong. There are other LV function that behave this way.
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 10 of 13
(4,502 Views)