Comments (3)
Please provide additional details about your use of fping
.
from fping.
Hi @auerswal
Thank you for the reply. Please find the usage of fping in the following code. Passing array of hosts to the ping operation in the background queue async way with arguments as below.
`/// Send ping with completion block.
///
/// - Parameters:
/// - hosts: hosts
/// - backoff: default 1.5
/// - count: number of ping send per host
/// - completion: results dictionary, the key is host string, the value is PngResult struct
public static func ping(hosts: [String], backoff: Float = 1.5, count: Int = 1,
progress: ((_ progress: (Float)) -> Void)? = nil,
completion: @escaping (_ results: [String: PngResult]) -> Void) {
let argv:[String?] = ["", "-c\(count)", "-B\(backoff)", "-q"] + hosts + [nil]
var cargs = argv.map { $0.flatMap { UnsafeMutablePointer<Int8>(strdup($0)) } }
let observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "fpingxProgress"), object: nil, queue: OperationQueue()) { (notification) in
if let p = notification.userInfo!["progress"] as? Float {
progress?(p > 1 ? 1 : p)
}
}
DispatchQueue.global(qos: .background).async {
let resultsArrarPtr = fping(Int32(argv.count), &cargs, progressCCallback)!
var hostPtr = resultsArrarPtr.pointee
var results: [String: PngResult] = [:]
while (hostPtr != nil) {
let h = hostPtr!.pointee
let host = String(cString: h.host)
let result = PngResult(host: host, xmt: Int(h.num_sent), rcv: Int(h.num_recv), avg: h.num_recv > 0 ? Float(h.total_time / h.num_recv / 100) : nil, min: h.num_recv > 0 ? Int(h.min_reply / 100) : nil, max: h.num_recv > 0 ? Int(h.max_reply / 100) : nil, jitt: (h.jitter / Float(count)))
results[host] = result
let freeNode = hostPtr
hostPtr = hostPtr?.pointee.ev_next
free(UnsafeMutableRawPointer(freeNode))
}
free(UnsafeMutablePointer(resultsArrarPtr))
completion(results)
NotificationCenter.default.removeObserver(observer)
for ptr in cargs { free(UnsafeMutablePointer(ptr)) }
}
}`
from fping.
The error looks as if you created a too restrictive environment for fping
to work.
from fping.
Related Issues (20)
- -g option not working properly HOT 3
- fping ipv6 address -g not working
- Warning when using autoconf from version 2.62 and 2.70 HOT 2
- Architectures support
- fping -n -g x.x.x.x/24 hangs with systemd-resolved HOT 3
- not enough sequence numbers available! (expire_timeout=10000000000, host_nr=0, ping_count=0, seqmap_next_id=0) HOT 9
- Combinations "-c -a" and "-c -u" give same output as combination "-c -q" instead of just "-c"
- Inconsistent limits for address generation via `-g`, `--generator` using either range or CIDR HOT 4
- No error message when `getprotobyname()` fails HOT 1
- Time of execution when using retry -r increases in a nonlinear growth HOT 2
- errors on fping version 5.1 HOT 4
- -D, --timestamp with custom time string eq: %Y-%m-%d %H:%M:%S HOT 9
- fping6 issue with multiple addresses HOT 1
- Is it possible to provide official portable build ?
- Fix code scanning alert - Incorrect return-value check for a 'scanf'-like function HOT 1
- packet loss after 8-10 targets HOT 2
- github ci unreliable test on macOS
- VSCode debugging does not work requires root rights HOT 2
- Test `ci/test-11-unpriv.pl` uses hard-coded copy destination and does not clean up afterwards HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fping.