Zen API
 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 
42 typedef k32s kIpAssignment;
43 
45 #define kIP_ASSIGNMENT_UNKNOWN (0)
46 #define kIP_ASSIGNMENT_AUTOMATIC (1)
47 #define kIP_ASSIGNMENT_MANUAL (2)
48 
56 typedef xkNetworkInfoFilter kNetworkAdapterType;
57 
59 #define kNETWORK_ADAPTER_ETHERNET (0x0001)
60 #define kNETWORK_ADAPTER_LOOPBACK (0x0002)
61 #define kNETWORK_ADAPTER_OTHER (0x0800)
62 #define kNETWORK_ADAPTER_OPTIONS (0xFFFF)
63 #define kNETWORK_ADAPTER_TYPE_FILTER_DEFAULT kNETWORK_ADAPTER_OPTIONS
64 #define kNETWORK_ADAPTER_TYPE_FILTER_NO_LOOPBACK (kNETWORK_ADAPTER_OPTIONS & ~kNETWORK_ADAPTER_LOOPBACK)
65 
73 typedef xkNetworkInfoFilter kNetworkAdapterState;
74 
76 #define kNETWORK_ADAPTER_STATE_DISABLED (0x0001)
77 #define kNETWORK_ADAPTER_STATE_ENABLED (0x0002)
78 #define kNETWORK_ADAPTER_STATE_OPTIONS (0x0003)
79 #define kNETWORK_ADAPTER_STATE_FILTER_DEFAULT kNETWORK_ADAPTER_STATE_ENABLED
80 
88 typedef struct kIpAddress
89 {
91  kByte address[16];
92 } kIpAddress;
93 
101 kFx(kIpAddress) kIpAddress_Any(kIpVersion version);
102 
110 
118 
127 
135 
146 kFx(kStatus) kIpAddress_Parse(kIpAddress* address, const kChar* text);
147 
157 kFx(kStatus) kIpAddress_Format(kIpAddress address, kChar* text, kSize capacity);
158 
168 
176 kFx(kBool) kIpAddress_IsLoopback(kIpAddress address);
177 
186 
194 kFx(k32u) kIpAddress_ToHost32u(kIpAddress address);
195 
203 kFx(k32u) kIpAddress_ToNet32u(kIpAddress address);
204 
212 kFx(kIpAddress) kIpAddress_FromHost32u(k32u address);
213 
221 kFx(kIpAddress) kIpAddress_FromNet32u(k32u address);
222 
231 kFx(kIpAddress) kIpAddress_Network(kIpAddress address, k32u prefixLength);
232 
242 kFx(kBool) kIpAddress_NetworkEquals(kIpAddress a, kIpAddress b, k32u prefixLength);
243 
250 typedef struct kIpEndPoint
251 {
254 } kIpEndPoint;
255 
257 #define kIP_PORT_ANY (0)
258 
261 #include <kApi/Io/kNetwork.x.h>
262 
269 //typedef kObject kNetworkInterface; --forward-declared in kApiDef.x.h
270 
279 {
280  kObj(kNetworkInterface, iface);
281  return obj->adapter;
282 }
283 
292 {
293  kObj(kNetworkInterface, iface);
294  return obj->address;
295 }
296 
305 {
306  kObj(kNetworkInterface, iface);
307  return obj->prefixLength;
308 }
309 
316 //typedef kObject kNetworkAdapter; --forward-declared in kApiDef.x.h
317 
326 {
327  kObj(kNetworkAdapter, adapter);
328  return obj->info;
329 }
330 
339 {
340  kObj(kNetworkAdapter, adapter);
341  return kString_Chars(obj->name);
342 }
343 
356 {
357  kObj(kNetworkAdapter, adapter);
358  return obj->id;
359 }
360 
372 {
373  kObj(kNetworkAdapter, adapter);
374  return obj->isEnabled;
375 }
376 
385 {
386  kObj(kNetworkAdapter, adapter);
387  return obj->isLinkRunning;
388 }
389 
398 {
399  kObj(kNetworkAdapter, adapter);
400  return obj->adapterType;
401 }
402 
413 {
414  kObj(kNetworkAdapter, adapter);
415  return obj->macAddress;
416 }
417 
426 {
427  kObj(kNetworkAdapter, adapter);
428  return obj->ipAssignment;
429 }
430 
439 {
440  kObj(kNetworkAdapter, adapter);
441  return kArrayList_Count(obj->interfaces);
442 }
443 
453 {
454  kObj(kNetworkAdapter, adapter);
455  return kArrayList_AsT(obj->interfaces, index, kNetworkInterface);
456 }
457 
468 {
469  kObj(kNetworkAdapter, adapter);
470  return kArrayList_ItemT(obj->interfaces, index, iface);
471 }
472 
479 //typedef kObject kNetworkInfo; --forward-declared in kApiDef.x.h
480 
490 {
491  return kNetworkInfo_ConstructEx(info, kNETWORK_ADAPTER_TYPE_FILTER_DEFAULT, kNETWORK_ADAPTER_STATE_FILTER_DEFAULT, alloc);
492 }
493 
494 #if defined(K_CPP)
495 
507 {
508  return kNetworkInfo_ConstructEx(info, typeFilter, stateFilter, alloc);
509 }
510 #endif
511 
520 
529 {
530  kObj(kNetworkInfo, info);
531  return kArrayList_Count(obj->adapters);
532 }
533 
543 {
544  kObj(kNetworkInfo, info);
545  return kArrayList_AsT(obj->adapters, index, kNetworkAdapter);
546 }
547 
556 {
557  kObj(kNetworkInfo, info);
558  return kArrayList_Count(obj->interfaces);
559 }
560 
570 {
571  kObj(kNetworkInfo, info);
572  return kArrayList_AsT(obj->interfaces, index, kNetworkInterface);
573 }
574 
584 kFx(kStatus) kNetworkInfo_FindAdapterByName(kNetworkInfo info, const kChar* name, kNetworkAdapter* adapter);
585 
596 
607 
618 
625 //typedef kObject kNetwork; --forward-declared in kApiDef.x.h
626 
647 kFx(kStatus) kNetwork_AddChangeHandler(kCallbackFx function, kPointer receiver);
648 
658 kFx(kStatus) kNetwork_RemoveChangeHandler(kCallbackFx function, kPointer receiver);
659 
672 kFx(kStatus) kNetwork_FindAdapterNameById(kSize adapterId, kChar* adapterName, kSize adapterNameCapacity);
673 
685 kFx(kStatus) kNetwork_FindAdapterIdByName(const kChar* adapterName, kSize* adapterId);
686 
699 kFx(kStatus) kNetwork_FindAdapterNameByInterface(kIpAddress interfaceAddress, kChar* adapterName, kSize adapterNameCapacity);
700 
712 kFx(kStatus) kNetwork_FindMacAdressByInterface(kIpAddress interfaceAddress, kMacAddress* macAddress);
713 
725 kFx(kStatus) kNetwork_FindFirstAdapterInterface(const kChar* adapterName, kIpAddress* interfaceAddress);
726 
738 kFx(kStatus) kNetwork_FindInterfaceByNetwork(kIpAddress network, kIpAddress* interfaceAddress);
739 
740 #endif
Represents a 32-bit unsigned integer.
kIpAddress kIpAddress_Any(kIpVersion version)
Gets an address representing an automatically-assigned address.
kIpAddress address
IP address.
Definition: kNetwork.h:252
Represents an Internet Protocol version.
#define kArrayList_ItemT(kArrayList_list, kSize_index, TPtr_item)
Gets the value of an item.
Definition: kArrayList.h:384
Represents the IP assignment.
Represents a void pointer.
k32u port
Port number.
Definition: kNetwork.h:253
kNetworkAdapter kNetworkInfo_AdapterAt(kNetworkInfo info, kSize index)
Gets the adapter at the specified index.
Definition: kNetwork.h:542
Represents network interface configuration information.
kIpAddress kIpAddress_Loopback(kIpVersion version)
Gets the loopback address.
kStatus kNetworkInfo_FindAdapterByName(kNetworkInfo info, const kChar *name, kNetworkAdapter *adapter)
Finds an adapter by name.
Declares the kString class.
kStatus kNetwork_FindInterfaceByNetwork(kIpAddress network, kIpAddress *interfaceAddress)
Finds the first interface address with subnet configuration that is compatible with the specified add...
Represents an unsigned integer that can store a pointer address.
Abstract base class for memory allocator types.
kIpAddress kIpAddress_Network(kIpAddress address, k32u prefixLength)
Extracts the network portion of an address.
kStatus kNetwork_FindAdapterNameById(kSize adapterId, kChar *adapterName, kSize adapterNameCapacity)
Finds the adapter name associated with a unique numeric adapter identifier.
#define kInlineFx(TYPE)
Inline method declaration helper.
Definition: kApiDef.h:29
Represents an IP address.
Definition: kNetwork.h:88
kNetworkAdapter kNetworkInterface_Adapter(kNetworkInterface iface)
Gets the adapter associated with this interface.
Definition: kNetwork.h:278
Represents a single unit (byte) in a UTF-8 character.
Represents a byte on the current platform.
kStatus kNetworkInfo_FindInterfaceByAddress(kNetworkInfo info, kIpAddress address, kNetworkInterface *iface)
Finds an interface by its exact local address.
kStatus kNetworkAdapter_InterfaceItem(kNetworkAdapter adapter, kSize index, kNetworkInterface *iface)
Gets the interface at the specified index, if present.
Definition: kNetwork.h:467
Represents network adapter configuration information.
kStatus kIpAddress_Format(kIpAddress address, kChar *text, kSize capacity)
Formats an IP address as a string.
kBool kNetworkAdapter_IsEnabled(kNetworkAdapter adapter)
Gets whether the adapter was enabled at the time of enumeration.
Definition: kNetwork.h:371
kSize kNetworkAdapter_Id(kNetworkAdapter adapter)
Gets the unique numeric ID associated with this adapter object.
Definition: kNetwork.h:355
kIpAddress kIpAddress_BroadcastV4()
Gets an address suitable for broadcasting IPv4 datagrams.
kStatus kNetwork_FindMacAdressByInterface(kIpAddress interfaceAddress, kMacAddress *macAddress)
Finds the MAC address associated with the specified interface address.
kStatus kNetwork_FindAdapterNameByInterface(kIpAddress interfaceAddress, kChar *adapterName, kSize adapterNameCapacity)
Finds the adapter name associated with the specified interface address.
kIpAddress kNetworkInterface_Address(kNetworkInterface iface)
Gets the IP address associated with this interface.
Definition: kNetwork.h:291
kStatus kNetworkInfo_Construct(kNetworkInfo *info, kAlloc alloc)
Constructs a network info object describing the current state of any local network adapters...
Definition: kNetwork.h:489
#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:3450
kStatus kNetwork_RemoveChangeHandler(kCallbackFx function, kPointer receiver)
Removes a network change notification handler.
kBool kIpAddress_Equals(kIpAddress a, kIpAddress b)
Compares two addresses for equality.
kNetworkInfo kNetworkAdapter_Info(kNetworkAdapter adapter)
Gets the network info object that owns this adapter object.
Definition: kNetwork.h:325
k32u kIpAddress_ToNet32u(kIpAddress address)
Converts an IPv4 address to a network-endian 32-bit integer.
kStatus kNetworkInfo_FindAdapterById(kNetworkInfo info, kSize id, kNetworkAdapter *adapter)
Finds an adapter by its unique numeric identifier.
kBool kIpAddress_NetworkEquals(kIpAddress a, kIpAddress b, k32u prefixLength)
Compares two addresses for network equality.
kSize kNetworkInfo_AdapterCount(kNetworkInfo info)
Reports the number of network adapters.
Definition: kNetwork.h:528
kChar * kString_Chars(kString str)
Returns a pointer to the internal character buffer.
Definition: kString.h:247
kStatus kNetwork_AddChangeHandler(kCallbackFx function, kPointer receiver)
Add a network change notification handler.
Core Zen type declarations.
kSize kArrayList_Count(kArrayList list)
Returns the current count of items in the list.
Definition: kArrayList.h:638
Represents a 32-bit signed integer.
Represents an Ethernet address.
Definition: kApiDef.h:1769
kBool kIpAddress_IsLoopback(kIpAddress address)
Reports whether the given address is a loopback address.
Represents network configuration information.
kNetworkInterface kNetworkInfo_InterfaceAt(kNetworkInfo info, kSize index)
Gets the interface at the specified index.
Definition: kNetwork.h:569
#define kArrayList_AsT(kArrayList_list, kSize_index, T)
Gets the value of an item.
Definition: kArrayList.h:417
kStatus(kCall * kCallbackFx)(kPointer receiver, kPointer sender, void *args)
Callback signature for a generic event handler.
Definition: kApiDef.h:1871
kIpAddress kIpAddress_LoopbackV4()
Gets the IpV4 loopback address.
kMacAddress kNetworkAdapter_MacAddress(kNetworkAdapter adapter)
Gets the current MAC address of the interface.
Definition: kNetwork.h:412
kSize kNetworkAdapter_InterfaceCount(kNetworkAdapter adapter)
Reports the number of interfaces associated with this adapter.
Definition: kNetwork.h:438
kIpVersion version
Address version.
Definition: kNetwork.h:90
kBool kIpAddress_IsLinkLocal(kIpAddress address)
Reports whether the given address is a link-local address.
kIpAddress kIpAddress_AnyV4()
Gets an address representing an automatically-assigned IPv4 address.
kBool kNetworkAdapter_IsLinkRunning(kNetworkAdapter adapter)
Gets whether the link (PHY) was running at the time of enumeration.
Definition: kNetwork.h:384
kStatus kIpAddress_Parse(kIpAddress *address, const kChar *text)
Parses a text-formatted IP address.
Represents an error code.
kByte address[16]
Address bytes (most significant byte first).
Definition: kNetwork.h:91
Represents an IP end point (address, port).
Definition: kNetwork.h:250
Represents the network adater state.
kNetworkAdapterType kNetworkAdapter_Type(kNetworkAdapter adapter)
Gets the adapter type.
Definition: kNetwork.h:397
kIpAddress kIpAddress_FromHost32u(k32u address)
Converts a host-endian 32-bit integer to an IPv4 address.
kSize kNetworkInfo_InterfaceCount(kNetworkInfo info)
Reports the total number of network interfaces across all adapters.
Definition: kNetwork.h:555
kNetworkInterface kNetworkAdapter_InterfaceAt(kNetworkAdapter adapter, kSize index)
Gets the interface at the specified index.
Definition: kNetwork.h:452
kStatus kNetwork_FindAdapterIdByName(const kChar *adapterName, kSize *adapterId)
Finds the unique numeric adapter identifier associated with an adapter name.
Represents the network adater type.
k32u kIpAddress_ToHost32u(kIpAddress address)
Converts an IPv4 address to a host-endian 32-bit integer.
Represents a boolean value.
k32u kNetworkInterface_PrefixLength(kNetworkInterface iface)
Gets the subnet prefix length associated with this interface.
Definition: kNetwork.h:304
kIpAssignment kNetworkAdapter_IpAssignment(kNetworkAdapter adapter)
Gets the current IP assignment method (automatic, manual, unknown) of the interface.
Definition: kNetwork.h:425
const kChar * kNetworkAdapter_Name(kNetworkAdapter adapter)
Gets the name associated with this adapter object.
Definition: kNetwork.h:338
kStatus kNetwork_FindFirstAdapterInterface(const kChar *adapterName, kIpAddress *interfaceAddress)
Finds the first interface address associated with an adapter name.
kStatus kNetworkInfo_FindInterfaceByNetwork(kNetworkInfo info, kIpAddress address, kNetworkInterface *iface)
Finds the first interface with subnet configuration that is compatible with the specified address...
kStatus kNetworkInfo_Refresh(kNetworkInfo info)
Updates network information.
kIpAddress kIpAddress_FromNet32u(k32u address)
Converts a network-endian 32-bit integer to an IPv4 address.