views:

371

answers:

2

I'm aware that it's straightforward to redirect the shell output to a file.

So I should also be able to set up a socket and redirect the shell's output to the socket, as essentially it's just another file descriptor (I think)?

I've seen some example C programs that create some basic client/server functionality but (as small as they are) this seems rather like over-kill.

Can I set up a socket with just a few commands in the shell? If so, what's the syntax I need?

I realise this is probably extremely simple, but I'm new to VxWorks, and having spent the last two days trawling the web for the answer I decided to ask here!

Thanks for any help you're willing to offer.

Dan

A: 

I don't know VxWorks, but there is a gnu program netcat for *nix that can do this, like:

your_program | netcat host port

will redirect the output of your_program to port@host.

+1  A: 

The shell is a simple c interpreter. Just write the code as if you were writing a c program:

-> mysock = socket(2, 1, 0)
/* double check that these are right for AF_INET and SOCK_STREAM*/
-> myaddr = malloc(100)
-> m myaddr
/* fill in the fields according to the address you want to connect to */
-> connect(mysock, myaddr, myaddrlen)
/* I don't have a system handy now, but you can figure out
   myaddrlen by writing a small C program to print out sizeof(sockaddr_in),
   or just figure it out by hand looking at the header. */

Now your socket fd is connected, redirect and have fun. (In my opinion, if you're going to do this regularly, it might be simpler to code this into a c program that you can run from the shell to do all of the setup for you.)

bstpierre