v4lookup()

v4lookup()

概要

  • /sys/src/9/ip/iproute.c?にて定義

引数

実装

  484: Route*
  485: v4lookup(Fs *f, uchar *a, Conv *c)
  486: {
  487:         Route *p, *q;
  488:         ulong la;
  489:         uchar gate[IPaddrlen];
  490:         Ipifc *ifc;
  491: 
  492:         if(c != nil && c->r != nil && c->r->ifc != nil && c->rgen == v4routegeneration)
  493:                 return c->r;
  494: 
  495:         la = nhgetl(a);
  496:         q = nil;
  497:         for(p=f->v4root[V4H(la)]; p;)
  • 詳細はV4H()?にて定義
  498:                 if(la >= p->v4.address) {
  499:                         if(la <= p->v4.endaddress) {
  500:                                 q = p;
  501:                                 p = p->mid;
  502:                         } else
  503:                                 p = p->right;
  504:                 } else
  505:                         p = p->left;
  506: 
  507:         if(q && (q->ifc == nil || q->ifcid != q->ifc->ifcid)){
  508:                 if(q->type & Rifc) {
  509:                         hnputl(gate+IPv4off, q->v4.address);
  510:                         memmove(gate, v4prefix, IPv4off);
  511:                 } else
  512:                         v4tov6(gate, q->v4.gate);
  513:                 ifc = findipifc(f, gate, q->type);
  514:                 if(ifc == nil)
  515:                         return nil;
  516:                 q->ifc = ifc;
  517:                 q->ifcid = ifc->ifcid;
  518:         }
  519: 
  520:         if(c != nil){
  521:                 c->r = q;
  522:                 c->rgen = v4routegeneration;
  523:         }
  524: 
  525:         return q;
  526: }