[mdlug] C Library for network applications

Michael Corral micorral at comcast.net
Tue Feb 27 13:49:27 EST 2007


Wojtak, Greg a ecrit:
> Does anyone have any experience using any of the network libraries
> available out there?  I am writing a small network based daemon and
> dont want to learn the intricacies of network programming in order
> to accomplish this otherwise small program.

How small? If you're just talking about a simple daemon that listens
on a port and runs some stuff based on the data it receives, then you
don't even need C, it can be done in bash or ksh. I posted about
this a few years ago on MDLUG, and posted actual code on the MDLUG
forums (which are unfortunately still down...hey merc, what's up with
that?:). Anyway, I can send you some sample code if you want.

The main idea is that bash and ksh have read/write capabilities on sockets
using the /dev/tcp/IP_ADDRESS/PORT interface. For example,
echo "HELO" > /dev/tcp/127.0.0.1/25
will write "HELO" to sendmail running on port 25 on localhost. And
cat < /dev/tcp/192.168.1.1/13
will read the time on 192.168.1.1 if the daytime service is running on
port 13. Using this interface, it's easy to write a script that gets
run from inetd whenever data hits a certain port. No need for C. :)

Michael



More information about the mdlug mailing list