示例#1
0
/* IPADDR_INFO_LIST */
static bool AsyncNotify_Move(TALLOC_CTX *mem_ctx, const uint8_t **ptr)
{
	const uint8_t *pos = *ptr;
	uint32_t length   = IVAL(pos,0);
	/* uint32_t reserved = IVAL(pos,4); */
	uint32_t num      = IVAL(pos,8);
	uint32_t n;

	pos += 12;

	for (n=0; n<num; n++) {
		uint32_t flags = IVAL(pos,0);
		struct in_addr ipv4;
		struct in6_addr ipv6;
		struct sockaddr_storage sas4, sas6;
		char *str4, *str6;
		pos += 4;

		ipv4.s_addr = *((const in_addr_t*)pos);
		in_addr_to_sockaddr_storage(&sas4, ipv4);
		str4 = print_canonical_sockaddr(mem_ctx, &sas4);
		pos += 4;

		memcpy(&ipv6.s6_addr, pos, 16);
		in6_addr_to_sockaddr_storage(&sas6, ipv6);
		str6 = print_canonical_sockaddr(mem_ctx, &sas6);
		pos += 16;

		d_printf("Flags 0x%08x", flags);
		if (flags & IPADDR_V4) {
			d_printf(" %s", str4);
		}
		if (flags & IPADDR_V6) {
			d_printf(" %s", str6);
		}
		if (flags & IPADDR_ONLINE) {
			d_printf(" Online");
		}
		if (flags & IPADDR_ONLINE) {
			d_printf(" Offline");
		}
		d_printf("\n");
		TALLOC_FREE(str4);
		TALLOC_FREE(str6);
	}

	if (pos - *ptr == length) {
		*ptr = pos;
		return true;
	}
	return false;
}
示例#2
0
bool namecache_store(const char *name,
                     int name_type,
                     int num_names,
                     struct ip_service *ip_list)
{
    time_t expiry;
    char *key, *value_string;
    int i;
    bool ret;

    /*
     * we use gecache call to avoid annoying debug messages about
     * initialised namecache again and again...
     */
    if (!gencache_init()) {
        return False;
    }

    if (name_type > 255) {
        return False; /* Don't store non-real name types. */
    }

    if ( DEBUGLEVEL >= 5 ) {
        TALLOC_CTX *ctx = talloc_stackframe();
        char *addr = NULL;

        DEBUG(5, ("namecache_store: storing %d address%s for %s#%02x: ",
                  num_names, num_names == 1 ? "": "es", name, name_type));

        for (i = 0; i < num_names; i++) {
            addr = print_canonical_sockaddr(ctx,
                                            &ip_list[i].ss);
            if (!addr) {
                continue;
            }
            DEBUGADD(5, ("%s%s", addr,
                         (i == (num_names - 1) ? "" : ",")));

        }
        DEBUGADD(5, ("\n"));
        TALLOC_FREE(ctx);
    }

    key = namecache_key(name, name_type);
    if (!key) {
        return False;
    }

    expiry = time(NULL) + lp_name_cache_timeout();

    /*
     * Generate string representation of ip addresses list
     * First, store the number of ip addresses and then
     * place each single ip
     */
    if (!ipstr_list_make(&value_string, ip_list, num_names)) {
        SAFE_FREE(key);
        SAFE_FREE(value_string);
        return false;
    }

    /* set the entry */
    ret = gencache_set(key, value_string, expiry);
    SAFE_FREE(key);
    SAFE_FREE(value_string);
    return ret;
}