Wil Lai
Wil Lai

Reputation: 1

Decode SimplePing response packet in Swift

I am using SimplePing sample from Apple to ping to a host which successfully received a response from the framework delegate

 func simplePing(pinger: SimplePing!, didReceivePingResponsePacket packet: NSData!)

Which I am struggled to find the way to to decode the packet data (e.g. get the host name, ip)

I know that it's something about CFNetwork but I just can't find the right way to read the data, hope someone can help.

Upvotes: 0

Views: 818

Answers (2)

DiegoRivera
DiegoRivera

Reputation: 11

If anyone stumble upon this topic in pesent, like me. Host name or ip address can be found in pinger property. If that is what you looking for.

Example:

func simplePing(_ pinger: SimplePing, didReceivePingResponsePacket packet: Data, sequenceNumber: UInt16) {
    print("Host: \(pinger.hostName)")
}

Upvotes: 1

dgatwood
dgatwood

Reputation: 10407

The sample provides a method called icmpInPacket: that returns a broken-out struct. Use that. :-)

Upvotes: 0

Related Questions