Thread: Listening to ports/devices

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    Listening to ports/devices

    Hello all,

    I am new to programming, and I was wanting to make my own logging program.

    I want to "listen" to say a port, or a device such as a modem to see when it goes "active."

    I can't seem to find anything about it. If someone could point me to a resource I would greatly appreciate it.

    (If my problem is too vague please let me know and I will try to explain myself further.)

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Way too vague. What OS would be a pretty critical piece of info. TCP or UDP? What are you logging to? You basically have a completely unspecified problem to solve which means you can't begin a solution.

    More importantly though: have you mastered the basics? Start with a classic like hello world, work your way through flow control, arrays, basic data structures, pointers and memory management, file handling, etc. There are some tutorials here to get you started: Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Some basic questions:
    Which operating system are you using?
    Which compiler?


    Do you have admin/root access?
    Digging around the hardware at a low level usually requires extra privileges.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    haha

    Oops! I meant to put this in the post... The OS could be Windows or Linux, prefferably Windows at the moment. It can be TCP or UDP, but TCP is preferred. I do have privs as my project will only be running on my own boxes. Probably mingw/gcc will be the compiler.

    And I know some python and Java, but I want to start trying the projects I've always wanted to do, and from what I have gathered these can only be done with something like C or ASM. I have books, and I know where I need to start, but I llike to have all my resources before I start. I don't want to get half way and not be able to find some bit like now.

    Thanks

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Don't use assembly! Way too low level. It's really only used for drivers and embedded stuff nowadays, and some low-level system calls, much lower than what you're doing. You'll probably end up blowing your brains out if you try.

    For Linux, look up the BSD sockets implementation. There are lots of docs and man pages. The main functions will be the socket, listen, send and recv functions (or sendto and recvfrom for UDP). You can google for tons of examples.

    In Windows, you can use the Winsock API, which is based very heavily on the BSD implementation, so the code will be very similar. Microsoft's website should have plenty of docs and some examples IIRC. If not, the Linux examples should port with little effort.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    So how about using wireshark then, or at least the packet capture interface it sits on?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Quote Originally Posted by anduril462 View Post
    Don't use assembly! Way too low level. It's really only used for drivers and embedded stuff nowadays, and some low-level system calls, much lower than what you're doing. You'll probably end up blowing your brains out if you try.

    For Linux, look up the BSD sockets implementation. There are lots of docs and man pages. The main functions will be the socket, listen, send and recv functions (or sendto and recvfrom for UDP). You can google for tons of examples.

    In Windows, you can use the Winsock API, which is based very heavily on the BSD implementation, so the code will be very similar. Microsoft's website should have plenty of docs and some examples IIRC. If not, the Linux examples should port with little effort.
    Thank you. And what about devices? Such as a modem? Or as Salem has pointed out the packet capture interface of wireshark..
    Last edited by nawledge; 01-25-2011 at 12:04 PM. Reason: stupidity

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    My resources are tapped on this one. I've never worked with the Wireshark API or TCP/IP over modem. Try googling around a bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Listening socket and thread problem
    By esaptonor in forum Windows Programming
    Replies: 6
    Last Post: 06-19-2010, 03:04 AM
  2. What are you listening to now?
    By Graham Aker in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 01-27-2009, 11:36 AM
  3. How to do port listening in C++?
    By voodoosg in forum Networking/Device Communication
    Replies: 1
    Last Post: 06-07-2006, 12:40 AM
  4. single Socket for listening and sending/receiving, Simultaneously?
    By Aidman in forum Networking/Device Communication
    Replies: 10
    Last Post: 10-01-2003, 11:17 PM
  5. Replies: 1
    Last Post: 10-03-2002, 09:52 AM