Network Socket Homework

CS 441 Homework, Dr. Lawlor

I've started a set of TCP network socket servers for you to communicate with.  These servers are all running on powerwall0.cs.uaf.edu, IP address 137.229.25.20, ports 6661 through 6669.  Sadly, the UAF firewall won't allow you to connect to these from outside the UAF network, so you may have to write your clients from inside NetRun.  Feel free to use my osl/socket.h library, or not (I use it, but then it's my library.)

For this homework, "int32" means a big-endian 32-bit integer, like my "Big32" class.

TCP Port
Purpose
Problem
Server protocol
6661
Basic test
None
Connect, and receive a "Hello!" string.  Terminated by exclamation point (or EOF).
6662
Newline string echo
441hw3.1
Send one newline-terminated string.  Receive the same string back again.
6663
Addition 441hw3.2 Send two int32 numbers, get back one int32 number, the sum.
6664
Counted string
441hw3.3
Send one int32 string length, then a string of that length.  Get back the string length (only, no data).
6665
Simple callback
441hw3.4
Create your own listening TCP port.
Send the server an int32 with your port number.
The server will connect on this port.  On this new connection, you then send the server a newline-terminated string, and the server will respond with the int32 length of the string you sent.
6666
Authenticated callback
441hw3.5
Create your own listening TCP port.
Send the server an int32 with your port number.
The server will connect on this port, and perform these steps: 
Authenticate:
        Server sends 0xBEEF as an int32.
        You send back 0xF00D as an int32.
        Server sends a challenge int32.
        You add 0xF00D to the challenge and send that int32 back.
Communicate:
        You send a newline-terminated string.  We store this string.
        Server sends back client's string, or an error message.
Close connection
6669
Log reader
(debugging)
None
Send two int32's: your student ID, and the server port you want the logs for.  Returns an int32 log length, and the logs from that server matching your ID.

The assignments are:
  1. Send a string containing your student ID to server 6662.
  2. Pick two integers that add up to your student ID, and send them to server 6663.
  3. Send a string containing your student ID formatted for server 6664.
  4. Get server 6665 to connect back to you, and send it a string containing your student ID.
  5. Get server 6666 to connect back to you, authenticate, and send it a string containing your student ID.
The "string containing your student ID" should be in ordinary ASCII decimal, but can be anywhere in the string, for example:

Turning in == Logs

There's nothing for you to turn in for this homework, instead I can see if you've done it by looking at the server logs.  You can extract this same data using server 6669, the log reader.  Here's an example 6669 client, runnable from NetRun:
#include "osl/socket.h"
#include "osl/socket.cpp"

int foo(void) {
skt_ip_t ip=skt_lookup_ip("137.229.25.20"); // powerwall0
int port=6669; // one demo server
int timeout=1; // seconds until timeout (usually 60)
SOCKET s=skt_connect(ip,port,timeout);
std::cout<<"Connected.\n";

// Send off my ID
Big32 id=36661313;
skt_sendN(s,&id,sizeof(id));

// Send off the requested server number
Big32 server=6669;
skt_sendN(s,&server,sizeof(server));

// Receive a string with all occurrences in the logfiles.
Big32 len=0;
skt_recvN(s,&len,sizeof(len));
unsigned int slen=len;
std::cout<<"Server is sending back "<<slen<<" bytes.\n";
if (slen>0 && slen<100000) {
std::string str(slen,'x');
skt_recvN(s,&str[0],slen);
std::cout<<"Back from server: \n"<<str<<"\n";
}
skt_close(s);

return 0;
}

(Try this in NetRun now!)

Of course, you need to use your own student ID and server number.  The 6669 server itself logs your request, so every time you run the above, you should see another entry with your ID and the date.

Debugging

Keeping servers up is hard, and it's likely at least one of these servers will find some creative new way to hang or crash.  If you can't even connect to one of the servers, please send me an email, and I will restart it!

If you discover an exploitable security hole (other than a denial of service) in one of the servers, I will pay you $20 to report it promptly.  Exploiting the hole without reporting it may result in academic, civil, criminal, and moral penalties.