Zen API

- Home
- Topics
- Types
- Files

All Classes Files Functions Variables Typedefs Friends Macros Modules Pages
kNetwork.h
Go to the documentation of this file.
1
10 #ifndef K_API_NETWORK_H
11 #define K_API_NETWORK_H
12
13 #include <kApi/kApiDef.h>
14 #include <kApi/Data/kString.h>
15
25 typedef k32s kIpVersion;
26
28 #define kIP_VERSION_4 (4)
29
37 typedef struct kIpAddress
38 {
39 kIpVersion version;
40 kByte address[16];
41 } kIpAddress;
42
50 kFx(kIpAddress) kIpAddress_Any(kIpVersion version);
51
58 kFx(kIpAddress) kIpAddress_AnyV4();
59
66 kFx(kIpAddress) kIpAddress_BroadcastV4();
67
75 kFx(kIpAddress) kIpAddress_Loopback(kIpVersion version);
76
83 kFx(kIpAddress) kIpAddress_LoopbackV4();
84
95 kFx(kStatus) kIpAddress_Parse(kIpAddress* address, const kChar* text);
96
106 kFx(kStatus) kIpAddress_Format(kIpAddress address, kChar* text, kSize capacity);
107
116 kFx(kBool) kIpAddress_Equals(kIpAddress a, kIpAddress b);
117
125 kFx(kBool) kIpAddress_IsLoopback(kIpAddress address);
126
134 kFx(kBool) kIpAddress_IsLinkLocal(kIpAddress address);
135
143 kFx(k32u) kIpAddress_ToHost32u(kIpAddress address);
144
152 kFx(k32u) kIpAddress_ToNet32u(kIpAddress address);
153
161 kFx(kIpAddress) kIpAddress_FromHost32u(k32u address);
162
170 kFx(kIpAddress) kIpAddress_FromNet32u(k32u address);
171
180 kFx(kIpAddress) kIpAddress_Network(kIpAddress address, k32u prefixLength);
181
191 kFx(kBool) kIpAddress_NetworkEquals(kIpAddress a, kIpAddress b, k32u prefixLength);
192
199 typedef struct kIpEndPoint
200 {
201 kIpAddress address;
202 k32u port;
203 } kIpEndPoint;
204
206 #define kIP_PORT_ANY (0)
207
210 #include <kApi/Io/kNetwork.x.h>
211
218 //typedef kObject kNetworkInterface; --forward-declared in kApiDef.x.h
219
227 kInlineFx(kNetworkAdapter) kNetworkInterface_Adapter(kNetworkInterface iface)
228 {
229 kObj(kNetworkInterface, iface);
230 return obj->adapter;
231 }
232
240 kInlineFx(kIpAddress) kNetworkInterface_Address(kNetworkInterface iface)
241 {
242 kObj(kNetworkInterface, iface);
243 return obj->address;
244 }
245
253 kInlineFx(k32u) kNetworkInterface_PrefixLength(kNetworkInterface iface)
254 {
255 kObj(kNetworkInterface, iface);
256 return obj->prefixLength;
257 }
258
265 //typedef kObject kNetworkAdapter; --forward-declared in kApiDef.x.h
266
274 kInlineFx(kNetworkInfo) kNetworkAdapter_Info(kNetworkAdapter adapter)
275 {
276 kObj(kNetworkAdapter, adapter);
277 return obj->info;
278 }
279
287 kInlineFx(const kChar*) kNetworkAdapter_Name(kNetworkAdapter adapter)
288 {
289 kObj(kNetworkAdapter, adapter);
290 return kString_Chars(obj->name);
291 }
292
304 kInlineFx(kSize) kNetworkAdapter_Id(kNetworkAdapter adapter)
305 {
306 kObj(kNetworkAdapter, adapter);
307 return obj->id;
308 }
309
320 kInlineFx(kBool) kNetworkAdapter_IsUp(kNetworkAdapter adapter)
321 {
322 kObj(kNetworkAdapter, adapter);
323 return obj->isUp;
324 }
325
333 kInlineFx(kSize) kNetworkAdapter_InterfaceCount(kNetworkAdapter adapter)
334 {
335 kObj(kNetworkAdapter, adapter);
336 return kArrayList_Count(obj->interfaces);
337 }
338
347 kInlineFx(kNetworkInterface) kNetworkAdapter_InterfaceAt(kNetworkAdapter adapter, kSize index)
348 {
349 kObj(kNetworkAdapter, adapter);
350 return kArrayList_AsT(obj->interfaces, index, kNetworkInterface);
351 }
352
362 kInlineFx(kStatus) kNetworkAdapter_InterfaceItem(kNetworkAdapter adapter, kSize index, kNetworkInterface* iface)
363 {
364 kObj(kNetworkAdapter, adapter);
365 return kArrayList_ItemT(obj->interfaces, index, iface);
366 }
367
374 //typedef kObject kNetworkInfo; --forward-declared in kApiDef.x.h
375
384 kFx(kStatus) kNetworkInfo_Construct(kNetworkInfo* info, kAlloc alloc);
385
393 kFx(kStatus) kNetworkInfo_Refresh(kNetworkInfo info);
394
402 kInlineFx(kSize) kNetworkInfo_AdapterCount(kNetworkInfo info)
403 {
404 kObj(kNetworkInfo, info);
405 return kArrayList_Count(obj->adapters);
406 }
407
416 kInlineFx(kNetworkAdapter) kNetworkInfo_AdapterAt(kNetworkInfo info, kSize index)
417 {
418 kObj(kNetworkInfo, info);
419 return kArrayList_AsT(obj->adapters, index, kNetworkAdapter);
420 }
421
429 kInlineFx(kSize) kNetworkInfo_InterfaceCount(kNetworkInfo info)
430 {
431 kObj(kNetworkInfo, info);
432 return kArrayList_Count(obj->interfaces);
433 }
434
443 kInlineFx(kNetworkInterface) kNetworkInfo_InterfaceAt(kNetworkInfo info, kSize index)
444 {
445 kObj(kNetworkInfo, info);
446 return kArrayList_AsT(obj->interfaces, index, kNetworkInterface);
447 }
448
458 kFx(kStatus) kNetworkInfo_FindAdapterByName(kNetworkInfo info, const kChar* name, kNetworkAdapter* adapter);
459
469 kFx(kStatus) kNetworkInfo_FindAdapterById(kNetworkInfo info, kSize id, kNetworkAdapter* adapter);
470
480 kFx(kStatus) kNetworkInfo_FindInterfaceByAddress(kNetworkInfo info, kIpAddress address, kNetworkInterface* iface);
481
491 kFx(kStatus) kNetworkInfo_FindInterfaceByNetwork(kNetworkInfo info, kIpAddress address, kNetworkInterface* iface);
492
499 //typedef kObject kNetwork; --forward-declared in kApiDef.x.h
500
521 kFx(kStatus) kNetwork_AddChangeHandler(kCallbackFx function, kPointer receiver);
522
532 kFx(kStatus) kNetwork_RemoveChangeHandler(kCallbackFx function, kPointer receiver);
533
546 kFx(kStatus) kNetwork_FindAdapterNameById(kSize adapterId, kChar* adapterName, kSize adapterNameCapacity);
547
559 kFx(kStatus) kNetwork_FindAdapterIdByName(const kChar* adapterName, kSize* adapterId);
560
573 kFx(kStatus) kNetwork_FindAdapterNameByInterface(kIpAddress interfaceAddress, kChar* adapterName, kSize adapterNameCapacity);
574
586 kFx(kStatus) kNetwork_FindFirstAdapterInterface(const kChar* adapterName, kIpAddress* interfaceAddress);
587
599 kFx(kStatus) kNetwork_FindInterfaceByNetwork(kIpAddress network, kIpAddress* interfaceAddress);
600
601 #endif
k32u
Represents a 32-bit unsigned integer.
kIpAddress::kIpAddress_Any
kIpAddress kIpAddress_Any(kIpVersion version)
Gets an address representing an automatically-assigned address.
kIpEndPoint::address
kIpAddress address
IP address.
Definition: kNetwork.h:201
kIpVersion
Represents an Internet Protocol version.
kArrayList::kArrayList_ItemT
#define kArrayList_ItemT(kArrayList_list, kSize_index, TPtr_item)
Gets the value of an item.
Definition: kArrayList.h:384
kPointer
Represents a void pointer.
kIpEndPoint::port
k32u port
Port number.
Definition: kNetwork.h:202
kNetworkInfo::kNetworkInfo_AdapterAt
kNetworkAdapter kNetworkInfo_AdapterAt(kNetworkInfo info, kSize index)
Gets the adapter at the specified index.
Definition: kNetwork.h:416
kNetworkAdapter::kNetworkAdapter_IsUp
kBool kNetworkAdapter_IsUp(kNetworkAdapter adapter)
Gets the current status of the interface.
Definition: kNetwork.h:320
kNetworkInterface
Represents network interface configuration information.
kIpAddress::kIpAddress_Loopback
kIpAddress kIpAddress_Loopback(kIpVersion version)
Gets the loopback address.
kNetworkInfo::kNetworkInfo_FindAdapterByName
kStatus kNetworkInfo_FindAdapterByName(kNetworkInfo info, const kChar *name, kNetworkAdapter *adapter)
Finds an adapter by name.
kString.h
Declares the kString class.
kNetwork::kNetwork_FindInterfaceByNetwork
kStatus kNetwork_FindInterfaceByNetwork(kIpAddress network, kIpAddress *interfaceAddress)
Finds the first interface address with subnet configuration that is compatible with the specified add...
kSize
Represents an unsigned integer that can store a pointer address.
kAlloc
Abstract base class for memory allocator types.
kIpAddress::kIpAddress_Network
kIpAddress kIpAddress_Network(kIpAddress address, k32u prefixLength)
Extracts the network portion of an address.
kNetwork::kNetwork_FindAdapterNameById
kStatus kNetwork_FindAdapterNameById(kSize adapterId, kChar *adapterName, kSize adapterNameCapacity)
Finds the adapter name associated with a unique numeric adapter identifier.
kInlineFx
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:26
kIpAddress
Represents an IP address.
Definition: kNetwork.h:37
kNetworkInterface::kNetworkInterface_Adapter
kNetworkAdapter kNetworkInterface_Adapter(kNetworkInterface iface)
Gets the adapter associated with this interface.
Definition: kNetwork.h:227
kChar
Represents a single unit (byte) in a UTF-8 character.
kByte
Represents a byte on the current platform.
kNetworkInfo::kNetworkInfo_FindInterfaceByAddress
kStatus kNetworkInfo_FindInterfaceByAddress(kNetworkInfo info, kIpAddress address, kNetworkInterface *iface)
Finds an interface by its exact local address.
kNetworkAdapter::kNetworkAdapter_InterfaceItem
kStatus kNetworkAdapter_InterfaceItem(kNetworkAdapter adapter, kSize index, kNetworkInterface *iface)
Gets the interface at the specified index, if present.
Definition: kNetwork.h:362
kNetworkAdapter
Represents network adapter configuration information.
kIpAddress::kIpAddress_Format
kStatus kIpAddress_Format(kIpAddress address, kChar *text, kSize capacity)
Formats an IP address as a string.
kNetworkAdapter::kNetworkAdapter_Id
kSize kNetworkAdapter_Id(kNetworkAdapter adapter)
Gets the unique numeric ID associated with this adapter object.
Definition: kNetwork.h:304
kIpAddress::kIpAddress_BroadcastV4
kIpAddress kIpAddress_BroadcastV4()
Gets an address suitable for broadcasting IPv4 datagrams.
kNetwork::kNetwork_FindAdapterNameByInterface
kStatus kNetwork_FindAdapterNameByInterface(kIpAddress interfaceAddress, kChar *adapterName, kSize adapterNameCapacity)
Finds the adapter name associated with the specified interface address.
kNetworkInterface::kNetworkInterface_Address
kIpAddress kNetworkInterface_Address(kNetworkInterface iface)
Gets the IP address associated with this interface.
Definition: kNetwork.h:240
kNetworkInfo::kNetworkInfo_Construct
kStatus kNetworkInfo_Construct(kNetworkInfo *info, kAlloc alloc)
Constructs a network info object describing the current state of any local network adapters...
kObj
#define kObj(TypeName_T, T_object)
Declares a local "obj" (this-pointer) variable and initializes it from a type-checked object handle...
Definition: kApiDef.h:2923
kNetwork::kNetwork_RemoveChangeHandler
kStatus kNetwork_RemoveChangeHandler(kCallbackFx function, kPointer receiver)
Removes a network change notification handler.
kIpAddress::kIpAddress_Equals
kBool kIpAddress_Equals(kIpAddress a, kIpAddress b)
Compares two addresses for equality.
kNetworkAdapter::kNetworkAdapter_Info
kNetworkInfo kNetworkAdapter_Info(kNetworkAdapter adapter)
Gets the network info object that owns this adapter object.
Definition: kNetwork.h:274
kIpAddress::kIpAddress_ToNet32u
k32u kIpAddress_ToNet32u(kIpAddress address)
Converts an IPv4 address to a network-endian 32-bit integer.
kNetworkInfo::kNetworkInfo_FindAdapterById
kStatus kNetworkInfo_FindAdapterById(kNetworkInfo info, kSize id, kNetworkAdapter *adapter)
Finds an adapter by its unique numeric identifier.
kIpAddress::kIpAddress_NetworkEquals
kBool kIpAddress_NetworkEquals(kIpAddress a, kIpAddress b, k32u prefixLength)
Compares two addresses for network equality.
kNetworkInfo::kNetworkInfo_AdapterCount
kSize kNetworkInfo_AdapterCount(kNetworkInfo info)
Reports the number of network adapters.
Definition: kNetwork.h:402
kString::kString_Chars
kChar * kString_Chars(kString str)
Returns a pointer to the internal character buffer.
Definition: kString.h:247
kNetwork::kNetwork_AddChangeHandler
kStatus kNetwork_AddChangeHandler(kCallbackFx function, kPointer receiver)
Add a network change notification handler.
kApiDef.h
Core Zen type declarations.
kArrayList::kArrayList_Count
kSize kArrayList_Count(kArrayList list)
Returns the current count of items in the list.
Definition: kArrayList.h:638
k32s
Represents a 32-bit signed integer.
kIpAddress::kIpAddress_IsLoopback
kBool kIpAddress_IsLoopback(kIpAddress address)
Reports whether the given address is a loopback address.
kNetworkInfo
Represents network configuration information.
kNetworkInfo::kNetworkInfo_InterfaceAt
kNetworkInterface kNetworkInfo_InterfaceAt(kNetworkInfo info, kSize index)
Gets the interface at the specified index.
Definition: kNetwork.h:443
kArrayList::kArrayList_AsT
#define kArrayList_AsT(kArrayList_list, kSize_index, T)
Gets the value of an item.
Definition: kArrayList.h:417
kCallbackFx
kStatus(kCall * kCallbackFx)(kPointer receiver, kPointer sender, void *args)
Callback signature for a generic event handler.
Definition: kApiDef.h:1737
kIpAddress::kIpAddress_LoopbackV4
kIpAddress kIpAddress_LoopbackV4()
Gets the IpV4 loopback address.
kNetworkAdapter::kNetworkAdapter_InterfaceCount
kSize kNetworkAdapter_InterfaceCount(kNetworkAdapter adapter)
Reports the number of interfaces associated with this adapter.
Definition: kNetwork.h:333
kIpAddress::version
kIpVersion version
Address version.
Definition: kNetwork.h:39
kIpAddress::kIpAddress_IsLinkLocal
kBool kIpAddress_IsLinkLocal(kIpAddress address)
Reports whether the given address is a link-local address.
kIpAddress::kIpAddress_AnyV4
kIpAddress kIpAddress_AnyV4()
Gets an address representing an automatically-assigned IPv4 address.
kIpAddress::kIpAddress_Parse
kStatus kIpAddress_Parse(kIpAddress *address, const kChar *text)
Parses a text-formatted IP address.
kStatus
Represents an error code.
kIpEndPoint
Represents an IP end point (address, port).
Definition: kNetwork.h:199
kIpAddress::kIpAddress_FromHost32u
kIpAddress kIpAddress_FromHost32u(k32u address)
Converts a host-endian 32-bit integer to an IPv4 address.
kNetworkInfo::kNetworkInfo_InterfaceCount
kSize kNetworkInfo_InterfaceCount(kNetworkInfo info)
Reports the total number of network interfaces across all adapters.
Definition: kNetwork.h:429
kNetworkAdapter::kNetworkAdapter_InterfaceAt
kNetworkInterface kNetworkAdapter_InterfaceAt(kNetworkAdapter adapter, kSize index)
Gets the interface at the specified index.
Definition: kNetwork.h:347
kNetwork::kNetwork_FindAdapterIdByName
kStatus kNetwork_FindAdapterIdByName(const kChar *adapterName, kSize *adapterId)
Finds the unique numeric adapter identifier associated with an adapter name.
kIpAddress::kIpAddress_ToHost32u
k32u kIpAddress_ToHost32u(kIpAddress address)
Converts an IPv4 address to a host-endian 32-bit integer.
kBool
Represents a boolean value.
kNetworkInterface::kNetworkInterface_PrefixLength
k32u kNetworkInterface_PrefixLength(kNetworkInterface iface)
Gets the subnet prefix length associated with this interface.
Definition: kNetwork.h:253
kNetworkAdapter::kNetworkAdapter_Name
const kChar * kNetworkAdapter_Name(kNetworkAdapter adapter)
Gets the name associated with this adapter object.
Definition: kNetwork.h:287
kNetwork::kNetwork_FindFirstAdapterInterface
kStatus kNetwork_FindFirstAdapterInterface(const kChar *adapterName, kIpAddress *interfaceAddress)
Finds the first interface address associated with an adapter name.
kNetworkInfo::kNetworkInfo_FindInterfaceByNetwork
kStatus kNetworkInfo_FindInterfaceByNetwork(kNetworkInfo info, kIpAddress address, kNetworkInterface *iface)
Finds the first interface with subnet configuration that is compatible with the specified address...
kNetworkInfo::kNetworkInfo_Refresh
kStatus kNetworkInfo_Refresh(kNetworkInfo info)
Updates network information.
kIpAddress::kIpAddress_FromNet32u
kIpAddress kIpAddress_FromNet32u(k32u address)
Converts a network-endian 32-bit integer to an IPv4 address.