Opening tcp ports?

This is a discussion on Opening tcp ports? within the C Programming forums, part of the General Programming Boards category; How can you open a tcp port, use your program as a service, and send data across it? Even more, ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    2

    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?

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    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).

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    2
    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!

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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.

  5. #5
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902
    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.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TCP Header problem (error)
    By nasim751 in forum C Programming
    Replies: 1
    Last Post: 04-25-2008, 08:30 AM
  2. Accessing TCP flags in TCP packets on Linux using C !!
    By vishamr in forum Linux Programming
    Replies: 2
    Last Post: 10-16-2006, 09:48 AM
  3. virtual ports
    By royuco77 in forum Networking/Device Communication
    Replies: 5
    Last Post: 07-02-2005, 11:33 AM
  4. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  5. TCP TIME_WAIT state
    By Engineer in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 12-27-2001, 08:50 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21