static void tftp_send_next_block(struct tftp_session *spt,

                                 struct tftp_t *recv_tp)

{

  struct sockaddr_in saddr, daddr;

  struct mbuf *m;

  struct tftp_t *tp;

  int nobytes;



  m = m_get(spt->slirp);



  if (!m) {

    return;

  }



  memset(m->m_data, 0, m->m_size);



  m->m_data += IF_MAXLINKHDR;

  tp = (void *)m->m_data;

  m->m_data += sizeof(struct udpiphdr);



  tp->tp_op = htons(TFTP_DATA);

  tp->x.tp_data.tp_block_nr = htons((spt->block_nr + 1) & 0xffff);



  saddr.sin_addr = recv_tp->ip.ip_dst;

  saddr.sin_port = recv_tp->udp.uh_dport;



  daddr.sin_addr = spt->client_ip;

  daddr.sin_port = spt->client_port;



  nobytes = tftp_read_data(spt, spt->block_nr, tp->x.tp_data.tp_buf, 512);



  if (nobytes < 0) {

    m_free(m);



    /* send "file not found" error back */



    tftp_send_error(spt, 1, "File not found", tp);



    return;

  }



  m->m_len = sizeof(struct tftp_t) - (512 - nobytes) -

        sizeof(struct ip) - sizeof(struct udphdr);



  udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);



  if (nobytes == 512) {

    tftp_session_update(spt);

  }

  else {

    tftp_session_terminate(spt);

  }



  spt->block_nr++;

}

static void tftp_send_next_block(struct tftp_session *spt,

                                 struct tftp_t *recv_tp)

{

  struct sockaddr_in saddr, daddr;

  struct mbuf *m;

  struct tftp_t *tp;

  int nobytes;



  m = m_get(spt->slirp);



  if (!m) {

    return;

  }



  memset(m->m_data, 0, m->m_size);



  m->m_data += IF_MAXLINKHDR;

  tp = (void *)m->m_data;

  m->m_data += sizeof(struct udpiphdr);



  tp->tp_op = htons(TFTP_DATA);

  tp->x.tp_data.tp_block_nr = htons((spt->block_nr + 1) & 0xffff);



  saddr.sin_addr = recv_tp->ip.ip_dst;

  saddr.sin_port = recv_tp->udp.uh_dport;



  daddr.sin_addr = spt->client_ip;

  daddr.sin_port = spt->client_port;



  nobytes = tftp_read_data(spt, spt->block_nr, tp->x.tp_data.tp_buf, 512);



  if (nobytes < 0) {

    m_free(m);



    



    tftp_send_error(spt, 1, "File not found", tp);



    return;

  }



  m->m_len = sizeof(struct tftp_t) - (512 - nobytes) -

        sizeof(struct ip) - sizeof(struct udphdr);



  udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY);



  if (nobytes == 512) {

    tftp_session_update(spt);

  }

  else {

    tftp_session_terminate(spt);

  }



  spt->block_nr++;

}

static void FUNC_0(struct tftp_session *VAR_0,

                                 struct tftp_t *VAR_1)

{

  struct sockaddr_in VAR_2, VAR_3;

  struct mbuf *VAR_4;

  struct tftp_t *VAR_5;

  int VAR_6;



  VAR_4 = m_get(VAR_0->slirp);



  if (!VAR_4) {

    return;

  }



  memset(VAR_4->m_data, 0, VAR_4->m_size);



  VAR_4->m_data += IF_MAXLINKHDR;

  VAR_5 = (void *)VAR_4->m_data;

  VAR_4->m_data += sizeof(struct udpiphdr);



  VAR_5->tp_op = htons(TFTP_DATA);

  VAR_5->x.tp_data.tp_block_nr = htons((VAR_0->block_nr + 1) & 0xffff);



  VAR_2.sin_addr = VAR_1->ip.ip_dst;

  VAR_2.sin_port = VAR_1->udp.uh_dport;



  VAR_3.sin_addr = VAR_0->client_ip;

  VAR_3.sin_port = VAR_0->client_port;



  VAR_6 = tftp_read_data(VAR_0, VAR_0->block_nr, VAR_5->x.tp_data.tp_buf, 512);



  if (VAR_6 < 0) {

    m_free(VAR_4);



    



    tftp_send_error(VAR_0, 1, "File not found", VAR_5);



    return;

  }



  VAR_4->m_len = sizeof(struct tftp_t) - (512 - VAR_6) -

        sizeof(struct ip) - sizeof(struct udphdr);



  udp_output2(NULL, VAR_4, &VAR_2, &VAR_3, IPTOS_LOWDELAY);



  if (VAR_6 == 512) {

    tftp_session_update(VAR_0);

  }

  else {

    tftp_session_terminate(VAR_0);

  }



  VAR_0->block_nr++;

}

static void FUNC_0(struct tftp_session *VAR_0,
struct tftp_t *VAR_1)
{ struct sockaddr_in VAR_2, VAR_3; struct mbuf *VAR_4; struct tftp_t *VAR_5; int VAR_6; VAR_4 = m_get(VAR_0->slirp); if (!VAR_4) { return; } memset(VAR_4->m_data, 0, VAR_4->m_size); VAR_4->m_data += IF_MAXLINKHDR; VAR_5 = (void *)VAR_4->m_data; VAR_4->m_data += sizeof(struct udpiphdr); VAR_5->tp_op = htons(TFTP_DATA); VAR_5->x.tp_data.tp_block_nr = htons((VAR_0->block_nr + 1) & 0xffff); VAR_2.sin_addr = VAR_1->ip.ip_dst; VAR_2.sin_port = VAR_1->udp.uh_dport; VAR_3.sin_addr = VAR_0->client_ip; VAR_3.sin_port = VAR_0->client_port; VAR_6 = tftp_read_data(VAR_0, VAR_0->block_nr, VAR_5->x.tp_data.tp_buf, 512); if (VAR_6 < 0) { m_free(VAR_4); tftp_send_error(VAR_0, 1, "File not found", VAR_5); return; } VAR_4->m_len = sizeof(struct tftp_t) - (512 - VAR_6) -
sizeof(struct ip) - sizeof(struct udphdr); udp_output2(NULL, VAR_4, &VAR_2, &VAR_3, IPTOS_LOWDELAY); if (VAR_6 == 512) { tftp_session_update(VAR_0); } else { tftp_session_terminate(VAR_0); } VAR_0->block_nr++; }