pike.git / lib / modules / NetUtils.pmod

version» Context lines:

pike.git/lib/modules/NetUtils.pmod:253:    {    if( a == "0.0.0.0" )    a = "::";    else    a = "::"+a;    }    return a+"/"+n;    case "array":    return ({ net, mask });    default: -  error("Can not cast to %O\n", type ); +  return UNDEFINED;    }       }    -  protected string _sprintf( int flag, mapping opt ) +  protected string _sprintf( int flag )    {    switch( flag )    {    case 't': return "NetMask";    case 'O': return "NetMask("+(string)this+")";    default: return (string)this;    }    }   }   
pike.git/lib/modules/NetUtils.pmod:320:    return sprintf("Range(%O -> %O)", (string)this, info);    }    }       //! Return a copy of the internal range to info mapping.    mapping(string:array(Range)) get_ranges()    {    return range_to_info + ([]);    }    -  protected string _sprintf() +  protected string _sprintf(int c)    {    return sprintf("IpRangeLookup( %{%O %})",Array.flatten(values(range_to_info)));    }       //! Looks up an IP address and returns the associated information, if any.    //!    //! @param ipstr    //! The IP address in string or binary form.    //! @returns    //! The information associated with the most-specific IP range
pike.git/lib/modules/NetUtils.pmod:361:    for( int i=0; i<=strlen(ip_str); i++ )    if(array(Range) ranges=range_to_info[ip_str[..<i]])    foreach(ranges, Range x )    if(x->ip_in( ipstr ))    return x;    }          // Ensures that the netmask only contains 255 or 0 bytes.    // This is used to speed up the lookup() function above. -  static string trim_net( int net, int mask ) +  protected string trim_net( int net, int mask )    {    int x = (net&(((1<<(mask->size()))-1)^((1<<(mask->size()-(mask->popcount()&~7)))-1)));       string q = x->digits(256);    while( strlen(q) && q[-1] == 0 )    q = q[..<1];    return q;    }       //! Creates a new IpRangeLookup object and initialises the IP range    //! table. Errors will be thrown if @[ranges] contains invalid    //! data.    //!    //! @param ranges    //! A mapping from information data to arrays of IP ranges.    //!    //! Each range can be a single addresses ("192.168.1.1"), a    //! range of addresses ("192.168.1.1-192.168.1.5") or be    //! written in CIDR notation ("192.168.1.0/24"). -  void create(mapping(mixed:array(string)) ranges, int|void _debug) +  void create(mapping(mixed:array(string)) ranges)    {    void add_range( Range range )    {    string key = trim_net(range->net,range->mask);    if( !range_to_info[key] )    range_to_info[key] = ({ range });    else    range_to_info[key] |= ({ range });    };    foreach( ranges; string info; array(string) ips )
pike.git/lib/modules/NetUtils.pmod:643:       mapping(string:array(string)) next__interfaces = ([]);       mapping(string:array(string)) next__broadcast_addresses = ([]);    foreach( ifconfig("list if" )/"\n", string iface )    {    array ips = ({});    foreach( (ifconfig(iface) + ifconfig(iface + " inet6"))/"\n",    string q )    { -  string i,m; +  string i,m,f;    q = String.trim_whites(q); -  +  if( sscanf( q, "%*sflags=%*x<%s>", f )==3 && +  search(f/",", "UP")<0) { +  // ignore interfaces which are not up +  ips = ({}); +  break; +  }    if( (sscanf( q, "inet addr:%[^ ]%*sMask:%s", i, m )==3) ||    (sscanf( q, "inet %[^ ] mask %[^ ]", i, m )==2) ||    (sscanf( q, "inet %[^ ]%*snetmask %[^ ]", i, m )==3))    {    ips += ({i+"/"+netmask_to_cidr(m)});    ips += ({ "::ffff:"+i+"/"+(96+netmask_to_cidr(m)) });    }    else if( (sscanf( q, "inet6 addr: %[^ ] %s", i, m ) ) ||    (sscanf( q, "inet6 %[^ ] %s", i, m )) )    {
pike.git/lib/modules/NetUtils.pmod:1024:    res = res[..search(res,GLOBALV6)-1] + prio + (res[search(res,GLOBALV6)..]-prio);    }    if( !v4 )    {    res -= ({ LOCALHOST, LOCAL, GLOBAL, MULTICAST, PRIVATE, });    }       return res;   }    - //! Returns network types in priority order according to RFC 3484. + //! Returns network types in priority order according to @rfc{3484@}.   //!   //! This function assumes a network category (ipv4 or ipv6) is   //! available if the local host has a configured address (excluding   //! localhost) of that network type.   //!   //! This function will always list the v6 and non-v6 addresses   //! separately.   array(NetworkType) connectable_network_types()   {    if( __c_n_t ) return __c_n_t;
pike.git/lib/modules/NetUtils.pmod:1084:       //3: Sort    foreach( connectable_types, string type )    if( tmp[type] )    res += Array.shuffle(tmp[type]);       return res;   }      //! Given a list of addresses, sort them according to connectable - //! priority order (RFC 3484). + //! priority order (@rfc{3484@}).   //!   //! If @[exclude_types] is specified, addresses that match any of the   //! network types (({"local", "localhost"}) for the local network as an example)   //! in the given array will be exluded from the result.   //!   //! If @[separate_v6] is true, @[exclude_types] separates v6 from   //! v4. That is, you can disable "localhost" without also disabling   //! "localhostv6".   //!   //! The addresses inside each group will be returned in random order.   array(string) sort_addresses( array(string) addresses,    array(NetworkType)|void exclude_types,    bool|void separate_v6)   {    return _sort_addresses( addresses, exclude_types, separate_v6,    connectable_network_types() );   }