C/C++ and Fortran

Expand all | Collapse all

Any C/C++ API to list all active connections on AIX(5-7)?

  • 1.  Any C/C++ API to list all active connections on AIX(5-7)?

    Posted Wed June 24, 2020 05:04 AM
    Edited by JING CHEN Wed June 24, 2020 06:32 AM
    Disclaimer: This post is migrated from IBM Developer Answers that is no longer in use. Its original author is ivan.shyiko, posted on Feb. 11, 2019.


    I need to get information about all active network connections on the system using C/C++(basically what the netstat command provides us). Basically I'm asking if there's any C/C++ netstat API available out there. If not, any place where I can get this data? I suppose it can also be read from the MIBs somehow, but I didn't manage to find documentation about it.

    Parsing netstat/lsof output is not an option.


    ---------------------------------------------------------------
    Question asked by ivan.shyiko on Feb. 11, 2019
    ----------------------------------------------------------------


  • 2.  RE: Any C/C++ API to list all active connections on AIX(5-7)?

    Posted Wed June 24, 2020 05:06 AM
    Edited by JING CHEN Wed June 24, 2020 06:32 AM

    This AIX C code lists the interfaces:

    https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_71/apis/getifaddrs.htm

    from there you can get detailed information for each interface by copying what netstat does:

    https://github.com/ecki/net-tools/blob/master/netstat.c

    or from "lsof -i", the lsof source rmp you can download from:

    http://www.perzl.org/aix/index.php%3Fn%3DMain.Lsof

    For the SNMP/MIB approach, peruse the OID's from: http://www.net-snmp.org/docs/mibs/interfaces.html


    -----------------------------------------------------------
    Answered by NiltonCastillo on Feb. 11, 2019
    -----------------------------------------------------------






  • 3.  RE: Any C/C++ API to list all active connections on AIX(5-7)?

    Posted Wed June 24, 2020 05:07 AM
    Edited by JING CHEN Wed June 24, 2020 07:36 AM
    The C code from the link provides only the network interfaces... I'm looking for API that would provide the same information as the netstat -an command(all active connections).


    ----------------------------------------------------
    Replied by ivan.shyiko on Feb. 11, 2019
    ----------------------------------------------------





  • 4.  RE: Any C/C++ API to list all active connections on AIX(5-7)?

    Posted Wed June 24, 2020 05:08 AM
    Edited by JING CHEN Wed June 24, 2020 06:36 AM

    In that case, just re-compile (or isolate the code from) lsof (it's in perzl, so it's open source)? https://github.com/aixoss/lsof

    not sure if this is something, but: HBA_GetPortAttributes has PortState


    -----------------------------------------------------------
    Answered by NiltonCastillo on Feb. 11, 2019
    -----------------------------------------------------------