예제 #1
0
파일: interface.c 프로젝트: Acidburn0zzz/mc
/****************************************************************************
  get the broadcast address for our address 
([email protected])
****************************************************************************/
static void
get_broadcast (struct in_addr *if_ipaddr, struct in_addr *if_bcast, struct in_addr *if_nmask)
{
    uint32 nm;
    short onbc;
    short offbc;

    /* get a default netmask and broadcast */
    default_netmask (if_nmask, if_ipaddr);

    get_netmask (if_ipaddr, if_nmask);

    /* sanity check on the netmask */
    nm = ntohl (if_nmask->s_addr);
    onbc = 0;
    offbc = 0;
    while ((onbc + offbc) < 32)
    {
        if (nm & 0x80000000)
        {
            onbc++;
            if (offbc)
            {
                /* already found an off bit, so mask
                   is wrong */
                onbc = 34;
            }
        }
        else
        {
            offbc++;
        }
        nm <<= 1;
    }
    if ((onbc < 8) || (onbc == 34))
    {
        DEBUG (0, ("Impossible netmask %s - using defaults\n", inet_ntoa (*if_nmask)));
        default_netmask (if_nmask, if_ipaddr);
    }

    /* derive the broadcast assuming a 1's broadcast, as this is what
       all MS operating systems do, we have to comply even if the unix
       box is setup differently */
    if_bcast->s_addr = MKBCADDR (if_ipaddr->s_addr, if_nmask->s_addr);

    DEBUG (4, ("Derived broadcast address %s\n", inet_ntoa (*if_bcast)));
}
예제 #2
0
파일: route.c 프로젝트: monomaniar/prettyos
static inline unsigned long guess_mask(unsigned long dst, struct net_device *dev)
{
    unsigned long mask;
    if(!dst)
        return 0;
    mask = default_netmask(dst);
    if((dst ^ dev->pa_addr) & mask)
        return mask;
    return dev->pa_mask;
}
예제 #3
0
int
ifconfig (char *ip, char *sm, char *gw, char *svr)
{
  in_addr tmp;
  
  if (sm) 
    {
      if (! inet_aton (sm, &tmp))
	return 0;
      
      netmask = tmp.s_addr;
    }
  
  if (ip) 
    {
      if (! inet_aton (ip, &arptable[ARP_CLIENT].ipaddr)) 
	return 0;
      
      if (! netmask && ! sm) 
	netmask = default_netmask ();
    }
  
  if (gw && ! inet_aton (gw, &arptable[ARP_GATEWAY].ipaddr)) 
    return 0;

  
  grub_memset (arptable[ARP_GATEWAY].node, 0, ETH_ALEN);
  
  if (svr && ! inet_aton (svr, &arptable[ARP_SERVER].ipaddr)) 
    return 0;

  
  grub_memset (arptable[ARP_SERVER].node, 0, ETH_ALEN);
  
  if (ip || sm)
    {
      if (IP_BROADCAST == (netmask | arptable[ARP_CLIENT].ipaddr.s_addr)
	  || netmask == (netmask | arptable[ARP_CLIENT].ipaddr.s_addr)
	  || ! netmask)
	network_ready = 0;
      else
	network_ready = 1;
    }
  
  return 1;
}
예제 #4
0
파일: interface.c 프로젝트: Acidburn0zzz/mc
/****************************************************************************
load a list of network interfaces
****************************************************************************/
static void
interpret_interfaces (char *s, struct interface **interfaces, const char *description)
{
    char *ptr;
    fstring token;
    struct interface *iface;
    struct in_addr ip;

    ptr = s;
    ipzero = *interpret_addr2 ("0.0.0.0");
    allones_ip = *interpret_addr2 ("255.255.255.255");
    loopback_ip = *interpret_addr2 ("127.0.0.1");

    while (next_token (&ptr, token, NULL, sizeof (token)))
    {
        /* parse it into an IP address/netmasklength pair */
        char *p = strchr (token, '/');
        if (p)
            *p++ = 0;

        ip = *interpret_addr2 (token);

        /* maybe we already have it listed */
        {
            struct interface *i;
            for (i = (*interfaces); i; i = i->next)
                if (ip_equal (ip, i->ip))
                    break;
            if (i)
                continue;
        }

        iface = (struct interface *) malloc (sizeof (*iface));
        if (!iface)
            return;

        iface->ip = ip;

        if (p)
        {
            if (strlen (p) > 2)
                iface->nmask = *interpret_addr2 (p);
            else
                iface->nmask.s_addr = htonl (((ALLONES >> atoi (p)) ^ ALLONES));
        }
        else
        {
            default_netmask (&iface->nmask, &iface->ip);
        }
        iface->bcast.s_addr = MKBCADDR (iface->ip.s_addr, iface->nmask.s_addr);
        iface->next = NULL;

        if (!(*interfaces))
        {
            (*interfaces) = iface;
        }
        else
        {
            last_iface->next = iface;
        }
        last_iface = iface;
        DEBUG (2, ("Added %s ip=%s ", description, inet_ntoa (iface->ip)));
        DEBUG (2, ("bcast=%s ", inet_ntoa (iface->bcast)));
        DEBUG (2, ("nmask=%s\n", inet_ntoa (iface->nmask)));
    }