Tuesday, May 29, 2007

Security-specific Programming Errors

Thomas Biege has written an interesting article about Security-specific Programming Errors. Article can be found from:
http://www.linux-knowledge-portal.org/en/content.php?SEARCH&content/programming/secprog1.html

Thursday, October 26, 2006

Common programming errors in C

Programming is something where practise helps. Are you familiar with these things:
http://www.drpaulcarter.com/cs/common-c-errors.php ?Link

Tuesday, August 15, 2006

Dealing with multiple interfaces?

After discussions about how to find out local IP addresses Martti Kylmälä (thank you) pointed out following web page:
http://www.hungry.com/~alves/local-ip-in-C.html. The page has example codes, discussion about portability and depency on DNS.

Lets add also a link to big endian and little endian discussion:
http://www.netrino.com/Publications/Glossary/Endianness.html

Wednesday, December 07, 2005

Getting started with IMAP

Sometimes (or more often) it is hard to start tasks by reading RFCs. For IMAP you might want to read introduction e.g. from:
http://www.tcpipguide.com/free/t_IMAP4GeneralOperationClientServerCommunicationandS-2.htm

Friday, November 11, 2005

Getting started with TCP

Before hitting head too many times to a wall, you might want to look some example code. You can find quite good example from http://www.cs.rpi.edu/courses/sysprog/sockets/sock.html

Example codes server.c and client.c should compile also in Linux if you add stdlib.h and strings.h in your #includes.

The example server can handle only a single connection. Later in the page the server is modified to handle multiple connections by forking new process for each client. When fork() is used the main program should wait signal from each client so child processes are not left as zombie processes after they stop executing. Indepedent processes for handling connection from each client can be problematic. Example of this is e.g. chat server, where messages from each connection must be relayed to other connections. If clients are connected to separate processes, then processes must communicate with each other somehow, e.g. using file or socket. Other issue is the number of processes. Two hundred users would mean two hundred processes competing from system resources.

Processing of multiple clients does not require fork. We can continue using select(). Few ideas why to use select() with a TCP server:

When we receive something to our original server socket (e.g. fd1), it is a new connection. Use accept() to process this new connection. accept() returns a new file descriptor (e.g. fd2). From now you have to be watching if you receive something in either of those file descriptors.

If you receive something from our main socket (fd1), it is a new connection request and should be handled with accept, which creates a new file descriptor again(e.g. fd3, etc.). If something arrives from other file descriptors (besides of main socket (fd1)) it is data arriving from the clients (or connection close).


Tuesday, November 08, 2005

Multicasting

I have once assumed a bit too much and not really explained what IP multicasting is. The basic idea is to send a single message, which is targeted to multiple receivers. This is that sender uses special IP multicast address, which those who want to receive the messages are joined to.

Difference to broadcasting is that in broadcasting message is targeted to all hosts and in multicasting message is targeted only to those who have subscribed (joined) the multicast group.

Wikipeda link about IP multicasting http://en.wikipedia.org/wiki/Multicasting

Multicast address assignments by Iana (http://www.iana.org/assignments/multicast-addresses)
 You can try e.g. multicast addresses in range of 239.255.000.000-239.255.255.255 in your own programs as they are defined to be in site-local scope.

How to join to a multicast group?
setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

How to use select?

Amazing - someone actually read and commented this blog! Thank you Janne for the link (http://www.lowtek.com/sockets/). Behind the link you can find Spencer's socket site. Get second option why you should use select() and links to some other sources of socket information.

I also encourage you to also say man select, as Linux man pages have generally quite good examples.

Monday, October 31, 2005

Initial ideas

This blog is founded to help students to learn socket programming. Designated audience for the blog are the students of network programming course (http://www.it.lut.fi/kurssit/05-06/Ti5315000/).

Please note that basic tools for programming are C-language and Linux workstations. This will guide our views and discussions.

Idea is that students can add comments about their ideas and especially leave links of helpful study material they might come across. Everyone is welcome to comment - participation in the cource is not requirement.

First link: Five pitfalls of Linux sockets programming
http://www-128.ibm.com/developerworks/linux/library/l-sockpit/?ca=dgr-lnxw06SocketPitfalls

Ok ? Who are the first ones send in links for explaining basic UDP-server, basic TCP-server, how multiple connections is handled, usage of select?