All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sreeram B S <sreeramb@netapp.com>
To: linux-kernel@vger.kernel.org
Subject: Re: UDP requires 2 reads to obtain vital information - Kindly comment
Date: Thu, 11 Aug 2011 11:20:01 +0530	[thread overview]
Message-ID: <4E436D89.6000201@netapp.com> (raw)
In-Reply-To: <1312998648.2295.10.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>

Hi all,
    Thanks for all the replies.
    Yes, it worked wonderfully upon setting the msg_name to the address 
of the place-holder for peer-address!

Regards,
Sreeram

On 08/10/2011 11:20 PM, Eric Dumazet wrote:
> Le mercredi 10 août 2011 à 22:27 +0530, Sreeram B S a écrit :
>> Respected people,
>>      I am Sreeram. I work on TCP/IP network applications.
>>      This mail is regarding UDP.
>>      Whenever a UDP datagram arrives, the receiver may wish to know the
>> sender's IP address and also the destination address of that datagram.
>> The recvfrom() function will return the sender's IP address. If the
>> destination address of the datagram is required, then the user has to
>> set the IP_PKTINFO socket option for the UDP socket and get the
>> address as ancillary data in recvmsg(). So, the point here is that the
>> user has to issue 2 reads on the same datagram (with the flag MSG_PEEK
>> in first read call enabled) in order to obtain the sender's IP and the
>> destination IP of the datagram. I personally feel that there should be
>> a way provided to the user to obtain these values in a single read
>> call. By doing this I am sure that lot of time would be saved in
>> collecting the required information.
>>      I have written a simple UDP client program to show that we need 2
>> reads to obtain the above information. I have made it signal-driven
>> just to make it interesting and not for any other reason. I have
>> attached the client program along with this mail.
>>      Fortunately, as mentioned above, Linux provides the IP_PKTINFO
>> socket option, enabling which, will send in a structure 'struct
>> in_pktinfo' as ancillary data in recvmsg(). The structure is as
>> follows:
>>
>>                    struct in_pktinfo {
>>                        unsigned int   ipi_ifindex;  /* Interface index */
>>                        struct in_addr ipi_spec_dst; /* Local address */
>>                        struct in_addr ipi_addr;     /* Header Destination
>>                                                        address */
>>                    };
>>
>>      Would it be incorrect if I request the kernel coders to add the
>> sender's IP address as well in this structure, so that the user will
>> get both the sender's IP and the destination IP address of the
>> datagram in a single call to recvmsg()?
>>      I very well understand that my knowledge is very much diminished.
>> Hence I request you to kindly correct me if what I have
>> understood/suggested is incorrect.
>> Please suggest.
>>
>> Regards,
>> Sreeram
>
> Part of your program :
>
>   /* Now receive the destination address. */
>      iov[0].iov_base = mesg;
>      iov[0].iov_len = 1;
>      msg.msg_name = NULL;<<  HERE>>
>      msg.msg_namelen = 0;<<  HERE>>
>      msg.msg_control = calloc(1, 100);
>      msg.msg_controllen = 100;
>      msg.msg_iov =&iov[0];
>      msg.msg_iovlen = 1;
>
>
> Remove the MSG_PEEK not needed call, and use instead :
>
> msg.msg_name =&peer;
> msg.msg_namelen = sizeof(peer);
>
>
> It should solve your problem : one single system call to get the message
> payload and metainformation (your own IP in ancillary data, and peer IP
> in&peer)
>
>
>
>

      reply	other threads:[~2011-08-11  5:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-10 16:57 UDP requires 2 reads to obtain vital information - Kindly comment Sreeram B S
2011-08-10 17:49 ` Andy Lutomirski
2011-08-10 17:50 ` Eric Dumazet
2011-08-11  5:50   ` Sreeram B S [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E436D89.6000201@netapp.com \
    --to=sreeramb@netapp.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.