Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - sysctl net.inet.tcp.pcblist in our software: (3 Items)
   
sysctl net.inet.tcp.pcblist in our software  
Hi everyone !

I'm facing an issue in one program I'm currently writting. I need to get a list of all opened tcp sockets, their status 
and the local and remote port to where they are bind.
For this, I was thinking of using netbsd sysctl functionality. (We do not want to have netstat on our embedded system). 
This is the piece of code I did write to test it out:

    int mib[4];
    size_t namelen = 0;

    char temp[1000];
    size_t len = sizeof(temp);

    if (-1 == sysctlnametomib("net.inet.tcp.pcblist", mib, &namelen))
    {
    	LOG_SYSTEM_DEBUG("error: %d",errno);
    }
    if (-1 == sysctl(mib, namelen, &temp, &len, NULL, 0))
    {
    	LOG_SYSTEM_DEBUG("error: %d",errno);
    }

Unfortunately the second instruction fails and errno is set to 22 EINVAL. According to QNX documentation, this error 
happens when: "The name array is less than two or greater than CTL_MAXNAME entries long, or a non-NULL newp was given, 
and its specified length in newlen is too large or too small.". For me, this is not the case, everythings seems okay. 
Even if I replace &temp by NULL in the second call, in order to have the length required, it fails the same...

Do you have maybe any idea about this ?

Many thanks in advance, 

Daniel Peppicelli

Please be advised that this email may contain confidential 
information.  If you are not the intended recipient, please notify us 
by email by replying to the sender and delete this message.  The 
sender disclaims that the content of this email constitutes an offer 
to enter into, or the acceptance of, any agreement; provided that the 
foregoing does not invalidate the binding effect of any digital or 
other electronic reproduction of a manual signature that is included 
in any attachment.

Re: sysctl net.inet.tcp.pcblist in our software  
# sysctl net.inet.tcp.pcblist
sysctl: net.inet.tcp.pcblist: use 'netstat' or 'sockstat' to view this 
information

I believe netstat in turn uses the kvm interface, which is in kvm.h.

Regards,
/P

On 06/29/2011 01:11 PM, Daniel Peppicelli wrote:
>
> Hi everyone !
>
> I'm facing an issue in one program I'm currently writting. I need to 
> get a list of all opened tcp sockets, their status and the local and 
> remote port to where they are bind.
> For this, I was thinking of using netbsd sysctl functionality. (We do 
> not want to have netstat on our embedded system). This is the piece of 
> code I did write to test it out:
>
>     int mib[4];
>     size_t namelen = 0;
>
>     char temp[1000];
>     size_t len = sizeof(temp);
>
>     if (-1 == sysctlnametomib("net.inet.tcp.pcblist", mib, &namelen))
>     {
>         LOG_SYSTEM_DEBUG("error: %d",errno);
>     }
>     if (-1 == sysctl(mib, namelen, &temp, &len, NULL, 0))
>     {
>         LOG_SYSTEM_DEBUG("error: %d",errno);
>     }
>
> Unfortunately the second instruction fails and errno is set to 22 
> EINVAL. According to QNX documentation, this error happens when: "The 
> name array is less than two or greater than CTL_MAXNAME entries long, 
> or a non-NULL newp was given, and its specified length in newlen is 
> too large or too small.". For me, this is not the case, everythings 
> seems okay. Even if I replace &temp by NULL in the second call, in 
> order to have the length required, it fails the same...
>
> Do you have maybe any idea about this ?
>
> Many thanks in advance,
>
> Daniel Peppicelli
>
> Please be advised that this email may contain confidential
> information.  If you are not the intended recipient, please notify us
> by email by replying to the sender and delete this message.  The
> sender disclaims that the content of this email constitutes an offer
> to enter into, or the acceptance of, any agreement; provided that the
> foregoing does not invalidate the binding effect of any digital or
> other electronic reproduction of a manual signature that is included
> in any attachment.
>
>
>
>
>
> _______________________________________________
>
> General
> http://community.qnx.com/sf/go/post86946
>
RE: sysctl net.inet.tcp.pcblist in our software  
Thanks for this info ! It helps a lot!

I ask access to the source code of the networking project on Foundry27 a
few weeks ago, I'm now registred as part of the project but I can access
them...

Can you do me a favor and send me the sources of netstat implementation
for QNX... I'm struggling in trying to do the same than the FreeBSD
sources with kvm...

Cheers,

Daniel


-----Original Message-----
From: Patrik Lahti [mailto:community-noreply@qnx.com] 
Sent: mercredi 29 juin 2011 19:18
To: general-networking
Subject: Re: sysctl net.inet.tcp.pcblist in our software


# sysctl net.inet.tcp.pcblist
sysctl: net.inet.tcp.pcblist: use 'netstat' or 'sockstat' to view this
information

I believe netstat in turn uses the kvm interface, which is in kvm.h.

Regards,
/P

On 06/29/2011 01:11 PM, Daniel Peppicelli wrote:
>
> Hi everyone !
>
> I'm facing an issue in one program I'm currently writting. I need to 
> get a list of all opened tcp sockets, their status and the local and 
> remote port to where they are bind.
> For this, I was thinking of using netbsd sysctl functionality. (We do 
> not want to have netstat on our embedded system). This is the piece of

> code I did write to test it out:
>
>     int mib[4];
>     size_t namelen = 0;
>
>     char temp[1000];
>     size_t len = sizeof(temp);
>
>     if (-1 == sysctlnametomib("net.inet.tcp.pcblist", mib, &namelen))
>     {
>         LOG_SYSTEM_DEBUG("error: %d",errno);
>     }
>     if (-1 == sysctl(mib, namelen, &temp, &len, NULL, 0))
>     {
>         LOG_SYSTEM_DEBUG("error: %d",errno);
>     }
>
> Unfortunately the second instruction fails and errno is set to 22 
> EINVAL. According to QNX documentation, this error happens when: "The 
> name array is less than two or greater than CTL_MAXNAME entries long, 
> or a non-NULL newp was given, and its specified length in newlen is 
> too large or too small.". For me, this is not the case, everythings 
> seems okay. Even if I replace &temp by NULL in the second call, in 
> order to have the length required, it fails the same...
>
> Do you have maybe any idea about this ?
>
> Many thanks in advance,
>
> Daniel Peppicelli
>
> Please be advised that this email may contain confidential 
> information.  If you are not the intended recipient, please notify us 
> by email by replying to the sender and delete this message.  The 
> sender disclaims that the content of this email constitutes an offer 
> to enter into, or the acceptance of, any agreement; provided that the 
> foregoing does not invalidate the binding effect of any digital or 
> other electronic reproduction of a manual signature that is included 
> in any attachment.
>
>
>
>
>
> _______________________________________________
>
> General
> http://community.qnx.com/sf/go/post86946
>



_______________________________________________

General
http://community.qnx.com/sf/go/post86947



Please be advised that this email may contain confidential 
information.  If you are not the intended recipient, please notify us 
by email by replying to the sender and delete this message.  The 
sender disclaims that the content of this email constitutes an offer 
to enter into, or the acceptance of, any agreement; provided that the 
foregoing does not invalidate the binding effect of any digital or 
other electronic reproduction of a manual signature that is included 
in any attachment.