问题描述:
判断两个Ip是否为同一个网段: Ip1,Ip2分别与子网淹Ip3进行与操作,结果相同则判断为同一个网段,输出结构:1 与操作结果; 否则输出0;
#include
#include
#include
#define Length 4
using namespace std;
void printIntArray(int * array){
for ( int i = 0; i < Length; i++ )
cout << array[i] << " ";
cout << endl;
}
int charToInt(char ch, int sum){
int result = sum * 10 + ( ch - '0' );
return result;
}
void getIntOfIp(char * ip, int * intArray){
int count = 0;
int temp = 0;
while ( *ip != '\0' ){
if ( *ip == '.' ){
intArray[count] = temp;
count ++;
temp = 0;
}else if ( count == 0 ){
temp = charToInt(*ip, temp);
}else if ( count == 1 ){
temp = charToInt(*ip, temp);
}else if ( count == 2 ){

该博客介绍了如何使用C/C++编程判断两个IP地址是否属于同一个网络段。通过与子网掩码进行位运算比较,如果得到相同的与运算结果,则认为两个IP在同一网段。
最低0.47元/天 解锁文章
50

被折叠的 条评论
为什么被折叠?



