<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://xinu.cs.mu.edu/index.php?action=history&amp;feed=atom&amp;title=TCP_Echo_Test</id>
	<title>TCP Echo Test - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://xinu.cs.mu.edu/index.php?action=history&amp;feed=atom&amp;title=TCP_Echo_Test"/>
	<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=TCP_Echo_Test&amp;action=history"/>
	<updated>2026-06-15T16:34:33Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>https://xinu.cs.mu.edu/index.php?title=TCP_Echo_Test&amp;diff=3850&amp;oldid=prev</id>
		<title>Jcowdy at 21:22, 16 June 2011</title>
		<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=TCP_Echo_Test&amp;diff=3850&amp;oldid=prev"/>
		<updated>2011-06-16T21:22:45Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 21:22, 16 June 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l12&quot; &gt;Line 12:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 12:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;**eg: echoclient 192.168.6.102 &amp;quot;Hello XINU World!&amp;quot;  &lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;**eg: echoclient 192.168.6.102 &amp;quot;Hello XINU World!&amp;quot;  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;echotest&lt;/del&gt;.c ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;xsh_echotest&lt;/ins&gt;.c ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;nowiki&amp;gt;#include &amp;lt;stddef.h&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;  &amp;lt;nowiki&amp;gt;#include &amp;lt;stddef.h&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l70&quot; &gt;Line 70:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 70:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     if (SYSERR == open(dev, localhost, &amp;amp;dst, NULL, ECHO_PORT, TCP_ACTIVE))&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     if (SYSERR == open(dev, localhost, &amp;amp;dst, NULL, ECHO_PORT, TCP_ACTIVE))&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     {&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     {&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         fprintf(stderr, &amp;quot;Client: Could not open the &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;UDP &lt;/del&gt;device\r\n&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         fprintf(stderr, &amp;quot;Client: Could not open the &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;TCP &lt;/ins&gt;device\r\n&amp;quot;);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         return SYSERR;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;         return SYSERR;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     }&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     }&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l94&quot; &gt;Line 94:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 94:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     return 0;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;     return 0;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot;&gt; &lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;}&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/nowiki&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/nowiki&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Jcowdy</name></author>
		
	</entry>
	<entry>
		<id>https://xinu.cs.mu.edu/index.php?title=TCP_Echo_Test&amp;diff=3833&amp;oldid=prev</id>
		<title>Jcowdy: Created page with '== About == This is a simple TCP usage example. It is an echo test client that sends a message to the echo server and then prints out the reply. The echo protocol is defined in R...'</title>
		<link rel="alternate" type="text/html" href="https://xinu.cs.mu.edu/index.php?title=TCP_Echo_Test&amp;diff=3833&amp;oldid=prev"/>
		<updated>2011-06-10T19:50:30Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;== About == This is a simple TCP usage example. It is an echo test client that sends a message to the echo server and then prints out the reply. The echo protocol is defined in R...&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== About ==&lt;br /&gt;
This is a simple TCP usage example. It is an echo test client that sends a message to the echo server and then prints out the reply.&lt;br /&gt;
The echo protocol is defined in RFC 862. In short, we send a message to the server, and the server echos the exact same message back.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
* Add the the to the shell directory as xsh_echotest.c&lt;br /&gt;
* Modify shell.c and shell.h to include the echotest command.&lt;br /&gt;
* Modify the Makefile in the shell directory to include xsh_echotest.c and then make XINU from the compile directory&lt;br /&gt;
* Boot XINU&lt;br /&gt;
* Run netup command from the shell&lt;br /&gt;
* Run echoclient from the shell with the arguments of the echoserver's ip and the message to be sent in quotes&lt;br /&gt;
**eg: echoclient 192.168.6.102 &amp;quot;Hello XINU World!&amp;quot; &lt;br /&gt;
&lt;br /&gt;
== echotest.c ==&lt;br /&gt;
 &amp;lt;nowiki&amp;gt;#include &amp;lt;stddef.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;device.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ether.h&amp;gt;&lt;br /&gt;
#include &amp;lt;tcp.h&amp;gt;&lt;br /&gt;
#include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define MSG_MAX_LEN 64&lt;br /&gt;
#define ECHO_PORT 7&lt;br /&gt;
&lt;br /&gt;
/**&lt;br /&gt;
 * Shell command (echotest) sends a message to an echo server per RFC 862.&lt;br /&gt;
 * It waits for a response, then prints out the reply from the echo server.&lt;br /&gt;
 * Expects args: echotest, echo server ip, Message to echo in quotes&lt;br /&gt;
 * @param nargs number of arguments in args array&lt;br /&gt;
 * @param args  array of arguments&lt;br /&gt;
 * @return non-zero value on error&lt;br /&gt;
 */&lt;br /&gt;
shellcmd xsh_echotest(int nargs, char *args[])&lt;br /&gt;
{&lt;br /&gt;
    ushort dev = 0;&lt;br /&gt;
    char buf[MSG_MAX_LEN];&lt;br /&gt;
&lt;br /&gt;
    char *dest = args[1];&lt;br /&gt;
&lt;br /&gt;
    struct netaddr dst;&lt;br /&gt;
    struct netaddr *localhost;&lt;br /&gt;
    struct netif *interface;&lt;br /&gt;
&lt;br /&gt;
    int len;&lt;br /&gt;
&lt;br /&gt;
    /* Allocate a new TCP device */&lt;br /&gt;
    if ((ushort)SYSERR == (dev = tcpAlloc()))&lt;br /&gt;
    {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Client: Failed to allocate a TCP device.&amp;quot;);&lt;br /&gt;
        return SYSERR;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* Look up local ip info */&lt;br /&gt;
    interface = netLookup((ethertab[0].dev)-&amp;gt;num);&lt;br /&gt;
    if (NULL == interface)&lt;br /&gt;
    {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Client: No network interface found\r\n&amp;quot;);&lt;br /&gt;
        return SYSERR;&lt;br /&gt;
    }&lt;br /&gt;
    localhost = &amp;amp;(interface-&amp;gt;ip);&lt;br /&gt;
&lt;br /&gt;
    /* Change the destination to ipv4 */&lt;br /&gt;
    if (SYSERR == dot2ipv4(dest, &amp;amp;dst))&lt;br /&gt;
    {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Client: Failed to convert ip address.&amp;quot;);&lt;br /&gt;
        return SYSERR;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* Open the TCP device with the destination and echo port*/&lt;br /&gt;
    if (SYSERR == open(dev, localhost, &amp;amp;dst, NULL, ECHO_PORT, TCP_ACTIVE))&lt;br /&gt;
    {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Client: Could not open the UDP device\r\n&amp;quot;);&lt;br /&gt;
        return SYSERR;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* Send the message to the destination*/&lt;br /&gt;
    memcpy(buf, args[2], MSG_MAX_LEN);&lt;br /&gt;
&lt;br /&gt;
    if(SYSERR == write(dev, buf, MSG_MAX_LEN))&lt;br /&gt;
    {&lt;br /&gt;
        fprintf(stderr, &amp;quot;Client: Error writing packet to the network&amp;quot;);&lt;br /&gt;
        close(dev);&lt;br /&gt;
        return SYSERR;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* Read a response from the server */&lt;br /&gt;
    if(SYSERR != (len = read(dev, buf, MSG_MAX_LEN)))&lt;br /&gt;
    {&lt;br /&gt;
        printf(&amp;quot;Client: Got response - %s\r\n&amp;quot;, buf);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    /* Close the device when done */&lt;br /&gt;
    close(dev);&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
&amp;lt;/nowiki&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jcowdy</name></author>
		
	</entry>
</feed>