Ejemplo n.º 1
0
int
get_min_mtu( void )
{
  struct ifi_info *info, *n;
  unsigned min_mtu_set = 0;
  unsigned min_mtu = 0;

  info = Get_ifi_info(AF_INET, 0);

  for(n = info; n; n = n->ifi_next)
    {
      if(!min_mtu_set)
        {
          min_mtu = n->ifi_mtu;
          min_mtu_set = 1;
        }
      else if( n->ifi_mtu < min_mtu )
        {
          min_mtu = n->ifi_mtu;
        }
    }

  free_ifi_info(info);
  return min_mtu;
}
Ejemplo n.º 2
0
struct ifi_info *
get_first_multicast_interface ( void )
{
   struct ifi_info *info, *n;

   info =  Get_ifi_info(AF_INET, 0);

   for(n = info; n; n = n->ifi_next)
    {
      /* The interface must be UP, not loopback and multicast enabled */
      if(! (n->ifi_flags & IFF_UP) )
        {
          continue;
        }

      if( n->ifi_flags & IFF_LOOPBACK )
        {
          continue;
        } 

      if(! (n->ifi_flags & IFF_MULTICAST) )
        {
          continue;
        }

      return n;
    }
   return NULL;
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
	struct ifi_info	*ifi, *ifihead;
	struct sockaddr	*sa;
	u_char			*ptr;
	int				i, family, doaliases;

	if (argc != 3)
		err_quit("usage: prifinfo <inet4|inet6> <doaliases>");

	if (strcmp(argv[1], "inet4") == 0)
		family = AF_INET;
#ifdef	IPv6
	else if (strcmp(argv[1], "inet6") == 0)
		family = AF_INET6;
#endif
	else
		err_quit("invalid <address-family>");
	doaliases = atoi(argv[2]);

	for (ifihead = ifi = Get_ifi_info(family, doaliases);
		 ifi != NULL; ifi = ifi->ifi_next) {
		printf("%s: ", ifi->ifi_name);
		if (ifi->ifi_index != 0)
			printf("(%d) ", ifi->ifi_index);
		printf("<");
/* *INDENT-OFF* */
		if (ifi->ifi_flags & IFF_UP)			printf("UP ");
		if (ifi->ifi_flags & IFF_BROADCAST)		printf("BCAST ");
		if (ifi->ifi_flags & IFF_MULTICAST)		printf("MCAST ");
		if (ifi->ifi_flags & IFF_LOOPBACK)		printf("LOOP ");
		if (ifi->ifi_flags & IFF_POINTOPOINT)	printf("P2P ");
		printf(">\n");
/* *INDENT-ON* */

		if ( (i = ifi->ifi_hlen) > 0) {
			ptr = ifi->ifi_haddr;
			do {
				printf("%s%x", (i == ifi->ifi_hlen) ? "  " : ":", *ptr++);
			} while (--i > 0);
			printf("\n");
		}
		if (ifi->ifi_mtu != 0)
			printf("  MTU: %d\n", ifi->ifi_mtu);

		if ( (sa = ifi->ifi_addr) != NULL)
			printf("  IP addr: %s\n",
						my_sock_ntop_host(sa, sizeof(*sa)));
		if ( (sa = ifi->ifi_brdaddr) != NULL)
			printf("  broadcast addr: %s\n",
						my_sock_ntop_host(sa, sizeof(*sa)));
		if ( (sa = ifi->ifi_dstaddr) != NULL)
			printf("  destination addr: %s\n",
						my_sock_ntop_host(sa, sizeof(*sa)));
	}
	free_ifi_info(ifihead);
	exit(0);
}
Ejemplo n.º 4
0
int main (int argc, char **argv)
{
	struct ifi_info	*ifi, *ifihead;
	struct sockaddr	*sa;
	u_char	*ptr;
	int i, family, doaliases;

	if (argc != 2)
	{
		printf ("usage: ictl  <doaliases>\n");
		exit(1);
	}
   printf("\n");
	family = AF_INET;
	doaliases = atoi(argv[1]);

	for (ifihead = ifi = Get_ifi_info(family, doaliases); ifi != NULL; ifi = ifi->ifi_next)
	{
		printf("%s: < ", ifi->ifi_name);

		if (ifi->ifi_flags & IFF_UP)
                          		printf("UP ");
		if (ifi->ifi_flags & IFF_BROADCAST)
			printf("BCAST ");
		if (ifi->ifi_flags & IFF_MULTICAST)
			printf("MCAST ");
		if (ifi->ifi_flags & IFF_LOOPBACK)
			printf("LOOP ");
		if (ifi->ifi_flags & IFF_POINTOPOINT)
			printf("P2P ");
		printf(">\n");

		ifi->ifi_hlen = 6;
		if ( (i = ifi->ifi_hlen) > 0)
		{
			printf("  MAC Address: ");
			ptr = (u_char *)ifi->ifi_hwaddr;
			//printf ("%x:%x:%x:%x:%x:%x\n", *(ptr +2), *(ptr +3), *(ptr +4),
         //	*(ptr +5), *(ptr + 6), *(ptr + 7));
			ptr++;
			do
			{
				printf("%s%x", (i == ifi->ifi_hlen) ? "  " : ":", *++ptr);
			}
			while (--i > 0);
				printf("\n");
		}
      if ( (sa = ifi->ifi_addr) != NULL)
			printf("  IP Address: %s\n", Sock_ntop_host(sa, sizeof(*sa)));
		if ( (sa = ifi->ifi_brdaddr) != NULL)
			printf("  Broadcast Address: %s\n", Sock_ntop_host(sa, sizeof(*sa)));
		if ( (sa = ifi->ifi_dstaddr) != NULL)
			printf("  Point-to-Point Address: %s\n", Sock_ntop_host(sa, sizeof(*sa)));
		printf("\n");
	}
	free_ifi_info(ifihead);
	exit(0);
}
Ejemplo n.º 5
0
struct ifi_info *
get_interface ( char *name )
{
   struct ifi_info *info, *n;

   info =  Get_ifi_info(AF_INET, 0);

   for(n = info; n; n = n->ifi_next)
    {
       if(!strcmp( name, n->ifi_name))
         {
           return n;
         }
    }

   return NULL;
}
Ejemplo n.º 6
0
/*
 * get_interface_list
 *
 * This function first scans the list of all the interfaces on the client and
 * stores it's associated IP and Mask.
 */
static int
get_interface_list (void)
{
    int idx = 0;
    struct ifi_info *ifi, *ifihead;
    struct sockaddr_in *sa, *netmask;
    char ip[IP_LEN], mask[IP_LEN], subnet[IP_LEN];

    printf("\nINTERFACE LIST:\n");

    /* Walk through all the interfaces in the system */
    for (ifihead = ifi = Get_ifi_info(AF_INET, 1); ifi != NULL; 
         ifi = ifi->ifi_next) {

        /* Store the connection details in our local conn_info structure */
        sa = (struct sockaddr_in *)ifi->ifi_addr;
        netmask = (struct sockaddr_in *)ifi->ifi_ntmaddr;
        bzero(&cli_params->iface[idx], sizeof(iface_info_t));
        memcpy(cli_params->iface[idx].ifname, ifi->ifi_name, IFNAME_LEN);
        memcpy(&cli_params->iface[idx].ip, sa, sizeof(struct sockaddr_in));
        memcpy(&cli_params->iface[idx].netmask, netmask, 
               sizeof(struct sockaddr_in));
        cli_params->iface[idx].subnet.sin_addr.s_addr = 
            (cli_params->iface[idx].ip.sin_addr.s_addr & 
             cli_params->iface[idx].netmask.sin_addr.s_addr);

        /* Display it! */
        printf("interface: %s ip: %s mask: %s subnet: %s\n", 
               cli_params->iface[idx].ifname,
               inet_ntop(AF_INET, &(cli_params->iface[idx].ip.sin_addr), 
                         ip, IP_LEN), 
               inet_ntop(AF_INET, &(cli_params->iface[idx].netmask.sin_addr), 
                         mask, IP_LEN), 
               inet_ntop(AF_INET, &(cli_params->iface[idx].subnet.sin_addr), 
                         subnet, IP_LEN));

        idx++;
    }

    cli_params->iface_count = idx;

    return 0;
}
Ejemplo n.º 7
0
Archivo: main.c Proyecto: AnSwErYWJ/UNP
int
main(int argc, char **argv)
{
	int					sockfd;
	char				buf[MAXLINE];
	ssize_t				n;
	socklen_t			salen, len;
	struct ifi_info		*ifi;
	struct sockaddr		*mcastsa, *wild, *from;
	struct timeval		now;

	if (argc != 2)
		err_quit("usage: ssntp <IPaddress>");

	sockfd = Udp_client(argv[1], "ntp", (void **) &mcastsa, &salen);

	wild = Malloc(salen);
	memcpy(wild, mcastsa, salen);	/* copy family and port */
	sock_set_wild(wild, salen);
	Bind(sockfd, wild, salen);	/* bind wildcard */

#ifdef	MCAST
		/* 4obtain interface list and process each one */
	for (ifi = Get_ifi_info(mcastsa->sa_family, 1); ifi != NULL;
		 ifi = ifi->ifi_next) {
		if (ifi->ifi_flags & IFF_MULTICAST) {
			Mcast_join(sockfd, mcastsa, salen, ifi->ifi_name, 0);
			printf("joined %s on %s\n",
				   Sock_ntop(mcastsa, salen), ifi->ifi_name);
		}
	}
#endif

	from = Malloc(salen);
	for ( ; ; ) {
		len = salen;
		n = Recvfrom(sockfd, buf, sizeof(buf), 0, from, &len);
		Gettimeofday(&now, NULL);
		sntp_proc(buf, n, &now);
	}
}
Ejemplo n.º 8
0
int main(int argc, char** argv)
{
    int sockfd, family, port;
    const int on = 1;
    pid_t pid;
    socklen_t salen;
    struct sockaddr *sa, *wild;
    struct ifi_info *ifi, *ifihead;

    if (argc == 2)
        sockfd = Udp_client(NULL, argv[1], (void**)&sa, &salen);
    else if (argc == 3)
        sockfd = Udp_client(argv[1], argv[2], (void**)&sa, &salen);
    else
        err_quit("usage: udpserv04 [ <host> ] <service or port>");
    family = sa->sa_family;
    port = sock_get_port(sa, salen);
    Close(sockfd); /* we just want family, port, salen */

    for (ifihead = ifi = Get_ifi_info(family, 1); ifi != NULL;
         ifi = ifi->ifi_next) {
        /*4bind unicast address */
        sockfd = Socket(family, SOCK_DGRAM, 0);
        Setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

        sock_set_port(ifi->ifi_addr, salen, port);
        Bind(sockfd, ifi->ifi_addr, salen);
        printf("bound %s\n", Sock_ntop(ifi->ifi_addr, salen));

        if ((pid = Fork()) == 0) { /* child */
            mydg_echo(sockfd, ifi->ifi_addr, salen);
            exit(0); /* never executed */
        }

        if (ifi->ifi_flags & IFF_BROADCAST) {
            /* 4try to bind broadcast address */
            sockfd = Socket(family, SOCK_DGRAM, 0);
            Setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

            sock_set_port(ifi->ifi_brdaddr, salen, port);
            if (bind(sockfd, ifi->ifi_brdaddr, salen) < 0) {
                if (errno == EADDRINUSE) {
                    printf("EADDRINUSE: %s\n",
                           Sock_ntop(ifi->ifi_brdaddr, salen));
                    Close(sockfd);
                    continue;
                } else
                    err_sys("bind error for %s",
                            Sock_ntop(ifi->ifi_brdaddr, salen));
            }
            printf("bound %s\n", Sock_ntop(ifi->ifi_brdaddr, salen));

            if ((pid = Fork()) == 0) { /* child */
                mydg_echo(sockfd, ifi->ifi_brdaddr, salen);
                exit(0); /* never executed */
            }
        }
    }

    /* 4bind wildcard address */
    sockfd = Socket(family, SOCK_DGRAM, 0);
    Setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));

    wild = Malloc(salen);
    memcpy(wild, sa, salen); /* copy family and port */
    sock_set_wild(wild, salen);

    Bind(sockfd, wild, salen);
    printf("bound %s\n", Sock_ntop(wild, salen));

    if ((pid = Fork()) == 0) { /* child */
        mydg_echo(sockfd, wild, salen);
        exit(0); /* never executed */
    }
    exit(0);
}
Ejemplo n.º 9
0
struct ifi_info *
get_first_interface ( void )
{
   return Get_ifi_info(AF_INET, 0); 
}