summaryrefslogtreecommitdiff
path: root/nuttx/netutils/tftpc/tftpc_packets.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/netutils/tftpc/tftpc_packets.c')
-rw-r--r--nuttx/netutils/tftpc/tftpc_packets.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/nuttx/netutils/tftpc/tftpc_packets.c b/nuttx/netutils/tftpc/tftpc_packets.c
index 0e606da69..73e4bd110 100644
--- a/nuttx/netutils/tftpc/tftpc_packets.c
+++ b/nuttx/netutils/tftpc/tftpc_packets.c
@@ -241,6 +241,12 @@ ssize_t tftp_recvfrom(int sd, void *buf, size_t len, struct sockaddr_in *from)
for (;;)
{
+ /* For debugging, it is helpful to start with a clean buffer */
+
+#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_NET)
+ memset(buf, 0, len);
+#endif
+
/* Receive the packet */
addrlen = sizeof(struct sockaddr_in);
@@ -320,4 +326,52 @@ ssize_t tftp_sendto(int sd, const void *buf, size_t len, struct sockaddr_in *to)
}
}
+/****************************************************************************
+ * Name: tftp_sendto
+ *
+ * Description:
+ * Dump a buffer of data
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NETUTILS_TFTP_DUMPBUFFERS
+void tftp_dumpbuffer(const char *msg, ubyte *buffer, int nbytes)
+{
+#ifdef CONFIG_DEBUG
+ char line[128];
+ int ch;
+ int i;
+ int j;
+
+ dbg("%s:\n", msg);
+ for (i = 0; i < nbytes; i += 16)
+ {
+ sprintf(line, "%04x: ", i);
+
+ for ( j = 0; j < 16; j++)
+ {
+ if (i + j < nbytes)
+ {
+ sprintf(&line[strlen(line)], "%02x ", buffer[i+j] );
+ }
+ else
+ {
+ strcpy(&line[strlen(line)], " ");
+ }
+ }
+
+ for ( j = 0; j < 16; j++)
+ {
+ if (i + j < nbytes)
+ {
+ ch = buffer[i+j];
+ sprintf(&line[strlen(line)], "%c", ch >= 0x20 && ch <= 0x7e ? ch : '.');
+ }
+ }
+ dbg("%s\n", line);
+ }
+#endif
+}
+#endif
+
#endif /* CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS */