/** * @param devName devName * @return an {@link org.pcap4j.util.Inet4NetworkAddress Inet4NetworkAddress} object. * @throws PcapNativeException if an error occurs in the pcap native library. */ public static Inet4NetworkAddress lookupNet(String devName) throws PcapNativeException { if (devName == null) { StringBuilder sb = new StringBuilder(); sb.append("devName: ").append(devName); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); IntByReference netp = new IntByReference(); IntByReference maskp = new IntByReference(); int rc = NativeMappings.pcap_lookupnet(devName, netp, maskp, errbuf); if (rc < 0) { throw new PcapNativeException(errbuf.toString(), rc); } int net = netp.getValue(); int mask = maskp.getValue(); return new Inet4NetworkAddress(Inets.itoInetAddress(net), Inets.itoInetAddress(mask)); }
/** * @param devName devName * @return an {@link org.pcap4j.util.Inet4NetworkAddress Inet4NetworkAddress} object. * @throws PcapNativeException if an error occurs in the pcap native library. */ public static Inet4NetworkAddress lookupNet(String devName) throws PcapNativeException { if (devName == null) { StringBuilder sb = new StringBuilder(); sb.append("devName: ").append(devName); throw new NullPointerException(sb.toString()); } PcapErrbuf errbuf = new PcapErrbuf(); IntByReference netp = new IntByReference(); IntByReference maskp = new IntByReference(); int rc = NativeMappings.pcap_lookupnet(devName, netp, maskp, errbuf); if (rc < 0) { throw new PcapNativeException(errbuf.toString(), rc); } int net = netp.getValue(); int mask = maskp.getValue(); return new Inet4NetworkAddress(Inets.itoInetAddress(net), Inets.itoInetAddress(mask)); }