rem: )
context: int add_interfaces(char* if_name, int family, unsigned short port,					unsigned short proto,					struct socket_info** list){	struct ifconf ifc;	struct ifreq ifr;	struct ifreq ifrcopy;	char*  last;	char* p;	int size;	int lastlen;	int s;	char* tmp;	struct ip_addr addr;	int ret;	enum si_flags flags;	#ifdef HAVE_SOCKADDR_SA_LEN	#ifndef MAX		#define MAX(a,b) ( ((a)>(b))?(a):(b))	#endif#endif	/* ipv4 or ipv6 only*/	flags=SI_NONE;	s=socket(family, SOCK_DGRAM, 0);	ret=-1;	lastlen=0;	ifc.ifc_req=0;	for (size=100; ; size*=2){		ifc.ifc_len=size*sizeof(struct ifreq);		ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));		if (ifc.ifc_req==0){			LOG(L_ERR, "ERROR: add_interfaces: memory allocation failure\n");			goto error;		}		if (ioctl(s, SIOCGIFCONF, &ifc)==-1){			if(errno==EBADF) return 0; /* invalid descriptor => no such ifs*/			LOG(L_ERR, "ERROR: add_interfaces: ioctl failed: %s\n",					strerror(errno));			goto error;		}		if  ((lastlen) && (ifc.ifc_len==lastlen)) break; /*success,														   len not changed*/		lastlen=ifc.ifc_len;		/* try a bigger array*/		pkg_free(ifc.ifc_req);	}		last=(char*)ifc.ifc_req+ifc.ifc_len;	for(p=(char*)ifc.ifc_req; p<last;			p+=(sizeof(ifr.ifr_name)+			#ifdef  HAVE_SOCKADDR_SA_LEN				MAX(ifr.ifr_addr.sa_len, sizeof(struct sockaddr))			#else				( (ifr.ifr_addr.sa_family==AF_INET)?					sizeof(struct sockaddr_in):					((ifr.ifr_addr.sa_family==AF_INET6)?						sizeof(struct sockaddr_in6):sizeof(struct sockaddr)) )			#endif				)		)	{		/* copy contents into ifr structure		 * warning: it might be longer (e.g. ipv6 address) */		memcpy(&ifr, p, sizeof(ifr));		if (ifr.ifr_addr.sa_family!=family){			/*printf("strange family %d skipping...\n",					ifr->ifr_addr.sa_family);*/			continue;		}				/*get flags*/		ifrcopy=ifr;		if (ioctl(s, SIOCGIFFLAGS,  &ifrcopy)!=-1){ /* ignore errors */			/* ignore down ifs only if listening on all of them*/			if (if_name==0){ 				/* if if not up, skip it*/				if (!(ifrcopy.ifr_flags & IFF_UP)) continue;			}		}								if ((if_name==0)||			(strncmp(if_name, ifr.ifr_name, sizeof(ifr.ifr_name))==0)){						/*add address*/			sockaddr2ip_addr(&addr, 					(struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));			if ((tmp=ip_addr2a(&addr))==0) goto error;			/* check if loopback */			if (ifrcopy.ifr_flags & IFF_LOOPBACK) 				flags|=SI_IS_LO;			/* add it to one of the lists */			if (new_sock2list(tmp, port, proto, flags, list)!=0){				LOG(L_ERR, "ERROR: add_interfaces: new_sock2list failed\n");				goto error;			}			ret=0;		}			/*			printf("%s:\n", ifr->ifr_name);			printf("        ");			print_sockaddr(&(ifr->ifr_addr));			printf("        ");			ls_ifflags(ifr->ifr_name, family, options);			printf("\n");*/	}	pkg_free(ifc.ifc_req); /*clean up*/	close(s);	return  ret;error:	if (ifc.ifc_req) pkg_free(ifc.ifc_req);	close(s);	return -1;}