Package org.hyperic.sigar

Examples of org.hyperic.sigar.NetConnection


        NetConnection[] connections = this.sigar.getNetConnectionList(flags);
        printf(HEADER);

        for (int i=0; i<connections.length; i++) {
            NetConnection conn = connections[i];
            String proto = conn.getTypeString();
            String state;

            if (conn.getType() == NetFlags.CONN_UDP) {
                state = "";
            }
            else {
                state = conn.getStateString();
            }

            ArrayList items = new ArrayList();
            items.add(proto);
            items.add(formatAddress(conn.getType(),
                                    conn.getLocalAddress(),
                                    conn.getLocalPort(),
                                    LADDR_LEN));
            items.add(formatAddress(conn.getType(),
                                    conn.getRemoteAddress(),
                                    conn.getRemotePort(),
                                    RADDR_LEN));
            items.add(state);

            String process = null;
            if (wantPid &&
                //XXX only works w/ listen ports
                (conn.getState() == NetFlags.TCP_LISTEN))
            {
                try {
                    long pid =
                        this.sigar.getProcPort(conn.getType(),
                                               conn.getLocalPort());
                    if (pid != 0) { //XXX another bug
                        String name =
                            this.sigar.getProcState(pid).getName();
                        process = pid + "/" + name;
                    }
View Full Code Here


        } catch (SigarException ex) {
            Logger.getLogger(NetStat.class.getName()).log(Level.SEVERE, null, ex);
        }

        for (int i = 0; i < connections.length; i++) {
            NetConnection conn = connections[i];
            NetStatObject netObj = new NetStatObject();

            String proto = conn.getTypeString();
            String state;
            if (conn.getType() == NetFlags.CONN_UDP) {
                state = "";
            } else {
                state = conn.getStateString();
            }


            netObj.setType(proto);
            netObj.setLocalAddress(formatAddress(conn.getType(),
                    conn.getLocalAddress(),
                    conn.getLocalPort(),
                    LADDR_LEN));
            netObj.setRemoteAddress(formatAddress(conn.getType(),
                    conn.getRemoteAddress(),
                    conn.getRemotePort(),
                    RADDR_LEN));
            netObj.setState(state);

            String process = null;
            if (wantPid &&
                    //XXX only works w/ listen ports
                    (conn.getState() == NetFlags.TCP_LISTEN)) {
                try {
                    long pid =
                            sigar.getProcPort(conn.getType(),
                            conn.getLocalPort());
                    if (pid != 0) { //XXX another bug
                        String name =
                                sigar.getProcState(pid).getName();
                        process = pid + "/" + name;
                    }
View Full Code Here

        NetConnection[] connections = this.sigar.getNetConnectionList(flags);
        printf(HEADER);

        for (int i=0; i<connections.length; i++) {
            NetConnection conn = connections[i];
            String proto = conn.getTypeString();
            String state;

            if (conn.getType() == NetFlags.CONN_UDP) {
                state = "";
            }
            else {
                state = conn.getStateString();
            }

            ArrayList items = new ArrayList();
            items.add(proto);
            items.add(formatAddress(conn.getType(),
                                    conn.getLocalAddress(),
                                    conn.getLocalPort(),
                                    LADDR_LEN));
            items.add(formatAddress(conn.getType(),
                                    conn.getRemoteAddress(),
                                    conn.getRemotePort(),
                                    RADDR_LEN));
            items.add(state);

            String process = null;
            if (wantPid &&
                //XXX only works w/ listen ports
                (conn.getState() == NetFlags.TCP_LISTEN))
            {
                try {
                    long pid =
                        this.sigar.getProcPort(conn.getType(),
                                               conn.getLocalPort());
                    if (pid != 0) { //XXX another bug
                        String name =
                            this.sigar.getProcState(pid).getName();
                        process = pid + "/" + name;
                    }
View Full Code Here

TOP

Related Classes of org.hyperic.sigar.NetConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.