Prefix *insert_a_node(Prefix *head,Prefix *node ){
Prefix *cur = head ;
if(head == NULL)
return node ;
if( node == NULL )
return head ;
if( node->IP < head->IP)
{ node->next = head ;
return node ; }
while( cur->next != NULL && cur->next->IP <= node->IP)
cur = cur->next ;
node->next = cur->next ;
cur->next = node ;
return head ;
}
Prefix *build_list(){
int a[4],len,i ;
int ip = 0 ;
Prefix *head = NULL ;
FILE *ofp ;
ofp
= fopen("trace_file","r") ; //此處為讀取檔案的DATA while( fscanf(ofp
,"%d.%d.%d.%d",&a
[0],&a
[1],&a
[2],&a
[3]) != EOF
){ Prefix
*node
= (Prefix
*)malloc(sizeof(Prefix
)) ; // if(a[1] == 0) 此處為len 處理 個人認為無關問題所在
node->len = 8 ;
if(a[1] != 0 && a[2] == 0)
node->len = 16 ;
if(a[2] != 0 && a[3] == 0)
node->len = 24 ;
if(a[0]*a[1]*a[2]*a[3] != 0 )
node->len =32 ; //
for ( i =0 ; i < 4 ; i++)
{ ip = ip + a[i] ;
if ( i != 3 )
ip = ip<<8 ; }
node->IP = ip ;
ip = 0 ;
head = insert_a_node(head,node);
}
}
UHJlZml4ICppbnNlcnRfYV9ub2RlKFByZWZpeCAqaGVhZCxQcmVmaXggKm5vZGUgKXsKICAgIFByZWZpeCAqY3VyID0gaGVhZCA7CiAgICBpZihoZWFkID09IE5VTEwpCiAgICAgICAgcmV0dXJuIG5vZGUgOwogICAgaWYoIG5vZGUgPT0gTlVMTCApCiAgICAgICByZXR1cm4gaGVhZCA7CiAgICBpZiggbm9kZS0+SVAgPCBoZWFkLT5JUCkKICAgICAgeyBub2RlLT5uZXh0ID0gaGVhZCA7CiAgICAgICAgICByZXR1cm4gbm9kZSA7ICB9CiAgICB3aGlsZSggY3VyLT5uZXh0ICE9IE5VTEwgJiYgY3VyLT5uZXh0LT5JUCA8PSBub2RlLT5JUCkKICAgICAgICBjdXIgPSBjdXItPm5leHQgOwogICAgICAgbm9kZS0+bmV4dCA9IGN1ci0+bmV4dCA7CiAgICAgICBjdXItPm5leHQgPSBub2RlIDsKICAgICAgcmV0dXJuIGhlYWQgOwogICAgICAgICAgICAgICAgICAgICAgIH0KUHJlZml4ICpidWlsZF9saXN0KCl7CiAgIGludCBhWzRdLGxlbixpIDsKICAgaW50IGlwID0gMCA7CiAgUHJlZml4ICpoZWFkID0gTlVMTCA7CiBGSUxFICpvZnAgOwogb2ZwID0gZm9wZW4oInRyYWNlX2ZpbGUiLCJyIikgOyAvL+atpOiZleeCuuiugOWPluaqlOahiOeahERBVEEKIHdoaWxlKCBmc2NhbmYob2ZwLCIlZC4lZC4lZC4lZCIsJmFbMF0sJmFbMV0sJmFbMl0sJmFbM10pICE9IEVPRil7CiAgICAgICBQcmVmaXggKm5vZGUgPSAoUHJlZml4KiltYWxsb2Moc2l6ZW9mKFByZWZpeCkpIDsKICAvLyAgICAgICBpZihhWzFdID09IDApICAgICAgICAgICDmraTomZXngrpsZW4g6JmV55CGIOWAi+S6uuiqjeeCuueEoemXnOWVj+mhjOaJgOWcqAogICAgICAgICAgICAgbm9kZS0+bGVuID0gOCA7CiAgICAgICAgIGlmKGFbMV0gIT0gMCAmJiBhWzJdID09IDApCiAgICAgICAgICAgICBub2RlLT5sZW4gPSAxNiA7CiAgICAgICAgIGlmKGFbMl0gIT0gMCAmJiBhWzNdID09IDApCiAgICAgICAgICAgICBub2RlLT5sZW4gPSAyNCA7CiAgICAgICAgIGlmKGFbMF0qYVsxXSphWzJdKmFbM10gIT0gMCApCiAgICAgICAgICAgICBub2RlLT5sZW4gPTMyIDsgICAvLwogICBmb3IgKCBpID0wIDsgaSA8IDQgOyBpKyspCiAgIHsgIGlwID0gaXAgKyBhW2ldIDsKICAgIGlmICggaSAhPSAzICkKICAgICAgaXAgPSBpcDw8OCA7ICB9CiAgICAgICAgbm9kZS0+SVAgPSBpcCA7CiAgICAgICAgaXAgPSAwIDsKICAgICBoZWFkID0gaW5zZXJ0X2Ffbm9kZShoZWFkLG5vZGUpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgIH0K