On Wed, Oct 05, 2005 at 01:24:22PM +1000, YH wrote: > Hi, > > Sorry, this is really not a linux question, rather a network programming > question if you could still help me out: Firstly, walk, nay, run to your nearest bookstore and pick up a copy of UNIX Network Programming volume 1 by W.R. Stevens. > 1. I have a server / client program of tcp connection on linux. The > server uses a select function to wait clients packets. It works fine > until a client program is terminated. Then the server is crashed (server > program can no longer be blocked at select). How can the server detects > the client terminate without crashing? Do you check the result of read()? It will return an error when the client closes it's end. If you don't do that you risk a SIGPIPE. > 2. Is there any system function call or utilities on linux to check > Ethernet and network status? ifconfig, tcpdump, many many others. > 3. Why we need to cast struct sockaddr_in serverAddress, clientAddress > to struct sockaddr *) in bind(fd, (struct sockaddr *)&serverAddress, > sizeof(serverAddress)) and accept(fd, (struct sockaddr *)&clientAddress, > &clientLength)? Because bind and accept work for other protocols than IP, including IPX, AX25, etc. So bind takes the generic type and you cast it when you use it. Hope this helps, -- Martijn van Oosterhout <kleptog@xxxxxxxxx> http://svana.org/kleptog/ > Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a > tool for doing 5% of the work and then sitting around waiting for someone > else to do the other 95% so you can sue them.
Attachment:
pgpCd4EjnqGmb.pgp
Description: PGP signature