Thread: how to get sender address in select system call?

  1. #1
    Registered User
    Join Date
    Mar 2008
    Location
    India
    Posts
    147

    how to get sender address in select system call?

    Hello all,

    previously i was using accept() API for my socket connections,As my requirement changed where i need to listien on multiple socket fds, i used select system call.



    my accept code is like below

    Code:
    accept(sockfd,(struct sockaddr*)&their_addr,&sin_size)
    Now my select call is like below.

    Code:
    select(serverSocket2 + 1, &fdset, NULL, NULL, NULL);

    Now how can i get the sender address in this select call..?

    Thanks all

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Basically, a loop over all valid file descriptors
    Code:
    for ( i = 0 ; i <= serverSocket2 ; i++ ) {
      if ( FD_ISSET(i,&fdset) ) {
        // do something with fd i
      }
    }
    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.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    when the select call indicates the server socket is readable as Salem shows, that's when you do an 'accept' and get the client address. "In order to be notified of incoming connections on a socket, you can use select(2) or poll(2). A readable event will be delivered when a new connection is attempted and you may then call accept() to get a socket for that connection"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. select system call usage doubt
    By vlrk in forum Linux Programming
    Replies: 4
    Last Post: 06-26-2011, 08:46 AM
  2. select system call with FIFO fd.
    By vlrk in forum Linux Programming
    Replies: 0
    Last Post: 05-11-2009, 04:27 AM
  3. simultaneously waiting for data on FIFO and UDP using select call
    By yogesh3073 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-05-2007, 09:53 AM
  4. Select Menu and Call Function
    By studentInC in forum C Programming
    Replies: 17
    Last Post: 12-14-2002, 07:42 PM
  5. C system call and library call
    By Coconut in forum C Programming
    Replies: 6
    Last Post: 08-22-2002, 11:20 AM