Ejemplo n.º 1
0
DOUBLE_PRECISION getifreq_(INTEGER *dummy)
{
    return (getifreq());
}
Ejemplo n.º 2
0
void ifget(int sockfd, enum mode mode, char *name)
{
	char *buf,*ptr,*colon;
	int len;
	int l;
	struct ifreq *ifr;
	struct sockaddr_in *sa_in, *sin;
#ifdef  HAVE_arpreq
	struct arpreq arpreq;
#endif
#ifndef USE_IFALIAS
	int cnt = 0;
#endif

	buf = getifreq(sockfd, &len);

	for(ptr=buf;ptr < buf+len;) 
	{
		ifr=(struct ifreq *)ptr;

		if (mode == IP) 
		{
			sa_in=(struct sockaddr_in *)&ifr->ifr_addr;
			if(strncmp(name,inet_ntoa(sa_in->sin_addr), IFNAMSIZ) == 0)
				printf("%s\n",ifr->ifr_name);
#ifdef DEBUG
			fprintf(stderr, "%s %s %s\n", name, inet_ntoa(sa_in->sin_addr), ifr->ifr_name);
#endif
		} 
		else if (mode == IF) 
		{
			/* This is rather questionable on linux and solaris */
			/* It will probably go in later versions */
			/* We return names of devices which are aliased. */
			/* Under BSD this makes no sense so we fake it */
			/* Note: the numbers under BSD are just placeholders */
#ifdef USE_IFALIAS
			if((colon=memchr(ifr->ifr_name,':',strlen(ifr->ifr_name))) != NULL) 
			{
				*colon='\0';

				if(strncmp(name,ifr->ifr_name, IFNAMSIZ) == 0)
					printf("%s\n",++colon);
			}
#else
			if(strncmp(name,ifr->ifr_name, IFNAMSIZ) == 0)
			{
				sa_in=(struct sockaddr_in *)&ifr->ifr_addr;
				if (sa_in->sin_family == AF_INET)
				{
					if (cnt > 0)
					{
						printf("%d\n", cnt);
					}
					cnt++;
				}
			}
#endif
#ifdef DEBUG
			fprintf(stderr, "%s %s\n", name, ifr->ifr_name);
#endif
		} 
		else if (mode == HW)
		{
			if(strncmp(name,ifr->ifr_name, IFNAMSIZ) == 0) 
			{
#ifdef HAVE_sockaddr_dl
				print_arp(LLADDR((struct sockaddr_dl *) &ifr->ifr_addr));
#elif defined(HAVE_SIOCGIFHWADDR)
				if(ioctl(sockfd,SIOCGIFHWADDR,ifr) == 0) 
				{
					print_arp(ifr->ifr_hwaddr.sa_data);
				}
#elif defined(HAVE_arpreq)
				memset(&arpreq, 0, sizeof(arpreq));
				sin = ((struct sockaddr_in *) &arpreq.arp_pa);
				memset(sin, 0, sizeof(*sin));
				sa_in=(struct sockaddr_in *)&ifr->ifr_addr;
				memcpy(&sin->sin_addr, &sa_in->sin_addr, sizeof(struct in_addr));
				if(ioctl(sockfd,SIOCGARP,&arpreq) == 0) 
				{
					print_arp(arpreq.arp_ha.sa_data);
				}
#else
# error "Unable to work out hardware address"
#endif
			break;
			}
		}
		else
		{
			error(3, "Invalid mode");
		}

#ifdef SA_LEN_IN_SOCKADDR
		l = ifr->ifr_addr.sa_len + sizeof(ifr->ifr_name);
                if (l < sizeof(*ifr))
                        l = sizeof(*ifr);
#else
		l = sizeof(ifr->ifr_name)+sizeof(struct sockaddr);
#endif

		ptr+=l;
	}
	free(buf);
}