我想更新给定数组中的条目,这样如果ptr_shost/ptr_dhost
对是相同的,我只会将更新的字段存储在相同的ptr_shost/ptr_dhost
对中。当我到时,你可以指向我制作错误,因为我看到一些值只是重复而不是我想要的。下面是我的代码:
void mysort(struct my_mac data[],int n){
int j,i = 0,k;
struct my_mac temp[1000];
while(i < n){
for(j = i+1; j < n; j++){
char src1[20];
char dst1[20];
char src2[20];
char dst2[20];
ether_ntoa_r(data[i].ptr_shost,src1);
ether_ntoa_r(data[i].ptr_dhost,dst1);
ether_ntoa_r(data[j].ptr_shost,src2);
ether_ntoa_r(data[j].ptr_dhost,dst2);
int comp1 = strcmp(src1, src2);
int comp2 = strcmp(dst1,dst2);
if( comp1 == 0 && comp2 == 0 && i!=j){
temp[i].ptr_shost = data[j].ptr_shost;
temp[i].ptr_dhost = data[j].ptr_dhost;
temp[i].packets = data[j].packets;
temp[i].octets += data[j].octets;
}else{
temp[i].ptr_shost = data[j].ptr_shost;
temp[i].ptr_dhost = data[i].ptr_dhost;
temp[i].packets = data[j].packets;
temp[i].octets = data[j].octets;
}
}i++;
}
编辑:添加了结构
struct my_mac {
u_char *ptr_dhost;
u_char *ptr_shost;
int octets;
int packets;
};