Add "tnet_get_mac_address()" function for Windows
This commit is contained in:
parent
e989621fe0
commit
40ec3479ad
|
@ -6,7 +6,7 @@
|
|||
#
|
||||
|
||||
AC_PREREQ([2.0])
|
||||
AC_INIT(libdoubango, 2.0.1305, doubango(at)googlegroups(dot)com)
|
||||
AC_INIT(libdoubango, 2.0.1311, doubango(at)googlegroups(dot)com)
|
||||
AC_CANONICAL_SYSTEM
|
||||
AM_INIT_AUTOMAKE([subdir-objects])
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
|
|
@ -74,6 +74,7 @@ typedef uint16_t tnet_port_t;
|
|||
typedef int tnet_family_t;
|
||||
typedef char tnet_host_t[NI_MAXHOST];
|
||||
typedef char tnet_ip_t[INET6_ADDRSTRLEN];
|
||||
typedef uint8_t tnet_mac_address[6];
|
||||
typedef unsigned char tnet_fingerprint_t[TNET_FINGERPRINT_MAX + 1];
|
||||
|
||||
typedef tsk_list_t tnet_interfaces_L_t; /**< List of @ref tnet_interface_t elements*/
|
||||
|
|
|
@ -367,8 +367,8 @@ tnet_addresses_L_t* tnet_get_addresses(tnet_family_t family, tsk_bool_t unicast,
|
|||
{
|
||||
tnet_addresses_L_t *addresses = tsk_list_create();
|
||||
|
||||
#if TSK_UNDER_WINDOWS
|
||||
#if TSK_UNDER_WINDOWS_RT
|
||||
#if TNET_UNDER_WINDOWS
|
||||
#if TNET_UNDER_WINDOWS_RT
|
||||
TSK_DEBUG_ERROR("Not implemented on your OS");
|
||||
#else /* !TSK_UNDER_WINDOWS_RT */
|
||||
|
||||
|
@ -633,6 +633,51 @@ bail:
|
|||
}
|
||||
|
||||
|
||||
/**@ingroup tnet_utils_group
|
||||
*/
|
||||
int tnet_get_mac_address(tnet_mac_address* address)
|
||||
{
|
||||
static const tsk_size_t __tnet_mac_address_len = sizeof(tnet_mac_address) / sizeof(uint8_t/*tnet_mac_address[0]*/);
|
||||
int ret = -1;
|
||||
if (!address) {
|
||||
TSK_DEBUG_ERROR("Invalid parameter");
|
||||
}
|
||||
#if TNET_UNDER_WINDOWS
|
||||
# if TNET_UNDER_WINDOWS_RT
|
||||
TSK_DEBUG_ERROR("Not implemented on your OS");
|
||||
# else /* !TSK_UNDER_WINDOWS_RT */
|
||||
{
|
||||
IP_ADAPTER_INFO *info = NULL, *pos;
|
||||
DWORD size = 0;
|
||||
ULONG _ret;
|
||||
|
||||
if ((_ret = GetAdaptersInfo(info, &size)) == ERROR_SUCCESS || _ret == ERROR_BUFFER_OVERFLOW) {
|
||||
info = (IP_ADAPTER_INFO *)tsk_calloc(size + 1, 1);
|
||||
if (info) {
|
||||
if ((_ret = GetAdaptersInfo(info, &size)) == ERROR_SUCCESS) {
|
||||
for (pos = info; pos != NULL && ret != 0; pos = pos->Next) {
|
||||
if (pos->Type == MIB_IF_TYPE_LOOPBACK && pos->Next) { // skip loopback if we still have items to check
|
||||
continue;
|
||||
}
|
||||
for (UINT i = 0; i < pos->AddressLength && i < __tnet_mac_address_len; ++i) {
|
||||
(*address)[i] = pos->Address[i];
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
TSK_FREE(info);
|
||||
}
|
||||
}
|
||||
# endif /* TSK_UNDER_WINDOWS_RT */
|
||||
#elif HAVE_IFADDRS_H && HAVE_GETIFADDRS
|
||||
#elif defined(SIOCGIFHWADDR)
|
||||
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**@ingroup tnet_utils_group
|
||||
* Retrieves the @a source IP address that has the best route to the specified IPv4 or IPv6 @a destination.
|
||||
* @param destination The destination address.
|
||||
|
|
|
@ -88,6 +88,7 @@ TINYNET_API tnet_addresses_L_t* tnet_get_addresses(tnet_family_t family, tsk_boo
|
|||
#define tnet_get_addresses_all_dnsservers() tnet_get_addresses(AF_UNSPEC, 0, 0, 0, 1, -1)
|
||||
#define tnet_get_addresses_dnsservers4() tnet_get_addresses(AF_INET, 0, 0, 0, 1, -1)
|
||||
#define tnet_get_addresses_dnsservers6() tnet_get_addresses(AF_INET6, 0, 0, 0, 1, -1)
|
||||
TINYNET_API int tnet_get_mac_address(tnet_mac_address* address);
|
||||
|
||||
TINYNET_API int tnet_getbestsource(const char* destination, tnet_port_t port, tnet_socket_type_t type, tnet_ip_t *source);
|
||||
TINYNET_API int tnet_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
|
||||
|
|
Loading…
Reference in New Issue