Monday, May 7, 2007

HuaWeiClient under FreeBSD

I recently got mailed up by an Chinese student who wished to run the HuaWeiClient under FreeBSD. Though he could not compile it for two reasons:

A wrong pragma pack in the global.h header file. GCC 3.4.6 did not like it:
#pragma pack(push)
#pragma pack(1)

As GCC suggested:
warning: malformed '#pragma pack(push[, id], )' - ignored

I corrected it:
#pragma pack(push, 1)

And the code used some Linux specific ioctl() code named SIOCGIFHWADDR to get the mac address of the interfaces.
if (!(ioctl (fd, SIOCGIFHWADDR, (char *) &buf[i])))

I replaced it with the proper sysctl() calls:
if ( sysctl(mib, 6, 0, &len, 0, 0) == 0 )
{
buf = new char[len];
if ( sysctl(mib, 6, buf, &len, 0, 0) == 0 )
{
ifm = reinterpret_cast(buf);
sdl = reinterpret_cast(ifm+1);
ptr = reinterpret_cast(LLADDR(sdl));
// Now copy it into our destination buffer
for ( int j = 0; j < 6; ++j )
{
infoarray[i].macaddr[j] = (int)ptr[j];
}
}
}


I know... the struct keyword is not necessary or may be even not pure C++... but it is my style; go with it.
The patches are available for download here. Just download the original software from the SorceForge project site and extract it. Then download my patches and extract them into the directory where your HuaWeiClient sources are located and type the following into a shell:
$ patch global.h < global.h.patch
$ patch networkoperation.cpp < networkoperation.cpp.patch

After you have finished patching the source files, compile it as usual. By typing:
$ qmake
$ make

If the patches do not work for you, please feel free to contact me.

No comments: