On Mon, Apr 11, 2011 at 07:10:52PM +0000, Herve Poussineau wrote: > From: Herv? Poussineau <hpous...@reactos.org> > > This option is described in RFC 1783. As this is only an optional field, > we may ignore it in some situations and handle it in some others. > Here, if client requests a block size bigger than the block size we emit > (512 bytes), accept the option with a value of 512 > > Signed-off-by: Herv? Poussineau <hpous...@reactos.org> > --- > slirp/tftp.c | 40 ++++++++++++++++++++++++++++++++-------- > 1 files changed, 32 insertions(+), 8 deletions(-)
The code looks fine except a small indentation issue below. However I don't really see the point of such a patch. This patch basically look for this option, but beside acking it, the behavior doesn't change. On the other hand servers are free to not support all the possible option, in which case they should simply ignore them (i.e. the current behavior). > diff --git a/slirp/tftp.c b/slirp/tftp.c > index 8055ccc..7ef44c9 100644 > --- a/slirp/tftp.c > +++ b/slirp/tftp.c > @@ -116,13 +116,13 @@ static int tftp_read_data(struct tftp_session *spt, > uint16_t block_nr, > } > > static int tftp_send_oack(struct tftp_session *spt, > - const char *key, uint32_t value, > + const char *key[], uint32_t value[], int nb, > struct tftp_t *recv_tp) > { > struct sockaddr_in saddr, daddr; > struct mbuf *m; > struct tftp_t *tp; > - int n = 0; > + int i, n = 0; > > m = m_get(spt->slirp); > > @@ -136,10 +136,12 @@ static int tftp_send_oack(struct tftp_session *spt, > m->m_data += sizeof(struct udpiphdr); > > tp->tp_op = htons(TFTP_OACK); > - n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", > - key) + 1; > - n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", > - value) + 1; > + for (i = 0; i < nb; i++) { > + n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%s", > + key[i]) + 1; > + n += snprintf(tp->x.tp_buf + n, sizeof(tp->x.tp_buf) - n, "%u", > + value[i]) + 1; > + } > > saddr.sin_addr = recv_tp->ip.ip_dst; > saddr.sin_port = recv_tp->udp.uh_dport; > @@ -260,6 +262,9 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t > *tp, int pktlen) > int s, k; > size_t prefix_len; > char *req_fname; > + const char *option_name[2]; > + uint32_t option_value[2]; > + int nb_options = 0; > > /* check if a session already exists and if so terminate it */ > s = tftp_session_find(slirp, tp); > @@ -364,9 +369,28 @@ static void tftp_handle_rrq(Slirp *slirp, struct tftp_t > *tp, int pktlen) > } > } > > - tftp_send_oack(spt, "tsize", tsize, tp); > - return; > + option_name[nb_options] = "tsize"; > + option_value[nb_options] = tsize; > + nb_options++; > } > + if (strcasecmp(key, "blksize") == 0) { > + int blksize = atoi(value); > + > + /* If blksize option is bigger than what we will > + * emit, accept the option with our packet size. > + * Otherwise, simply do as we didn't see the option. > + */ > + if (blksize >= 512) { > + option_name[nb_options] = "blksize"; > + option_value[nb_options] = 512; > + nb_options++; > + } > + } > + } > + I known slirp/tftp.c has weird indentation, but you should probably try to match the indentation from "tsize" for this black, that is 4 space like in QEMU, except for the initial indentation. > + if (nb_options > 0) { > + tftp_send_oack(spt, option_name, option_value, nb_options, tp); > + return; > } > > tftp_send_data(spt, 1, tp); > -- > 1.6.0.2.GIT > > > -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurel...@aurel32.net http://www.aurel32.net