-
Opening tcp ports?
How can you open a tcp port, use your program as a service, and send data across it? Even more, the code must be linux/gcc compatible. If it matters enough that the code is radically different, move the thread to the linux board. My idea was a file transfer system between computers, using a port high enough (45,723, for example) that main stream port scanners won't by default scan up there. Any thoughts?
-
You are right, it should be moved to the linux board, though I believe Windows may have a similar socket layer that's compatible. Regardless, it's not to do with the C language.
Anyway, see http://beej.us/guide/bgnet/
By the way, if you want afile transfer system between computers, why don't you just use the usual methods, ftp, scp, rsync, etc.?
Also, putting something on a high port to "hide from port scanners" is a rather silly idea. The protocol and implementation still needs to be secure. If it's insecure, you are better off leaving in only accessible from trusted hosts (either physical isolation or firewall).
-
Your right, but I'm really just doing it for fun. I'm not going to transmit government docs on it ;) . Thanks for the link!
-
Actually, questions of this nature ought to be posted in the Network and Device Programming board, but since the question is already answered, we'll just leave it at that. You may also find some help by searching the forums. Networking beginners often run into the same problems.
-
Window's socket layer is fairly compatible. Most of the function calls are the same, so what is in the guide that cwr posted can be applied on Winodws. On Windows you can also get messages sent to Windows whenever a socket is ready for read/write... but that'll kill any portability.
The two biggest differences between sockets in Windows & Linux, at least in my mind, is that on Windows you need to do a few things special. You'll need to link with the winsock dll (-lwsock32 / something for the later versions...) and call the initialization/shutdown functions. (I usually wrap them in a preprocessor directive.)
The other difference is send()/recv(). I believe on *nix they're defined as (int, [const] void *, int, int). (Which I personally agree is how they should be defined.) However, on Windows, send() & recv() are defined as (SOCKET, [const] char *, int, int). SOCKET is just a typedef'd unsigned int (And thus socket()'s return type is SOCKET, not int). However the change of void * to char * can be particullarly annoying, as it causes warnings under -Wall for me. It's also closesocket() in Windows, not close(). (I'm not sure if close() in Windows works... never tried.)
Most of these problems can be overcome by a fancy header with some preprocessoring. Only thing I can't think how to overcome is the differences in recv() & send().
I've found this page to be helpful.