本文介绍了不等于陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想显示不等于192.168.1.103但未编译的内容.
printf("\n source port : %ld", htons(tcp_header->source_port)<>192.168.1.103);解决方案
printf("\n source port : %ld", htons(tcp_header->source_port)<>192.168.1.103);
该语句没有任何意义,也难怪它不会编译.通过代码的外观,还会使端口号与IP地址混淆. 您需要通过 inet_addr() 将两个IP地址都转换为整数值[ ^ ]和然后进行简单的数值比较.然后使用类似的内容:
long IPaddress1 = inet_adr("192.168.1.103"); long IPaddress2 = inet_adr(source_address); // string if (IPaddress1 != IPaddress2) printf("IP address: %s\n", source_address);
您想要的东西 int *addressValue = new int(); char *address = "192.168.1.103"; inet_pton(AF_INET, address, addressValue); if (htons(tcp_header->source_port) != *addressValue) printf("\n source port : %d", htons(tcp_header->source_port));
那应该将IP地址的字符串表示形式转换为数字,然后将其与您获取的其他地址进行比较.
我相信您必须使用!=.
I want to show only those that are not equal to 192.168.1.103 but it''s not compiling.
printf("\n source port : %ld", htons(tcp_header->source_port)<>192.168.1.103); 解决方案 printf("\n source port : %ld", htons(tcp_header->source_port)<>192.168.1.103);This statement makes no sense, no wonder it does not compile. You are also confusing a port number with an IP address by the look of your code. You need to convert both your IP addresses to integer values via inet_addr()[^] and then make a simple numeric comparison. Then use something like:
long IPaddress1 = inet_adr("192.168.1.103"); long IPaddress2 = inet_adr(source_address); // string if (IPaddress1 != IPaddress2) printf("IP address: %s\n", source_address);You''re going to want something like int *addressValue = new int(); char *address = "192.168.1.103"; inet_pton(AF_INET, address, addressValue); if (htons(tcp_header->source_port) != *addressValue) printf("\n source port : %d", htons(tcp_header->source_port));That should convert the string representation of the IP address to a number, then compare it to the other address you''re getting.
I believe you must use !=.更多推荐
不等于陈述
发布评论