不等于陈述

编程入门 行业动态 更新时间:2024-10-22 03:07:11
本文介绍了不等于陈述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我只想显示不等于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 !=.

更多推荐

不等于陈述

本文发布于:2023-11-15 21:35:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1598162.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不等于

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!