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

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

?? tftpserver.c

?? 基于STM32F107的UDP服務器程序
?? C
?? 第 1 頁 / 共 2 頁
字號:
  if (!args)
  {
    /* unable to allocate memory for tftp args  */
    tftp_send_error_message(upcb, to, to_port, TFTP_ERR_NOTDEFINED);

    /* no need to use tftp_cleanup_rd because no 
            "tftp_connection_args" struct has been malloc'd   */
    tftp_cleanup_rd(upcb, args);

    return 0;
  }

  /* initialize connection structure  */
  args->op = TFTP_RRQ;	 //操作碼
  args->to_ip.addr = to->addr;	 //目的ip
  args->to_port = to_port;		 //to_port=0
  args->block = 1; //接收到讀請求時,塊號從1開始
  args->tot_bytes = 0;	 /* total number of bytes transferred */


  /* set callback for receives on this UDP PCB (Protocol Control Block) */
  udp_recv(upcb, rrq_recv_callback, args);	  //得到回復時調用rrq_recv_callback

  /* initiate the transaction by sending the first block of data
   * further blocks will be sent when ACKs are received
   *   - the receive callbacks need to get the proper state    */

  tftp_send_next_block(upcb, args, to, to_port);   //file_read要改

  return 1;
}

void wrq_recv_callback(void *_args, struct udp_pcb *upcb, struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port)
{
  tftp_connection_args *args = (tftp_connection_args *)_args;
  int n = 0;

  if (pkt_buf->len != pkt_buf->tot_len)		
  {
    return;
  }

  /* Does this packet have any valid data to write? */
  if ((pkt_buf->len > TFTP_DATA_PKT_HDR_LEN) &&
      (tftp_extract_block(pkt_buf->payload) == (args->block + 1)))
  {
    /* write the received data to the file */ //將文件內容寫入
    n = file_write(&file_CR,
                   pkt_buf->len - TFTP_DATA_PKT_HDR_LEN,
                   (euint8*)pkt_buf->payload + TFTP_DATA_PKT_HDR_LEN);

    if (n <= 0)
    {
      tftp_send_error_message(upcb, addr, port, TFTP_ERR_FILE_NOT_FOUND);
      /* close the connection */
      tftp_cleanup_wr(upcb, args); /* close the connection */
    }

    /* update our block number to match the block number just received */
    args->block++;
    /* update total bytes  */
    (args->tot_bytes) += (pkt_buf->len - TFTP_DATA_PKT_HDR_LEN);  //加上數據部分長度

    /* This is a valid pkt but it has no data.  This would occur if the file being
       written is an exact multiple of 512 bytes.  In this case, the args->block
       value must still be updated, but we can skip everything else.    */
  }
  else if (tftp_extract_block(pkt_buf->payload) == (args->block + 1))
  {
    /* update our block number to match the block number just received  */
    args->block++;
  }

  /* SEndTransferthe appropriate ACK pkt (the block number sent in the ACK pkt echoes
   * the block number of the DATA pkt we just received - see RFC1350)
   * NOTE!: If the DATA pkt we received did not have the appropriate block
   * number, then the args->block (our block number) is never updated and
   * we simply sEndTransfera "duplicate ACK" which has the same block number as the
   * last ACK pkt we sent.  This lets the host know that we are still waiting
   * on block number args->block+1. */
  tftp_send_ack_packet(upcb, addr, port, args->block);

  /* If the last write returned less than the maximum TFTP data pkt length,
   * then we've received the whole file and so we can quit (this is how TFTP
   * signals the EndTransferof a transfer!)
   */
  if (pkt_buf->len < TFTP_DATA_PKT_LEN_MAX)
  {
    tftp_cleanup_wr(upcb, args);
    pbuf_free(pkt_buf);
  }
  else
  {
    pbuf_free(pkt_buf);
    return;
  }

}

int tftp_process_write(struct udp_pcb *upcb, struct ip_addr *to, int to_port, char *FileName)
{
  tftp_connection_args *args = NULL;

  /* If Could not open the file which will be transmitted  */
  if (file_fopen(&file_CR, &efs2.myFs, FileName, 'w') != 0)
  {
    tftp_send_error_message(upcb, to, to_port, TFTP_ERR_FILE_ALREADY_EXISTS);

    tftp_cleanup_wr(upcb, args);

    return 0;
  }

  /* This function is called from a callback,
   * therefore interrupts are disabled,
   * therefore we can use regular malloc   */
  args = mem_malloc(sizeof *args);
  if (!args)
  {
    tftp_send_error_message(upcb, to, to_port, TFTP_ERR_NOTDEFINED);

    tftp_cleanup_wr(upcb, args);

    return 0;
  }

  args->op = TFTP_WRQ;
  args->to_ip.addr = to->addr;
  args->to_port = to_port;
  /* the block # used as a positive response to a WRQ is _always_ 0!!! (see RFC1350)  */
  args->block = 0;		   //接收到的是寫入請求時,包號為0
  args->tot_bytes = 0;

  /* set callback for receives on this UDP PCB (Protocol Control Block) */
  udp_recv(upcb, wrq_recv_callback, args);

  /* initiate the write transaction by sending the first ack */
  tftp_send_ack_packet(upcb, to, to_port, args->block);

  return 0;
}

/* for each new request (data in p->payload) from addr:port,
 * create a new port to serve the response, and start the response
 * process
 */
void process_tftp_request(struct pbuf *pkt_buf, struct ip_addr *addr, u16_t port)
{
  tftp_opcode op = tftp_decode_op(pkt_buf->payload);   //取出操作碼
  char FileName[30];
  struct udp_pcb *upcb;
  err_t err;
  u32_t IPaddress;
  u8_t iptxt[20];
  u8_t iptab[4];
  
  IPaddress = addr->addr;
  printf("\n\rTFTP RRQ (read request) from: %d.%d.%d.%d\n\r", (u8_t)(IPaddress),
            (u8_t)(IPaddress >> 8),(u8_t)(IPaddress >> 16),(u8_t)(IPaddress >> 24));
  
  /* read its IP address */
  iptab[0] = (u8_t)(IPaddress >> 24);
  iptab[1] = (u8_t)(IPaddress >> 16);
  iptab[2] = (u8_t)(IPaddress >> 8);
  iptab[3] = (u8_t)(IPaddress);

  sprintf((char*)iptxt, "TFTP: %d.%d.%d.%d   ", iptab[3], iptab[2], iptab[1], iptab[0]);	  
  LCD_DisplayStringLine(Line7, iptxt);
  
  /* create new UDP PCB structure */
  upcb = udp_new();
  if (!upcb)
  {     /* Error creating PCB. Out of Memory  */
    return;
  }

  /* bind to port 0 to receive next available free port */
  /* NOTE:  This is how TFTP works.  There is a UDP PCB for the standard port
   * 69 which al transactions begin communication on, however, _all_ subsequent
   * transactions for a given "stream" occur on another port!  */
  err = udp_bind(upcb, IP_ADDR_ANY, 0);
  if (err != ERR_OK)
  {    /* Unable to bind to port   */
    return;
  }


  switch (op)
  {

    case TFTP_RRQ:    /* TFTP RRQ (read request)  */
      /* Read the name of the file asked by the client 
                            to be sent from the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);  //提取文件名

      printf("\n\rTFTP RRQ (read request)");
      printf("\n\rONLY EFS filesystem(NTFS in WinXp) is support");
      
      /* If Could not open filesystem */
      if (efs_init(&efs1, 0) != 0)
      {
        printf("\n\rIf Could not open filesystem");
        return;
      }
      printf("\n\rCould open filesystem\n\r");
      /* If Could not open the selected directory */
      if (ls_openDir(&list1, &(efs1.myFs), "/") != 0)
      {
        printf("\n\rIf Could not open the selected directory");
        return;
      }
      /* Start the TFTP read mode*/	  //addr為接收方的IP地址 ,port=0
      printf("\n\rStart the TFTP read mode....");
      tftp_process_read(upcb, addr, port, FileName); //根據文件名讀取SD卡中的文件,并發送
      break;

    case TFTP_WRQ:    /* TFTP WRQ (write request)   */
      /* Read the name of the file asked by the client 
                to received and writen in the SD card */
      tftp_extract_filename(FileName, pkt_buf->payload);

      /* If Could not open filesystem */
      if (efs_init(&efs2, 0) != 0)
      {
        return;
      }
      /* If Could not open the selected directory */
      if (ls_openDir(&list2, &(efs2.myFs), "/") != 0)
      {
        return;
      }

      /* Start the TFTP write mode*/
      tftp_process_write(upcb, addr, port, FileName);
      break;

    default:
      /* sEndTransfera generic access violation message */
      tftp_send_error_message(upcb, addr, port, TFTP_ERR_ACCESS_VIOLATION);
      /* TFTP unknown request op */
      /* no need to use tftp_cleanup_wr because no 
            "tftp_connection_args" struct has been malloc'd   */
      udp_remove(upcb);

      break;
  }
}

/* the recv_callback function is called when there is a packet received
 * on the main tftp server port (69)
 */
void recv_callback_tftp(void *arg, struct udp_pcb *upcb, struct pbuf *pkt_buf,
                        struct ip_addr *addr, u16_t port)
{
  /* process new connection request */
  process_tftp_request(pkt_buf, addr, port);

  pbuf_free(pkt_buf);
}

void tftpd_init(void)
{
  err_t err;
  unsigned port = 69;

  /* create a new UDP PCB structure  */
  UDPpcb = udp_new();
  if (!UDPpcb)
  {  /* Error creating PCB. Out of Memory  */
    return;
  }

  /* Bind this PCB to port 69  */
  err = udp_bind(UDPpcb, IP_ADDR_ANY, port);
  if (err != ERR_OK)
  {    /* Unable to bind to port  */
    return;
  }

  /* TFTP server start  */	//啟動TFTP服務器
  udp_recv(UDPpcb, recv_callback_tftp, NULL); //通知協議棧當69端口有連接請求時調用recv_callback_tftp,
}		 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲码国产岛国毛片在线| 欧美一级日韩不卡播放免费| 久久国产精品99久久人人澡| 亚洲成av人片在线观看无码| 亚洲最大色网站| 亚洲一区免费在线观看| 亚洲午夜久久久久久久久久久| 亚洲天堂2016| 亚洲国产精品久久久久秋霞影院 | 亚洲精品亚洲人成人网在线播放| 国产精品传媒入口麻豆| 亚洲三级在线观看| 亚洲一区二区在线免费观看视频| 日韩二区三区在线观看| 精品系列免费在线观看| 成人精品国产福利| 欧洲激情一区二区| 精品国产乱码久久久久久浪潮| 久久免费电影网| 亚洲精品免费视频| 免费观看日韩电影| 成人久久18免费网站麻豆| 91色综合久久久久婷婷| 欧美精品第1页| 久久久久免费观看| 亚洲成人福利片| 国产在线国偷精品产拍免费yy| 成人av免费在线播放| 欧美精品日韩综合在线| 国产亚洲精品福利| 亚洲1区2区3区视频| 国产原创一区二区| 欧美日韩一卡二卡| 国产日韩欧美a| ...中文天堂在线一区| 日本va欧美va欧美va精品| 成a人片国产精品| 日韩欧美一区二区三区在线| 日本一区二区三区国色天香 | 亚洲成人三级小说| 丁香网亚洲国际| 欧美精品乱码久久久久久| 久久精品欧美日韩| 日韩av在线免费观看不卡| gogogo免费视频观看亚洲一| 91精品欧美久久久久久动漫 | 欧美少妇xxx| 国产三级精品在线| 男人的天堂久久精品| 99久免费精品视频在线观看| 精品久久久久久久久久久院品网| 亚洲视频一二三| 丁香亚洲综合激情啪啪综合| 日韩一区二区高清| 图片区小说区区亚洲影院| 91麻豆6部合集magnet| 国产亚洲成年网址在线观看| 日韩精品久久理论片| 色婷婷精品大在线视频| 国产精品日产欧美久久久久| 狠狠色丁香九九婷婷综合五月| 色天使色偷偷av一区二区| 26uuu国产一区二区三区| 日本不卡在线视频| 欧美日韩1234| 天涯成人国产亚洲精品一区av| 91免费小视频| 中文字幕一区二区三区在线不卡 | 欧美性感一区二区三区| 亚洲美女精品一区| 日本韩国视频一区二区| 亚洲欧美日韩国产手机在线| 不卡在线观看av| 亚洲欧洲日本在线| 懂色中文一区二区在线播放| 国产精品毛片高清在线完整版 | 欧美色成人综合| 亚洲电影欧美电影有声小说| 欧美日韩免费在线视频| 亚洲va国产天堂va久久en| 欧美日韩在线三级| 日本欧美在线看| 精品国产乱码久久久久久闺蜜 | 欧美色图一区二区三区| 亚洲一区二区三区影院| 欧美嫩在线观看| 麻豆视频观看网址久久| 国产女人18毛片水真多成人如厕 | 欧美极品xxx| 91美女蜜桃在线| 午夜精品一区二区三区三上悠亚| 欧美一区二区三区视频在线观看| 久久99日本精品| 国产精品久久免费看| 91久久精品一区二区三| 欧美aaaaa成人免费观看视频| 2024国产精品视频| 成年人午夜久久久| 日本麻豆一区二区三区视频| 久久久99精品免费观看| 在线免费观看不卡av| 久久99精品一区二区三区| 国产精品免费丝袜| 欧美一区二区三区视频免费播放| 国产在线精品不卡| 艳妇臀荡乳欲伦亚洲一区| www国产亚洲精品久久麻豆| 色婷婷综合久久久久中文| 开心九九激情九九欧美日韩精美视频电影 | 中文字幕日韩av资源站| 欧美巨大另类极品videosbest | 国产欧美综合在线观看第十页| 91影院在线免费观看| 日本亚洲欧美天堂免费| 亚洲欧洲精品成人久久奇米网| 欧美日本精品一区二区三区| 福利一区二区在线观看| 久久精品噜噜噜成人88aⅴ| 亚洲免费观看高清完整版在线观看| 欧美一区二区三区不卡| 91丨porny丨最新| 国产精一区二区三区| 天天色综合成人网| 一区二区三区在线免费| 欧美经典一区二区| 欧美成人艳星乳罩| 欧美久久一二三四区| 色一情一伦一子一伦一区| 国产成人综合在线播放| 五月综合激情婷婷六月色窝| 国产精品美女一区二区| 久久亚洲春色中文字幕久久久| 欧美日韩在线播放| 国产中文字幕一区| 亚洲天天做日日做天天谢日日欢| 欧美电影精品一区二区| 欧美日韩卡一卡二| 在线视频欧美区| 不卡av电影在线播放| 国产一区二区免费在线| 老司机精品视频导航| 欧美96一区二区免费视频| 日韩av不卡在线观看| 亚洲成人精品影院| 亚洲成人免费影院| 亚洲国产一区二区在线播放| 一区二区三区成人在线视频| 日韩美女啊v在线免费观看| 国产精品久久久久久久蜜臀| 欧美国产激情二区三区| 欧美激情一区二区三区蜜桃视频| 国产欧美日韩在线看| 国产精品欧美一区喷水| 自拍av一区二区三区| 亚洲猫色日本管| 亚洲永久精品国产| 亚洲国产精品视频| 日本vs亚洲vs韩国一区三区| 久久成人麻豆午夜电影| 国产精品综合av一区二区国产馆| 精品无码三级在线观看视频| 国产一区二区三区蝌蚪| 国v精品久久久网| 成人av综合在线| 91麻豆精品一区二区三区| 色综合天天在线| 欧美日韩精品电影| 欧美成人三级电影在线| 国产欧美日韩亚州综合| 亚洲男人的天堂在线aⅴ视频| 亚洲精品自拍动漫在线| 秋霞午夜av一区二区三区| 国产麻豆精品在线| 99亚偷拍自图区亚洲| 欧美日韩一级二级| 日韩精品综合一本久道在线视频| 国产日本欧美一区二区| 亚洲美女屁股眼交3| 男女视频一区二区| av高清久久久| 91精品久久久久久久99蜜桃 | 成人天堂资源www在线| 色中色一区二区| 欧美一区二视频| 中文字幕一区二区不卡| 视频在线观看91| 丁香六月久久综合狠狠色| 欧美中文字幕一区| 久久美女艺术照精彩视频福利播放| 中文字幕日本不卡| 免费成人在线观看| 91福利精品第一导航| 久久综合九色综合欧美亚洲| 亚洲一二三区视频在线观看| 国产69精品久久久久毛片| 9191精品国产综合久久久久久| 国产欧美日韩综合精品一区二区| 亚洲成人动漫在线免费观看| 成人免费高清视频在线观看| 欧美一区二区三区四区在线观看|