通配符和IP地址 [英] Wild Card and IP Address

查看:1161
本文介绍了通配符和IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以用通配符引用IP地址的任意数字?我想在以192.168.开头的所有IP地址上运行代码会这样吗?
192.168.*.*
这是我要运行的代码.这是麻烦的第一部分.

 如果((ipSrc ==  192 ."  " );
printf(" ,ipDest); 



也尝试过这个...没有工作.

 如果((ipSrc == " -" )||(ip_header -> source_ip == sockAddr.sin_addr.s_addr))
{



ipSrc是char

解决方案

  if (( class ="code-string">" ,ipSrc, 7 )==  0 )||(ip_header-> source_ip == sockAddr.sin_addr.s_addr))
{
printf("  " );
printf(" ,ipDest); 



这可能行得通,它只是比较IP地址的第一部分(7是要比较的字符数,192.168是7个字符长)


以上示例中的表达式是无效,将永远无法使用.您应该比较IPAddresses中的各个值,以查看它们是否在同一子网中.使用 FIRST_IPADDRESS [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.

if ((ipSrc == "192.168.0.0" - "192.168.255.255") || (ip_header->source_ip == sockAddr.sin_addr.s_addr))
			{



ipSrc is a char

解决方案

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)


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.


这篇关于通配符和IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆