Thread: Question about socket programming

  1. #1
    Bill
    Guest

    Question about socket programming

    I am writing a socket program that will accept all the ip packet regardless of the destination address value in the header of the ip packet. I would like to ask what ip address should I bind my socket to in order to achieve this? Or are there any other way to achieve this?
    I am using GCC as C compiler and Sun solaris 8 platform.
    Thanks in advance.

  2. #2
    Unregistered
    Guest
    Hi,

    Since you didn't describe code I assumed that you used a call similar to
    socket(PF_INET,SOCK_RAW,.... (you didn't note TCP nor UDP)
    If you want to receive packets you need to bind the socket to your _local_ interface address (as described in the bind(2) man page). If you bind INADDR_ANY the socket will be bound all to your interfaces. See the ip(7) man page too.

    I hope this will help.



    Bye

  3. #3
    Bill
    Guest
    Hi,
    Sorry for my carelessness. here is the details:
    My program needs to capture all promiscuous IP packets (UDP) in the LAN, regardless of the value of the destination ip address in the header. Would you know how could I accomplish this?

    Thanks in advance.

    ~~~~~~~~~~~Here is my code~~~~~~~~

    struct sockaddr_in servAddr;
    ....
    sd = socket(AF_INET, SOCK_DGRAM, 0);
    servAddr.sin_family = AF_INET;
    servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servAddr.sin_port = htons(1500);
    servLen = sizeof(servAddr);
    if(bind(sd, (struct sockaddr *) &servAddr, servLen)<0) {
    perror("\nERROR : Failed to bind socket for the Listener ");
    return ERROR;
    ....
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  4. #4
    Unregistered
    Guest
    Hi,

    I am using Linux and I never programmed a functional capturing program, but I note the following to you:

    I think you need to use a lower level part of socket implementation. You used socket(AF_INET... but I recommend to use socket(PF_INET,... system call to create socket. On my system this is the way to do what you want. I don't know wether Solaris supports it or not; this is a BSD style thing. See the 'man 7 ip' page to obtain details about it (you should also inspect the sys/socket.h and netinet/in.h files).
    You also need to turn your LAN card to promiscous mode. I have never programmed it before in C (I've done it with ifconfig) but I vote to ioctl()...
    Replying to your original post again I tell you the binding of socket to an address is meaningful for your ip addresses so INADDR_ANY means binding the socket all to your interfaces.
    And take a look to pont.net/socket

    Have good luck!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Socket Question
    By BENCHMARKMAN in forum C Programming
    Replies: 15
    Last Post: 03-12-2008, 09:57 PM
  2. Socket program
    By mhetfield in forum C Programming
    Replies: 5
    Last Post: 04-03-2007, 03:46 PM
  3. Slight problem with socket reading!!!
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 02-15-2006, 09:55 AM
  4. problem closing socket
    By Wisefool in forum Networking/Device Communication
    Replies: 2
    Last Post: 10-29-2003, 12:19 PM
  5. Simple Socket Question
    By SourceCode in forum Linux Programming
    Replies: 2
    Last Post: 06-22-2003, 09:20 PM