Changeset bdae198 in mainline for uspace/lib/c/generic/inet/addr.c


Ignore:
Timestamp:
2013-08-04T12:01:10Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ea50906
Parents:
b08879c2 (diff), d856110 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/inet/addr.c

    rb08879c2 rbdae198  
    5252};
    5353
     54static const addr48_t inet_addr48_solicited_node = {
     55        0x33, 0x33, 0xff, 0, 0, 0
     56};
     57
    5458static const inet_addr_t inet_addr_any_addr = {
    5559        .family = AF_INET,
     
    7074{
    7175        memcpy(dst, src, 16);
     76}
     77
     78int addr48_compare(const addr48_t a, const addr48_t b)
     79{
     80        return memcmp(a, b, 6);
     81}
     82
     83int addr128_compare(const addr128_t a, const addr128_t b)
     84{
     85        return memcmp(a, b, 16);
     86}
     87
     88/** Compute solicited node MAC multicast address from target IPv6 address
     89 *
     90 * @param ip  Target IPv6 address
     91 * @param mac Solicited MAC address to be assigned
     92 *
     93 */
     94void addr48_solicited_node(const addr128_t ip, addr48_t mac)
     95{
     96        memcpy(mac, inet_addr48_solicited_node, 3);
     97        memcpy(mac + 3, ip + 13, 3);
    7298}
    7399
     
    212238}
    213239
     240void inet_addr_naddr(const inet_addr_t *addr, uint8_t prefix,
     241    inet_naddr_t *naddr)
     242{
     243        naddr->family = addr->family;
     244        memcpy(naddr->addr6, addr->addr6, 16);
     245        naddr->prefix = prefix;
     246}
     247
    214248void inet_addr_any(inet_addr_t *addr)
    215249{
     
    234268                return (a->addr == b->addr);
    235269        case AF_INET6:
    236                 return memcmp(&a->addr6, &b->addr6, 16);
     270                return addr128_compare(a->addr6, b->addr6);
    237271        default:
    238272                return 0;
     
    245279            (inet_addr_compare(addr, &inet_addr_any_addr)) ||
    246280            (inet_addr_compare(addr, &inet_addr_any_addr6)));
     281}
     282
     283int inet_naddr_compare(const inet_naddr_t *naddr, const inet_addr_t *addr)
     284{
     285        if (naddr->family != addr->family)
     286                return 0;
     287       
     288        switch (naddr->family) {
     289        case AF_INET:
     290                return (naddr->addr == addr->addr);
     291        case AF_INET6:
     292                return addr128_compare(naddr->addr6, addr->addr6);
     293        default:
     294                return 0;
     295        }
    247296}
    248297
Note: See TracChangeset for help on using the changeset viewer.