libsocket 0.7.1 Documentation
libsocket Documentation version 1.0.2
Last updated: 12th May 1998
Copyright
libsocket Copyright 1997, 1998 by Indrek Mandre
libsocket Copyright 1997, 1998 by Richard
Dawe
Portions of libsocket Copyright 1997, 1998 by the Regdos Group
libsocket is distributed under the terms of the GNU
Library General Public License (the GNU LGPL).
This document was written by Richard
Dawe. Please see his contact details for (slightly)
more information.
Introduction
libsocket is a BSD-socket library for DJGPP. It uses Windows's networking
functions to provide TCP/IP networking services to DJGPP programs. For
more detail, please see question 1.1 of the FAQ.
libsocket currently does not work with Winsock 2! This means it will
not work under Windows '98.
This version has not been tested extensively, as I do not have access
to all of the networking environments that the new code works with. It
is very much a work in progress, hence the extra .0 version. Any feedback
about when it works or doesn't would be appreciated.
Table of Contents
The following links explain various aspects of libsocket in more detail:
Please see the Library Reference (HTML versions
of the man pages) and some Frequently Asked Questions
(FAQ).
Availability
Where to Download libsocket
The main site for libsocket is http://irix.bris.ac.uk/~rd5718/libsocket/,
but the distributions are actually on Geocities (see below). The old distribution
site can be found via http://www.pld.ttu.ee/~indrek/.
There will be a link from the old site to the new site. libsocket should
be downloadable from the DJGPP archive. A mirror of this as part of the
Simtelnet archive can be found in the UK at ftp://sunsite.doc.ic.ac.uk/packages/simtelnet/gnu/djgpp/.
If you do not know of a local mirror site, click below to download from
the main distribution site:
I know the links in this document are UK-centric. I'd be happy to make
up for this, if you mail me international
links.
Which Distribution to Download
If you simply wish to use libsocket in programs, download the binary version.
If you're interested in how libsocket works, or you wish to modify the
library, download the source distribution. If you download the source distribution,
you will be able to compile a debugging version of the library.
What libsocket requires
The following DJGPP packages are required to compile libsocket's demo programs
and the library:
The following DJGPP packages are required to view the man page documentation:
The following DJGPP packages are required to rebuild the HTML versions
of the man page documentation:
-
GNU Man (man11b.zip
or later)
-
GNU Make (mak375b.zip
or later)
-
Perl (perl54b.zip
or later) *WARNING* This is untested - ActiveState's Perl for Win32
was used in generating the library. This should work, however.
libsocket requires TCP/IP networking to have been installed. This can be
done from the networking control panel.
[Back]
Installation
Decompression
As of version 0.7.1, libsocket uses the contrib/ directory layout, and
should be unzipped into the DJGPP directory. libsocket should be decompressed
using InfoZip or WinZip or another unzipper that supports long filenames.
If you do not have a long filename decompressor, then the library will
still work, but some of the documentation will not be accessible (some
of the man pages; some of the HTML links won't work). If you use PKZip,
don't forget to use the '-d' option! All the file names in the archive
will be prefixed with contrib/libsocket-<version>/, e.g. contrib/libsocket-0.7.1/,
or manifest/, so it is safe to decompress into the DJGPP directory, as
all the files will go into a sub-directory.
Once the library has been decompressed, changed into its directory and
type "make" for a list of targets. The source distribution will
have more targets than the binary distribution. To compile everything that
comes with the distribution, type the following:
make distclean
make dep
make all
Configuration
Please read this section carefully. It may be the case that no configuration
is necessary. I realise that this is probably the least clear part of using
libsocket, so if this section does not make sense or answer any of your
questions, please ask me about it.
libsocket comes with a configuration program, Netsetup,
that creates the configuration files. libsocket uses the same set of configuration
files as Linux: hosts, host.conf and resolv.conf. These are described below,
and have links to the appropriate man pages. Note that they are usually
stored in c:\windows under Windows rather than /etc under Linux.
File
|
Function
|
hosts
|
"Resolving": Name to IP address translation, e.g. fred.acme.com
=> 192.168.0.123
|
host.conf
|
Tells the name resolver whether to look at hosts or use the DNS
server first
|
resolv.conf
|
Tells the name resolver the domain name and the DNS server's IP
address
|
Netsetup can be compiled and run by typing "make netsetup".
It will need to know the following information:
-
Your computer's name - This will be placed in the hosts file.
-
Your computer's IP address - This will be placed in the hosts file.
-
Your domain name - This will be placed in the resolv.conf file.
-
Whether you have a DNS server or not, and what its IP address is - This
is used to construct host.conf and resolv.conf.
The files created are hosts.eg, host.conf and resolv.conf, all in the setup/
directory. They need copying to a directory where libsocket will find them
on start-up. You can specify this directory using the LIBSOCKET environment
variable, e.g.
SET LIBSOCKET=C:\NETCONFIG
at the DOS prompt, or in autoexec.bat, or a line in djgpp.env in your
DJGPP directory (see the DJGPP FAQ for more details). If you do not specify
it, the Windows directory is searched. When copying these files, don't
forget to back-up the old hosts file, and don't forget to rename hosts.eg
to hosts.
Note: If you configured libsocket using an earlier version of
libsocket, then please reconfigure it with the latest version of Netsetup
- there may have been bugs in the older version (see Netsetup bugfix 1,
2).
To test the configuration of the library, try running one of the demos,
e.g. the name resolving program resit. Try:
demo\resit <your computer name>
This should display the IP address you gave Netsetup.
libsocket can also determine some settings from the Registry. It can
determine the DNS server's IP addresses from the registry in the following
circumstances:
-
the DNS server(s) IP addresses have been set in the networking control
panel for a permanent network connection;
-
the computer is using dial-up TCP/IP access with static (fixed) DNS server
IP addresses.
In these cases, Netsetup does not need to be run. Netsetup requires the
computer's name only to set-up the hosts file - libsocket can determine
the host-name automatically.
Netsetup is probably most useful on private networks where there is
unlikely to be a DNS server.
Using the Library in Other Programs
Before the library can be used in other programs, the header files (include
files) and library must be copied to the DJGPP directories. This can be
done by typing "make install". Then, using the library in a program
is simply a matter of including the correct files (e.g. "#include <socket.h>")
and linking in the library with the "-lsocket" option on the linker
line.
Using the man Pages
To install the man pages, type "make installman". To view the
main libsocket man page, type "man libsocket".
[Back]
Request for Feedback and Information
If there are any features you'd like in libsocket, or you have any comments
about the library, the documentation or anything to do with libsocket,
please mail me, Richard Dawe,
and I'll try and help.
Also, if anyone has any information about using Winsock 2 from a DOS
box, then I'd be very grateful to hear how. The lack of Winsock 2 support
is currently the largest problem facing libsocket.
[Back]
Bugs & To-dos
[Indrek] There are some (there must be), but I don't have anything very
nasty in mind. Most bugs are misfeatures, which means some things don't
work as they're supposed to.
-
gethostname() returns the NetBIOS name sometimes.
-
ioctl() partly works
-
fcntl() partly works
-
Lack of Winsock 2 support
[Rich] Here are some things I plan to add when I have time:
-
Better documentation (as always) - any comments on how I can improve it
would be appreciated.
-
Add a Windows set-up program. This should be able to detect settings automatically,
making the library easier to use, not just by programmers, but by end-users
too.
-
Check that libsocket works with the DJGPP version 2.02 (currently in alpha).
-
Tidy up the code - more consistent comments, etc..
-
Write some documentation about the library's internal functions, for those
who want to know.
-
Packet driver support? (e.g. like WAT/TCP, maybe using ndispkt3?)
-
Test with threading libraries such as lwp for multi-threaded network applications.
-
Overhaul the resolver code - it uses 'goto's! Besides, the extra code is
bolted-on rather than integrated.
-
Connecting to non-existent IP addresses seems to hang the library and not
time-out - why? How long is the time-out?
[Back]
Credits
General
Dan M. Hedlund <hedl0036@tc.umn.edu> http://www.geocities.com/SiliconValley/Peaks/8523/
His Wsock library is the base of this library.
Alfons Hoogervorst <alfons@hoogervorst.demon.nl> http://www.hoogervorst.demon.nl/
His dsock library helped to get select() and blocking
recv() calls work. He also contributed some information on how to obtain
Windows machine and DNS IP addresses.
The Regdos Group <alfons@hoogervorst.demon.nl> http://www.hoogervorst.demon.nl/
They contributed the registry-access code that is
used to automatically find out some IP settings. Alfons is the maintainer.
George Foot <george.foot@merton.oxford.ac.uk> http://users.ox.ac.uk/~mert0407/
He pointed out a bug in Dan Hedlund's code.
Indrek's Credits
Linus Torvalds
Linux is the best OS - much of the code is from
it.
Richard Dawe <rd5718@bristol.ac.uk>
http://irix.bris.ac.uk/~rd5718/
This man made 99% of the documentation of this library.
I can't describe him in words, magnificent guy! You'll get far, Rich. [Rich:
Please, you're making me blush! =) ]
Heiko Jappe <hej@gis.de>
He has a very nice habit of finding all the nastiest
bugs and reporting them. There would be some very bad "features" in the
library without him.
Wojtek Galazka <wgalazka@chem.uw.edu.pl>
He pointed out some bugs and has some great ideas.
A man with an open mind.
Rich's Credits
Indrek Mandre <indrek@warp.edu.ee> http://www.pld.ttu.ee/~indrek/
Thanks to Indrek for writing the library in the
first place, letting me contribute to it, and then, gulp, trusting me to
look after it. This man has a lot faith and trust! I hope I do a good job,
Indrek.
Discredits
Indrek's Discredits
Bill
The worst OS I've ever seen, it's slow, it crashes
all the time and it looks ugly. [Rich: Well, it only crashes for me when
I use Microsoft applications!]
[Back]
Version History
Version 0.7.1 1998-5-12
-
Fixed some ambiguities in conditions in the resolver code, so that the
source could be compiled with gcc 2.8.0 (and later?).
-
Added code to query the DHCP VxD, to obtain more DNS addresses automatically.
-
Tidied up some of the code.
-
Fixed many memory leaks and reduced memory usage slightly.
-
Fixed some bugs in the DNS address obtaining code.
-
gethostname() will no longer return spaces in host names.
-
Fixed a bug in callvxd.c that lead to nearly *all* socket functions failing
:(
-
Client demo now has name resolving.
-
Found a bug in Netsetup that created host.conf
incorrectly when no DNS server was present, leading to the computer appearing
to hang when resolving names. Also fixed some errors in the Netsetup Makefile.
-
Slight updates to the FAQ.
-
Added a man page for host.conf.
-
Added two new targets, debug and nodebug, to the top-level Makefile to
create Makefile.cfg for debugging and non-debugging builds of the library.
-
Moved the library into the contrib/ tree and added manifest files.
Version 0.7.0 Work-in-progress 1998-5-3
-
Richard Dawe took over maintainance of the library.
-
The source files renamed to have short filenames. This lead to compilation
after typing "SET LFN=Y" at the DOS prompt.
-
The Regdos Group's registry code was incorporated, to allow automatic configuration
using registry settings.
-
Added Winsock 2 detection. Creation of sockets fails, in order to prevent
protection faults.
-
Rearranged the library, and created binary and source distributions.
-
Fixed a bug in the VxD calling code, pointed out by George Foot.
-
Wrote some new documentation, including a FAQ, and updated the old documentation.
-
Fixed getdomainname() to look at the environment variable LOCALDOMAIN,
resolv.conf or the registry, so it's more likely to succeed.
-
Modified WS_init() to return errors.
-
Added support for the enviroment variable LIBSOCKET, so that configuration
files could be placed somewhere other than in the Windows directory.
-
Upgraded to the latest version of man2html, the program that converts man
pages into HTML.
-
Modified resit to use command-line parameters as well as prompting for
a name (e.g. the command form "resit jimbo" now works).
-
Fixed bug in Netsetup.
-
Added some defines: FIONREAD, FIONBIO.
-
Fixed socket() and accept() calls.
-
Added select() demo, demo/select.c
-
The library now works with C++.
Version 0.6 1997-12-02
-
Made workaround to djgpp's fsext bug, thanks to Heiko Jappe.
-
Fixed close(), now fopen() after creating and closing sockets works.
-
Added a huge amount of documentation by Richard Dawe.
-
Added netsetup script by Richard Dawe.
-
Lots of minor bugs fixed.
-
Added fcntl() call and defined some new flags that I would like to see
in future DJGPP versions: O_NDELAY and O_FNDELAY.
Version 0.5 1997-10-11
-
Fixed misfeatures in Makefiles pointed out by Laszlo Vecsey. Created one
global Makefile.cfg.
-
Name resolving now works.
-
Wrote new demo resit that demonstrates name resolving.
Version 0.4 1997-09-15
-
Fixed the bugfix made in recv(). I discovered that programs crash after
connect on many Windows '95 installations.
Version 0.3 1997-08-28
-
Fixed bug in recv()/recvfrom() (blocking and return value and EOF condition)
-
connect() now waits for Windows; this means send() just after connect()
works now.
-
Wrote new demo httpget that gets http files from WWW servers.
Version 0.2 1997-08-22
-
Fixed Makefile bug when make all gave errors at demo directory.
-
Wrote client.c and server.c as demos at demo directory.
[Back]
This document was written by Richard Dawe.
His home page can found at http://irix.bris.ac.uk/~rd5718/
and his e-mail address is rd5718@bristol.ac.uk.