fork download
  1. Prefix *insert_a_node(Prefix *head,Prefix *node ){
  2. Prefix *cur = head ;
  3. if(head == NULL)
  4. return node ;
  5. if( node == NULL )
  6. return head ;
  7. if( node->IP < head->IP)
  8. { node->next = head ;
  9. return node ; }
  10. while( cur->next != NULL && cur->next->IP <= node->IP)
  11. cur = cur->next ;
  12. node->next = cur->next ;
  13. cur->next = node ;
  14. return head ;
  15. }
  16. Prefix *build_list(){
  17. int a[4],len,i ;
  18. int ip = 0 ;
  19. Prefix *head = NULL ;
  20. FILE *ofp ;
  21. ofp = fopen("trace_file","r") ; //此處為讀取檔案的DATA
  22. while( fscanf(ofp,"%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]) != EOF){
  23. Prefix *node = (Prefix*)malloc(sizeof(Prefix)) ;
  24. // if(a[1] == 0) 此處為len 處理 個人認為無關問題所在
  25. node->len = 8 ;
  26. if(a[1] != 0 && a[2] == 0)
  27. node->len = 16 ;
  28. if(a[2] != 0 && a[3] == 0)
  29. node->len = 24 ;
  30. if(a[0]*a[1]*a[2]*a[3] != 0 )
  31. node->len =32 ; //
  32. for ( i =0 ; i < 4 ; i++)
  33. { ip = ip + a[i] ;
  34. if ( i != 3 )
  35. ip = ip<<8 ; }
  36. node->IP = ip ;
  37. ip = 0 ;
  38. head = insert_a_node(head,node);
  39. }
  40. }
  41.  
Success #stdin #stdout 0s 4496KB
stdin
Standard input is empty
stdout
Standard output is empty