慶應義塾大学
2007年度 秋学期
ネットワーク・プログラミング(C言語)
Network Programming in C
第9回 12月11日
Lecture 9, December 11: Getting Caught Up 2
Outline of This Lecture
- Where You Ought to Be
-
- Question and Answer
- Homework
Where You Ought to Be
By now, you are supposed to be comfortable with the
following tools:
- The C language
- Your C compiler
- A debugger
- make
- A wire analyzer (such as WireShark)
And the following concepts:
- Fundamentals of programming:
- loops, recursion and control flow
- data types and structures (structs,
pointers, linked lists)
- procedures, functions, and modular programming
- memory management
- Fundamentals of software engineering:
- Coding for maintainability: comments, simplicity,
readability
- Unit test
- Regression testing
- Version control, collaborative tools
- TCP/IP networking:
- IPv4 and IPv6 addressing
- TCP (stream, or connection-oriented) data transfer
- UDP (datagram) data transfer
- DNS
- Sockets
- Network byte order
- Mixed binary and ASCII (text) data handling
...that's a lot for one semester.
Structure of Your System
By now, you should have a complete system fairly well under way.
It should consist of the following:
- A makefile
- TCP server
- TCP client
- UDP server
- UDP client
- Basic library routines (mylib.c)
- A library of networking routines
(networking.c)
- Module test files, mylibtest.c and networkingtest.c
宿題 10/9
Homework From Lecture 2
This week's homework (submit via email):
- Begin your term project. Create three source files with the
following functions:
- hotpotato.c:
main()
- mylib.c:
SleepALittle()
- networking.c:
OpenConnectionToServer()
Compile and run your program.
main() should call
both SleepALittle()
and OpenConnectionToServer(). The other two
functions can be dummy functions for now.
- Above, we defined the function MakeElementList().
Write a program including the
function FreeElementList(), using the library
function free().
宿題 10/16
Homework From Lecture 3
This week's homework (submit via email):
- Last week, you were supposed to create three source files and link
them together for your program. This week, we are going to
add unit test. We need two more source code files:
- mylibtest.c
- networkingtest.c
Each of those should include a main() function that
calls each function in the corresponding source file to test
that it works. Now you must compile three separate programs:
hotpotato, mylibtest, and networkingtest. Show that each one runs.
- The homework "answer" at the top of this page does not actually
work. Please copy that to your computer, and debug it. (You may
also want to use this as an opportunity to try a source code control
system, such as RCS, and my preference is that you send me
the solution to this problem as a diff or rcsdiff from
the existing program.)
宿題 10/23
Homework From Lecture 4
This week's homework (submit via email):
- Take the above program, and edit where the comments are to print
out information about the connections,
using getnameinfo(), getpeerinfo(),
and gai_strerror().
- Test for errors from the system calls in the above code.
Use perror() where appropriate.
- Modify the above server so that it calls fork()
and creates a second process after accepting the connection. The
parent should close() the connection socket and
return to waiting for a new connection, while the
child should close the initial socket, process the connection, then
exit.
- Learn to use a wire monitoring tool, such as Wireshark or
tcpdump. Capture the packets of two connections to your server to
show that both connections are being processed at the same time.
宿題 11/6
Homework From Lecture 5
This week's homework (submit via email):
- If you are using a Unix-like environment (including cygwin), and
you are not yet using make, create a Makefile like
the one above for your programs.
- Add a main() to the TCP client example above, and
test it with your TCP server.
- The UDP client above uses the old-style approach to sockets
(AF_INET, htonl(), htons()). Adapt it to
use getnameinfo(), as in the TCP client example.
This should allow it to operate with IPv6.
Don't forget to loop over the possibly multiple return values
from getnameinfo().
- The UDP client doesn't wait for a response from the server. Adapt
it to use recvfrom() to receive a packet from the
server, and print out what it gets.
宿題 11/13
Homework From Lecture 6
This week's homework (submit via email):
- Test your TCP and UDP clients against my server.
- Capture the packet trace.
- Create the file mylib.c, if you don't have it, and
add the functions report_mysocket()
and report_partner() to it, and use them in your TCP
and UDP servers.
- Create prototypes for those functions and create a matching header
file.
- Use a more thorough Makefile, with dependencies
made automatically. You will need to use GNU make (possibly
called gmake) to use this file.
宿題 11/27
Homework From Lecture 7
This week's homework (submit via email):
- Compile the example program from the IBM website and report
whether your machine is big endian or little endian.
- Adapt your TCP client and server programs to
use htonl() and ntohl() to send and
receive binary data correctly, as well.
Next Lecture
第7回 11月13日
Lecture 7, November 13: Binary data encodings
Additional Information
その他