Filter server

This is a discussion on Filter server within the Networking/Device Communication forums, part of the General Programming Boards category; Hi all,, I need to implement a TCP Server which should listen on port 1234 and should have ip=192.168.1.1,,,, It ...

  1. #1
    Registered User
    Join Date
    Jul 2013
    Posts
    15

    Filter server

    Hi all,,
    I need to implement a TCP Server which should listen on port 1234 and should have ip=192.168.1.1,,,,
    It should be able to accept connections of same subnets clients i.e.
    192.168.1.2-254;;;
    When it gets desired client should say to him Hello otherwise others should be welcomed "Good Bye"..
    Any suggestions ??

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Why those IP addresses specifically?

    The IP address of the server program will depend on which computer you run it on. The IP address is technically assigned per network interface (e.g. ethernet card in your computer or wifi connection). So if the computer you are running this on is 192.168.1.1, great. Otherwise you need to reconfigure it's network settings or run it on another device.

    Network programming is not the same for all OSes. Linux, Windows and MacOS all do things a little differently. The core concepts are the same, and even the APIs are very similar, but they are not 100% compatible.

    Then, you need to study up on network programming. I like Beej's Guide. It's Linux oriented, but it's a great tutorial, and all of the concepts carry over to MacOS or Windows quite well. Google will turn up many more, for whatever OS you use.

    Working through a good guide (no rushing or skipping steps) should give you some ideas of how to do your filter.

  3. #3
    Registered User
    Join Date
    Jul 2013
    Posts
    15
    Quote Originally Posted by anduril462 View Post
    Why those IP addresses specifically?

    The IP address of the server program will depend on which computer you run it on. The IP address is technically assigned per network interface (e.g. ethernet card in your computer or wifi connection). So if the computer you are running this on is 192.168.1.1, great. Otherwise you need to reconfigure it's network settings or run it on another device.

    Network programming is not the same for all OSes. Linux, Windows and MacOS all do things a little differently. The core concepts are the same, and even the APIs are very similar, but they are not 100% compatible.

    Then, you need to study up on network programming. I like Beej's Guide. It's Linux oriented, but it's a great tutorial, and all of the concepts carry over to MacOS or Windows quite well. Google will turn up many more, for whatever OS you use.

    Working through a good guide (no rushing or skipping steps) should give you some ideas of how to do your filter.

    Actually i had been through beejs guide already and had practiced on linux and yes i agree that ipadress cant be forced...but i want to do like this on linux OS but it seems imposible on localhost

  4. #4
    Registered User
    Join Date
    Jul 2013
    Posts
    15
    Filtering a class of ipaddresses is what i want to learn........
    A specific class....
    Had already done practice of network programming using linux....
    but in the current scenario is lacking vision a little bit

  5. #5
    Registered User
    Join Date
    Oct 2006
    Posts
    2,590
    Quote Originally Posted by Javed Iqbal View Post
    Filtering a class of ipaddresses is what i want to learn
    you'd do well to study up on the linux firewall, iptables, and learn how to filter TCP traffic with it.
    Code:
    namespace life
    {
        const bool change = true;
    }

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    All this stuff is in Beej's guide. The section on bind() discusses listening on specific network interfaces (it uses getaddrinfo to get a list of local interfaces you can listen on). The section on accept shows you how to get the address of the person connecting to you. Also, he has man pages for bind and accept. Read them.

    I'm being intentionally vague with my help for two reasons:
    The first is that, it's good for you. If I do all the thinking and spew out an answer you don't learn much. Also, learning to dig up the documentation, and be able to read and understand it, are crucial skills for any programmer, even the "hobbyist".

    Second, this forum is not a place for free code. It's actually against our forum guidelines. You will need make an attempt at this, and post your code here, and ask specific questions about what you don't understand. Make sure you do at least the 3 following things, to make it easy for us to help you:

    1. Post your code as plain text in [code][/code] tags, so it's easy for us to read.
    2. Post properly formatted/indented code (make sure it looks good in this forum, not just your editor), again, so it's easy for us to read.
    3. Make sure you check all your socket-related functions for errors. If an error occurs, print a useful message (e.g. using perror) and act appropriately (e.g. try again, continue anyway, or exit).

  7. #7
    Registered User
    Join Date
    Jul 2013
    Posts
    15
    Quote Originally Posted by anduril462 View Post
    All this stuff is in Beej's guide. The section on bind() discusses listening on specific network interfaces (it uses getaddrinfo to get a list of local interfaces you can listen on). The section on accept shows you how to get the address of the person connecting to you. Also, he has man pages for bind and accept. Read them.
    I need to know that if i will be able to programme so..how to check on linux host i.e i will be provided with localhost only...how to check for other ant ip addresses for testing purpose using single machine..

  8. #8
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,676
    Okay, here's some code to get you started:
    Code:
    int main(void)
    {
        // you fill in this part
        return 0;
    }
    Seriously, you said you've done network programming before, so why can't you at least attempt this, and post something? Beej's guide has code you could literally copy-paste, that would take care of 90% of what you need. I already explained, I wont write code for you.

    My comment #6 explains the 3 functions you need to do what you want. That's all the help you're getting until I see some real effort on your part.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DNS Filter ( Redirect)
    By jhsedona in forum C Programming
    Replies: 1
    Last Post: 04-08-2012, 05:20 PM
  2. Fir filter
    By kiros88 in forum C Programming
    Replies: 3
    Last Post: 06-18-2010, 04:02 PM
  3. Gabor Filter in C#
    By nanang in forum C# Programming
    Replies: 0
    Last Post: 05-17-2009, 09:22 PM
  4. yahoo filter
    By Yarin in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-27-2008, 05:36 AM
  5. Simple Filter
    By 00Sven in forum C Programming
    Replies: 3
    Last Post: 03-14-2006, 08:46 PM

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