Click here to Skip to main content
15,914,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is there a way to refernce a nuber of IP address with a wildcar character? I want to run code on all IP addresses starting with 192.168. Would it be done like this?
192.168.*.*
Here is the code I'm trying to run. It's the first part that is giving trouble.

C++
if ((ipSrc == 192.168.*.*) || (ip_header->source_ip == sockAddr.sin_addr.s_addr))
			{
			printf("\n   Source      IP: %s", "0.0.0.0");
			printf("\n   Destination IP: %s", ipDest);


Tried this as well...No work.
C++
if ((ipSrc == "192.168.0.0" - "192.168.255.255") || (ip_header->source_ip == sockAddr.sin_addr.s_addr))
			{


ipSrc is a char
Posted
Updated 16-Sep-11 9:55am
v4

C++
if ((strncmp("192.168", ipSrc, 7) == 0) || (ip_header->source_ip == sockAddr.sin_addr.s_addr))
			{
			printf("\n   Source      IP: %s", "0.0.0.0");
			printf("\n   Destination IP: %s", ipDest);


This may work, it just compares the first part of the IP address, (the 7 is the number of characters to compare, 192.168 is 7 characters long)
 
Share this answer
 
Comments
Member 7766180 16-Sep-11 16:12pm    
Thank You, Works like a charm!!!!!!
The expressions in the above samples are not valid and will never work. You should compare individual values from IPAddresses to see if they are on the same subnet. Use the FIRST_IPADDRESS[^] and related macros to extract each field.
 
Share this answer
 
Comments
Member 7766180 16-Sep-11 16:13pm    
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900