I playing around with Apple's Reachabilitty
class in Swift.
The web server in my private Wi-Fi runs on http://10.0.0.1
. To check its reachability I want to use the following function from Reachability.h
(not the one with hostname):
/*!
* Use to check the reachability of a given IP address.
*/
+ (instancetype)reachabilityWithAddress:(const struct sockaddr *)hostAddress;
I sockaddr
looks accordingly to socket.h
like this:
/*
* [XSI] Structure used by kernel to store most addresses.
*/
struct sockaddr {
__uint8_t sa_len; /* total length */
sa_family_t sa_family; /* [XSI] address family */
char sa_data[14]; /* [XSI] addr value (actually larger) */
};
How can I create a sockaddr
struct with th ip address 10.0.0.1
in Swift?
I already read [here] something about UnsafePointer
and UnsafeMutablePointer
and that C arrays (or is it in this case an Objective-C array?) are represented as tuples in Swift, but I still don't know for sure how to work with them.