[Ns-bugs] [Bug 283] getsockname implementation needs support in socket base class
bugzilla-daemon@nsnam-www.ece.gatech.edu
bugzilla-daemon at nsnam-www.ece.gatech.edu
Sat Sep 6 23:16:21 PDT 2008
http://www.nsnam.org/bugzilla/show_bug.cgi?id=283
------- Comment #9 from liujatp at gmail.com 2008-09-07 02:16 -------
i know what has happend after reading kernel code.
when getsockname() was called without bind(), linux kernel fill the struct
sockaddr with the initial value(memset with zero), then it call
move_addr_to_user() to fill the userspace sockaddr by the input namelen.
so,
if the input namelen == 0, the output sockaddr not changed,
if the input namelen == sizeof(sockaddr), the output sockaddr were all zero,
if the input namelen (0, sizeof(sockaddr)), the output sockaddr partly zero,
partly not changed.
At the NS3 side, GetSockName return address value by 0, when called before
bind().
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > Created an attachment (id=237)
--> (http://www.nsnam.org/bugzilla/attachment.cgi?id=237&action=view) [details] [details] [details]
> > > Socket::GetSockName patch
> > >
> > > thanks methieu's comments, i did some test calling getsockname before bind, the
> > > output sockaddr was same to the input.
> >
> > can you show me the code you used to test this ?
>
> And the reason I am asking this is that I wrote the following code and it shows
> that getsockname does not return the the input address: it returns ip=0.0.0.0,
> port=0, and family = AF_INET
>
> #include <sys/socket.h>
> #include <netinet/in.h>
> #include <stdio.h>
>
> int main (int argc, char *argv[])
> {
> struct sockaddr_in name;
> socklen_t namelen;
> int fd = socket (AF_INET, SOCK_STREAM, 0);
>
> namelen = sizeof (struct sockaddr);
> name.sin_family = 0xff;
> name.sin_port = 0xffff;
> name.sin_addr.s_addr = 0xffffffff;
> int retval = getsockname (fd, (struct sockaddr *)&name, &namelen);
>
> if (name.sin_family != AF_INET)
> {
> printf ("family error\n");
> }
> printf ("port=%d\n", name.sin_port);
> printf ("ad=%d\n", name.sin_addr.s_addr);
>
> return 0;
> }
>
--
Configure bugmail: http://www.nsnam.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the Ns-bugs
mailing list