亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dhcp.c

?? ARM7的一些試驗程序
?? C
?? 第 1 頁 / 共 4 頁
字號:
/**
 * @file
 *
 * Dynamic Host Configuration Protocol client
 */

/*
 *
 * Copyright (c) 2001-2004 Leon Woestenberg <leon.woestenberg@gmx.net>
 * Copyright (c) 2001-2004 Axon Digital Design B.V., The Netherlands.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * This file is a contribution to the lwIP TCP/IP stack.
 * The Swedish Institute of Computer Science and Adam Dunkels
 * are specifically granted permission to redistribute this
 * source code.
 *
 * Author: Leon Woestenberg <leon.woestenberg@gmx.net>
 *
 * This is a DHCP client for the lwIP TCP/IP stack. It aims to conform
 * with RFC 2131 and RFC 2132.
 *
 * TODO:
 * - Proper parsing of DHCP messages exploiting file/sname field overloading.
 * - Add JavaDoc style documentation (API, internals).
 * - Support for interfaces other than Ethernet (SLIP, PPP, ...)
 *
 * Please coordinate changes and requests with Leon Woestenberg
 * <leon.woestenberg@gmx.net>
 *
 * Integration with your code:
 *
 * In lwip/dhcp.h
 * #define DHCP_COARSE_TIMER_SECS (recommended 60 which is a minute)
 * #define DHCP_FINE_TIMER_MSECS (recommended 500 which equals TCP coarse timer)
 *
 * Then have your application call dhcp_coarse_tmr() and
 * dhcp_fine_tmr() on the defined intervals.
 *
 * dhcp_start(struct netif *netif);
 * starts a DHCP client instance which configures the interface by
 * obtaining an IP address lease and maintaining it.
 *
 * Use dhcp_release(netif) to end the lease and use dhcp_stop(netif)
 * to remove the DHCP client.
 *
 */
 
#include <string.h>
 
#include "lwip/stats.h"
#include "lwip/mem.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/inet.h"
#include "netif/etharp.h"

#include "lwip/sys.h"
#include "lwip/opt.h"
#include "lwip/dhcp.h"

#if LWIP_DHCP /* don't build if not configured for use in lwipopt.h */

/** global transaction identifier, must be
 *  unique for each DHCP request. We simply increment, starting
 *  with this value (easy to match with a packet analyzer) */
static u32_t xid = 0xABCD0000;

/** DHCP client state machine functions */
static void dhcp_handle_ack(struct netif *netif);
static void dhcp_handle_nak(struct netif *netif);
static void dhcp_handle_offer(struct netif *netif);

static err_t dhcp_discover(struct netif *netif);
static err_t dhcp_select(struct netif *netif);
static void dhcp_check(struct netif *netif);
static void dhcp_bind(struct netif *netif);
static err_t dhcp_decline(struct netif *netif);
static err_t dhcp_rebind(struct netif *netif);
static void dhcp_set_state(struct dhcp *dhcp, unsigned char new_state);

/** receive, unfold, parse and free incoming messages */
static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port);
static err_t dhcp_unfold_reply(struct dhcp *dhcp);
static u8_t *dhcp_get_option_ptr(struct dhcp *dhcp, u8_t option_type);
static u8_t dhcp_get_option_byte(u8_t *ptr);
static u16_t dhcp_get_option_short(u8_t *ptr);
static u32_t dhcp_get_option_long(u8_t *ptr);
static void dhcp_free_reply(struct dhcp *dhcp);

/** set the DHCP timers */
static void dhcp_timeout(struct netif *netif);
static void dhcp_t1_timeout(struct netif *netif);
static void dhcp_t2_timeout(struct netif *netif);

/** build outgoing messages */
/** create a DHCP request, fill in common headers */
static err_t dhcp_create_request(struct netif *netif);
/** free a DHCP request */
static void dhcp_delete_request(struct netif *netif);
/** add a DHCP option (type, then length in bytes) */
static void dhcp_option(struct dhcp *dhcp, u8_t option_type, u8_t option_len);
/** add option values */
static void dhcp_option_byte(struct dhcp *dhcp, u8_t value);
static void dhcp_option_short(struct dhcp *dhcp, u16_t value);
static void dhcp_option_long(struct dhcp *dhcp, u32_t value);
/** always add the DHCP options trailer to end and pad */
static void dhcp_option_trailer(struct dhcp *dhcp);

/**
 * Back-off the DHCP client (because of a received NAK response).
 *
 * Back-off the DHCP client because of a received NAK. Receiving a
 * NAK means the client asked for something non-sensible, for
 * example when it tries to renew a lease obtained on another network.
 *
 * We back-off and will end up restarting a fresh DHCP negotiation later.
 *
 * @param state pointer to DHCP state structure
 */
static void dhcp_handle_nak(struct netif *netif) {
  struct dhcp *dhcp = netif->dhcp;
  u16_t msecs = 10 * 1000;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_handle_nak(netif=%p) %c%c%u\n", netif,
    netif->name[0], netif->name[1], (unsigned int)netif->num));
  dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_handle_nak(): set request timeout %u msecs\n", msecs));
  dhcp_set_state(dhcp, DHCP_BACKING_OFF);
}

/**
 * Checks if the offered IP address is already in use.
 *
 * It does so by sending an ARP request for the offered address and
 * entering CHECKING state. If no ARP reply is received within a small
 * interval, the address is assumed to be free for use by us.
 */
static void dhcp_check(struct netif *netif)
{
  struct dhcp *dhcp = netif->dhcp;
  err_t result;
  u16_t msecs;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (unsigned int)netif->name[0],
    (unsigned int)netif->name[1]));
  /* create an ARP query for the offered IP address, expecting that no host
     responds, as the IP address should not be in use. */
  result = etharp_query(netif, &dhcp->offered_ip_addr, NULL);
  if (result != ERR_OK) {
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_check: could not perform ARP query\n"));
  }
  dhcp->tries++;
  msecs = 500;
  dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_check(): set request timeout %u msecs\n", msecs));
  dhcp_set_state(dhcp, DHCP_CHECKING);
}

/**
 * Remember the configuration offered by a DHCP server.
 *
 * @param state pointer to DHCP state structure
 */
static void dhcp_handle_offer(struct netif *netif)
{
  struct dhcp *dhcp = netif->dhcp;
  /* obtain the server address */
  u8_t *option_ptr = dhcp_get_option_ptr(dhcp, DHCP_OPTION_SERVER_ID);
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_handle_offer(netif=%p) %c%c%u\n", netif,
    netif->name[0], netif->name[1], netif->num));
  if (option_ptr != NULL)
  {
    dhcp->server_ip_addr.addr = htonl(dhcp_get_option_long(&option_ptr[2]));
    LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): server 0x%08lx\n", dhcp->server_ip_addr.addr));
    /* remember offered address */
    ip_addr_set(&dhcp->offered_ip_addr, (struct ip_addr *)&dhcp->msg_in->yiaddr);
    LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08lx\n", dhcp->offered_ip_addr.addr));

    dhcp_select(netif);
  }
}

/**
 * Select a DHCP server offer out of all offers.
 *
 * Simply select the first offer received.
 *
 * @param netif the netif under DHCP control
 * @return lwIP specific error (see error.h)
 */
static err_t dhcp_select(struct netif *netif)
{
  struct dhcp *dhcp = netif->dhcp;
  err_t result;
  u32_t msecs;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_select(netif=%p) %c%c%u\n", netif, netif->name[0], netif->name[1], netif->num));

  /* create and initialize the DHCP message header */
  result = dhcp_create_request(netif);
  if (result == ERR_OK)
  {
    dhcp_option(dhcp, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
    dhcp_option_byte(dhcp, DHCP_REQUEST);

    dhcp_option(dhcp, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
    dhcp_option_short(dhcp, 576);

    /* MUST request the offered IP address */
    dhcp_option(dhcp, DHCP_OPTION_REQUESTED_IP, 4);
    dhcp_option_long(dhcp, ntohl(dhcp->offered_ip_addr.addr));

    dhcp_option(dhcp, DHCP_OPTION_SERVER_ID, 4);
    dhcp_option_long(dhcp, ntohl(dhcp->server_ip_addr.addr));

    dhcp_option(dhcp, DHCP_OPTION_PARAMETER_REQUEST_LIST, 4/*num options*/);
    dhcp_option_byte(dhcp, DHCP_OPTION_SUBNET_MASK);
    dhcp_option_byte(dhcp, DHCP_OPTION_ROUTER);
    dhcp_option_byte(dhcp, DHCP_OPTION_BROADCAST);
    dhcp_option_byte(dhcp, DHCP_OPTION_DNS_SERVER);

    dhcp_option_trailer(dhcp);
    /* shrink the pbuf to the actual content length */
    pbuf_realloc(dhcp->p_out, sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + dhcp->options_out_len);

    /* TODO: we really should bind to a specific local interface here
       but we cannot specify an unconfigured netif as it is addressless */
    udp_bind(dhcp->pcb, IP_ADDR_ANY, DHCP_CLIENT_PORT);
    /* send broadcast to any DHCP server */
    udp_connect(dhcp->pcb, IP_ADDR_BROADCAST, DHCP_SERVER_PORT);
    udp_send(dhcp->pcb, dhcp->p_out);
    /* reconnect to any (or to server here?!) */
    udp_connect(dhcp->pcb, IP_ADDR_ANY, DHCP_SERVER_PORT);
    dhcp_delete_request(netif);
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_select: REQUESTING\n"));
    dhcp_set_state(dhcp, DHCP_REQUESTING);
  } else {
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 2, ("dhcp_select: could not allocate DHCP request\n"));
  }
  dhcp->tries++;
  msecs = dhcp->tries < 4 ? dhcp->tries * 1000 : 4 * 1000;
  dhcp->request_timeout = (msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_STATE, ("dhcp_select(): set request timeout %u msecs\n", msecs));
  return result;
}

/**
 * The DHCP timer that checks for lease renewal/rebind timeouts.
 *
 */
void dhcp_coarse_tmr()
{
  struct netif *netif = netif_list;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_coarse_tmr()\n"));
  /* iterate through all network interfaces */
  while (netif != NULL) {
    /* only act on DHCP configured interfaces */
    if (netif->dhcp != NULL) {
      /* timer is active (non zero), and triggers (zeroes) now? */
      if (netif->dhcp->t2_timeout-- == 1) {
        LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout\n"));
        /* this clients' rebind timeout triggered */
        dhcp_t2_timeout(netif);
      /* timer is active (non zero), and triggers (zeroes) now */
      } else if (netif->dhcp->t1_timeout-- == 1) {
        LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout\n"));
        /* this clients' renewal timeout triggered */
        dhcp_t1_timeout(netif);
      }
    }
    /* proceed to next netif */
    netif = netif->next;
  }
}

/**
 * DHCP transaction timeout handling
 *
 * A DHCP server is expected to respond within a short period of time.
 * This timer checks whether an outstanding DHCP request is timed out.
 * 
 */
void dhcp_fine_tmr()
{
  struct netif *netif = netif_list;
  /* loop through netif's */
  while (netif != NULL) {
    /* only act on DHCP configured interfaces */
    if (netif->dhcp != NULL) {
      /* timer is active (non zero), and is about to trigger now */
      if (netif->dhcp->request_timeout-- == 1) {
        /* { netif->dhcp->request_timeout == 0 } */
        LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_fine_tmr(): request timeout\n"));
        /* this clients' request timeout triggered */
        dhcp_timeout(netif);
      }
    }
    /* proceed to next network interface */
    netif = netif->next;
  }
}

/**
 * A DHCP negotiation transaction, or ARP request, has timed out.
 *
 * The timer that was started with the DHCP or ARP request has
 * timed out, indicating no response was received in time.
 *
 * @param netif the netif under DHCP control
 *
 */
static void dhcp_timeout(struct netif *netif)
{
  struct dhcp *dhcp = netif->dhcp;
  LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | 3, ("dhcp_timeout()\n"));
  /* back-off period has passed, or server selection timed out */
  if ((dhcp->state == DHCP_BACKING_OFF) || (dhcp->state == DHCP_SELECTING)) {
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE, ("dhcp_timeout(): restarting discovery\n"));
    dhcp_discover(netif);
  /* receiving the requested lease timed out */
  } else if (dhcp->state == DHCP_REQUESTING) {
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out\n"));
    if (dhcp->tries <= 5) {
      dhcp_select(netif);
    } else {
      LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
      dhcp_release(netif);
      dhcp_discover(netif);
    }
  /* received no ARP reply for the offered address (which is good) */
  } else if (dhcp->state == DHCP_CHECKING) {
    LWIP_DEBUGF(DHCP_DEBUG | DBG_TRACE | DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out\n"));
    if (dhcp->tries <= 1) {
      dhcp_check(netif);
    /* no ARP replies on the offered address,
       looks like the IP address is indeed free */
    } else {
      /* bind the interface to the offered address */
      dhcp_bind(netif);
    }
  }
  /* did not get response to renew request? */
  else if (dhcp->state == DHCP_RENEWING) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一区和二区| 亚洲天堂2014| 日韩理论片中文av| 麻豆精品一二三| 色美美综合视频| 国产香蕉久久精品综合网| 亚洲高清免费观看高清完整版在线观看 | 成人听书哪个软件好| 欧美少妇一区二区| 亚洲色图清纯唯美| 国产aⅴ综合色| 精品处破学生在线二十三| 午夜av一区二区三区| 色综合久久中文字幕| 欧美—级在线免费片| 国产一区在线看| 日韩女同互慰一区二区| 五月婷婷欧美视频| 欧美日韩一区二区电影| 亚洲色图.com| 91视频免费观看| 国产精品成人免费精品自在线观看 | 91精品国产手机| 亚洲综合一区二区| 99久久精品国产导航| 国产欧美日韩不卡免费| 国产成人av电影在线| 久久久99精品免费观看| 国产在线视频一区二区| 欧美一区二区免费观在线| 婷婷成人激情在线网| 欧美久久免费观看| 日本不卡视频在线| 日韩免费观看高清完整版| 免费在线观看精品| 欧美xxxx在线观看| 国产精品99久久不卡二区| 国产女主播视频一区二区| 国产成人av电影| 中文字幕一区二区三区不卡在线 | 精品一区二区三区欧美| 日韩欧美精品三级| 国产夫妻精品视频| 中文字幕欧美一| 色琪琪一区二区三区亚洲区| 亚洲自拍都市欧美小说| 欧美妇女性影城| 久久99热99| 日本一区二区三区电影| 色综合久久综合网欧美综合网| 亚洲激情在线播放| 欧美一区国产二区| 国产成人av一区二区三区在线| 国产精品麻豆久久久| 91福利小视频| 日本aⅴ精品一区二区三区| 久久蜜臀精品av| 99精品久久久久久| 日韩成人午夜精品| 国产精品视频线看| 欧美手机在线视频| 国产乱理伦片在线观看夜一区| 中文字幕一区在线观看视频| 欧美日韩国产综合视频在线观看| 久久精品99国产精品| 亚洲欧洲精品一区二区精品久久久 | 成人av电影在线观看| 亚洲与欧洲av电影| 久久午夜电影网| 欧美制服丝袜第一页| 精品在线播放午夜| 一区二区三区国产精品| 欧美精品一区二| 欧美亚洲愉拍一区二区| 国产一区视频网站| 香蕉久久一区二区不卡无毒影院 | 亚洲欧洲韩国日本视频| 欧美日韩不卡视频| 99久久婷婷国产精品综合| 男人的天堂亚洲一区| 亚洲精品伦理在线| 欧美激情一区三区| 欧美大胆人体bbbb| 欧美日韩成人综合| 色婷婷av一区二区| www.亚洲人| 国产一区二区三区蝌蚪| 爽好久久久欧美精品| 18欧美乱大交hd1984| 26uuu亚洲综合色| 91麻豆精品国产91久久久久 | 综合电影一区二区三区| ww久久中文字幕| 欧美一区二区三区公司| 色狠狠av一区二区三区| 成人免费高清在线观看| 精品一区二区三区欧美| 日本不卡视频在线观看| 婷婷激情综合网| 亚洲午夜影视影院在线观看| 亚洲欧美自拍偷拍| 国产精品理论在线观看| 久久这里只有精品视频网| 555www色欧美视频| 717成人午夜免费福利电影| 日本道免费精品一区二区三区| www.亚洲色图| 91丝袜高跟美女视频| 99久久综合国产精品| 99精品国产一区二区三区不卡| 懂色av一区二区三区免费看| 狠狠色伊人亚洲综合成人| 欧美aaaaaa午夜精品| 蜜桃视频一区二区三区 | 日韩精品电影一区亚洲| 亚洲午夜在线视频| 五月激情综合色| 香蕉成人伊视频在线观看| 亚洲午夜久久久久中文字幕久| 一区二区三区鲁丝不卡| 夜夜嗨av一区二区三区四季av| 亚洲精品成人天堂一二三| 依依成人综合视频| 天堂av在线一区| 捆绑紧缚一区二区三区视频| 久久激情五月激情| 国产精品一区二区在线播放 | 美脚の诱脚舐め脚责91| 麻豆精品一二三| 国产成人在线免费观看| 播五月开心婷婷综合| 色吧成人激情小说| 欧美精品99久久久**| 日韩午夜激情av| 2022国产精品视频| 国产精品久久久久aaaa| 亚洲激情男女视频| 视频一区中文字幕| 狠狠色丁香婷综合久久| av综合在线播放| 欧美精品久久99久久在免费线| 日韩午夜精品视频| 国产精品成人一区二区艾草 | 伊人色综合久久天天人手人婷| 亚洲影院理伦片| 久久国产综合精品| 99视频精品全部免费在线| 欧美军同video69gay| 久久久久99精品一区| 亚洲主播在线播放| 国产精品一区二区视频| 色视频成人在线观看免| 久久一二三国产| 亚洲一区二区三区精品在线| 麻豆精品一区二区三区| 91一区一区三区| 制服丝袜国产精品| 中文字幕制服丝袜一区二区三区 | 欧美电视剧免费观看| 亚洲图片激情小说| 久久er99精品| 欧美三级电影在线观看| 久久久www成人免费毛片麻豆| 亚洲影视资源网| 东方欧美亚洲色图在线| 日韩欧美在线网站| 玉米视频成人免费看| 国产91在线|亚洲| 日韩一区二区三区在线| 亚洲免费av高清| 国产成人久久精品77777最新版本| 欧美日韩大陆在线| 国产精品成人一区二区艾草 | 色哟哟一区二区三区| 国产欧美日韩三级| 精品一区二区久久| 欧美精品久久一区二区三区| 亚洲人妖av一区二区| 国产黄色91视频| 久久人人爽人人爽| 捆绑变态av一区二区三区| 欧美日韩一区小说| 亚洲激情五月婷婷| 91首页免费视频| 国产精品久久久久桃色tv| 国产寡妇亲子伦一区二区| 日韩一区二区三区四区五区六区| 一区二区三区四区在线免费观看| 懂色中文一区二区在线播放| 久久久精品免费网站| 久久99久久久久久久久久久| 51精品国自产在线| 五月综合激情网| 欧美日韩免费视频| 亚洲国产婷婷综合在线精品| 91国偷自产一区二区使用方法| 中文字幕一区日韩精品欧美| 99精品视频中文字幕| 国产精品理论片在线观看| 99久久婷婷国产|