libimobiledevice / libimobiledevice-glue

A library with common code used by libraries and tools around the libimobiledevice project
GNU Lesser General Public License v2.1
86 stars 69 forks source link

Fixed compilation on msys #24

Closed mexmer closed 1 year ago

mexmer commented 1 year ago

when compiling on msys2, gcc doesn't define WIN32 (unless you use windows SDK, which i don't), i'm using default environment with cygwin64 compiler, therefore CYGWIN macro is defined.

nikias commented 1 year ago

Have you checked if get_primary_mac_address function works with your change?

mexmer commented 1 year ago

@nikias it works when compiling under msys2 didn't test other windows cygwin enviroments

tbh. msys2 is currently one of few still managed enviroments that works properly under windows 10.

i've been using cygwin for years and still have it on computer, but switched to msys few years ago, when compiling stuff, because it works better.

mexmer commented 1 year ago

ok, just tested under cygwin (either gcc-core or mingw64-gcc-core) and without my patch i get

socket.c:746:2: error: #error get_primary_mac_address is not supported on this platform.
  746 | #error get_primary_mac_address is not supported on this platform.

with patch it compiles and works.

mexmer commented 1 year ago

i can post full list of packages intalled in either environment if needed (for cygwin and msys2 that is)

nikias commented 1 year ago

I know that it compiles, but I want to know if the function is actually able to get the mac address.

mexmer commented 1 year ago

well, it does return some mac address Primary mac address: 00:00:00:ff:ea:7c closest match is VPN adapter mac 00-FF-EA-7C-C6-57 after expanding to 8 chars, it fully matches VPN adapter MAC, with addition of 00:00: at begining Primary mac address: 00:00:00:ff:ea:7c:c6:57

tested with simple code

#include "libimobiledevice-glue/socket.h"
#include <stdio.h>
main ()
{
    unsigned char primary_mac_addr[6] = { 0, 0, 0, 0, 0, 0 };

    if (get_primary_mac_address(primary_mac_addr) != 0)
        fprintf(stderr, "Cannot get primary mac");

    fprintf(stdout, "Primary mac address: %02x:%02x:%02x:%02x:%02x:%02x\n", primary_mac_addr[0], primary_mac_addr[1], primary_mac_addr[2], primary_mac_addr[3], primary_mac_addr[4], primary_mac_addr[5]);
}
mexmer commented 1 year ago

@nikias i can do more tests, and fix behavior of this function if needed. not sure if it's cygwin or 64bit windows thing, that it's 8 bytes, but it is, what it is.

mexmer commented 1 year ago

this PR missed few point so i changed code in better way that match getiffaddr function output on cygwin