Re: [Linux-cluster] Multicast for GFS?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2004-08-09 at 15:34, Patrick Caulfield wrote:
> OK, thanks for clearing that up. It seems I have some thinking to do...

holiday? egypt? :) 

ok, attached is the file with two new functions: my_gethostbyname2() and
my_freehe(). First should be used everywhere instead of gethostbyname(),
and the later should be called to free up  all the used memory. 

I deliberately didn't send a patch, since I haven't CO'ed yet, so patch
would fail with new version. I'm counting on you for incorporating it
into new tree. :)

With this, you can also keep the memcpy(mreq.imr_interaface, ...) since
it's working now :)

cheers 
-- 
Lazar Obradovic, System Engineer
----- 
laza@xxxxxx
YUnet International http://www.EUnet.yu
Dubrovacka 35/III, 11000 Belgrade
Tel: +381 11 3119901; Fax: +381 11 3119901
-----
This e-mail is confidential and intended only for the recipient.
Unauthorized distribution, modification or disclosure of its
contents is prohibited. If you have received this e-mail in error,
please notify the sender by telephone +381 11 3119901.
-----
struct hostent *my_gethostbyname2(const char *name, int af)
{
    struct hostent *he, *tmp_he;
    int i;

    tmp_he = gethostbyname2(name, af);
    if (!tmp_he) {
        return tmp_he;
    }

    he = malloc (sizeof(struct hostent));
    if (!he)
        die ("Malloc (hostent) failed\n");

    he->h_name = strdup ((char *)tmp_he->h_name);
    he->h_addrtype = tmp_he->h_addrtype;
    he->h_length = tmp_he->h_length;

    i=0;
    while (tmp_he->h_aliases[i]) {
        he->h_aliases = realloc (he->h_aliases, sizeof(char *));
	/* realloc could also fail */ 
	if (he->h_aliases == NULL) { 
		die ("Realloc(h_aliases) failed\n");
	}
        he->h_aliases[i] = strdup(tmp_he->h_aliases[i]);
        i++;
    }

    i = 0;
    while (tmp_he->h_addr_list[i]) {
        he->h_addr_list = realloc (he->h_addr_list, sizeof(char *));
	if (he->h_addr_list == NULL) { 
		die ("Realloc(h_addr_list) failed\n"); 
	}
        he->h_addr_list[i] = strdup (tmp_he->h_addr_list[i]);
        i++;
    };

    return he;
}

static int my_freehe (struct hostent *he)
{
    /* no need for a separate free'ing, since it's all just one large block */
    free (he->h_addr_list);
    free (he->h_aliases);
    
    free (he->h_name);
    free (he);

    return 0;
}

[Index of Archives]     [Corosync Cluster Engine]     [GFS]     [Linux Virtualization]     [Centos Virtualization]     [Centos]     [Linux RAID]     [Fedora Users]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite Camping]

  Powered by Linux