⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zeroconf.c

📁 Intrisyc 公司的PXA255-bootloader,源码易懂
💻 C
字号:
//////////////////////////////////////////////////////////////////////////////////// Copyright(c) 2002 Intrinsyc Software Inc. All rights reserved.//// Module name:////      zeroconf.c//// Description:////      Handles Zeroconf IP address assignment (see http://www.zeroconf.org)//      (draft-ietf-zeroconf-ipv4-linklocal-xx.txt)//// Author:////      Dan Fandrich//// Created:////      September 2002//////////////////////////////////////////////////////////////////////////////////#include <string.h>#include <debug.h>#include <c_main.h>#include <util.h>#include <ip.h>#include <arp.h>#include <timer.h>#include <zeroconf.h>////////////////////////////////////////////////////////////////////////////////// init_zeroconf// PURPOSE: Handles the Zeroconf protocol to obtain the board's IP address// PARAMS:  (IN) u32 *ciaddr - Client IP address returned.//          (IN) u32 *siaddr - TFTP or other server address.//          (IN) u32 *giaddr - gateway address.//          (IN) u32 *smask  - IP netmask//          (IN) int *ttl  - IP TTL// RETURNS: 1 for success, 0 for failure. Some parameters are changed//          on failure.// NOTES:   The pointers must point to the actual structures used by the//          network stack.////////////////////////////////////////////////////////////////////////////////intinit_zeroconf(u32 * ciaddr, u32 * siaddr, u32 * giaddr, u32 * smask, int *ttl){    u32 ip;    u16 mac[3];    int retries = 0;    *ciaddr = 0;                // We must start with a zero address    *giaddr = 0;                // Zeroconf networking is unrouted    *smask = 0;                 // Zeroconf networking is unrouted    *ttl = ZEROCONF_TTL;    // Delay a short random amount to space out Zeroconf requests from    // many clients booting up at once.    udelay(rand() % 100000);    udelay(rand() % 100000);    // Initial PRNG to a consistent value, unique to this device    srand((status.macaddr[2] << 16) | status.macaddr[1]);    // Do ARP Probes until we find a free one    while (1)    {        do        {            if (++retries > ZEROCONF_RETRIES)            {                itc_printf("Couldn't obtain an address\r\n");                ip = 0;                break;            }            // Loop until we generate a valid address            do            {                ip = ZEROCONF_NET | (rand() & 0xffff);            } while (ip < ZEROCONF_IP_RANGE_MIN || ip > ZEROCONF_IP_RANGE_MAX);            itc_printf(".");            DEBUG_2("Trying IP %s\r\n", iptoa(ip));        } while (arp(ip, mac));        // Plug our IP address into the network stack        *ciaddr = ip;        DEBUG_2("Announcing our IP\r\n");        // Do ARP Announcements & ensure that our address is still free        if (ip && !arp(ip, mac))        {            // We have our address!            break;        }        ip = 0;        *ciaddr = ip;    }    // Reseed the random number generator with more entropy for other callers    srand(get_time_timer() ^ ((status.macaddr[2] << 16) | status.macaddr[1]));    return !!ip;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -