Mac network ping source code compile error - c

I download the Mac OS network ping source code from Apple: http://www.opensource.apple.com/tarballs/network_cmds/network_cmds-356.8.tar.gz
and compile it in xcode, but get errors in both 10.7 and 10.6,
'IP_NO_IFT_CELLULAR' undeclared (first use in this function)
'SO_TRAFFIC_CLASS' undeclared (first use in this function)
'SO_RECV_TRAFFIC_CLASS' undeclared (first use in this function)
'SO_TRAFFIC_CLASS' undeclared (first use in this function)
Did I miss something?

I thought it was possible that you needed to import a networking framework into your project, but Apple doesn't provide any description or information about the project you've downloaded.
For posterity's sake:
To add frameworks, select the project in the top left, then click your target, pick 'Build Phases' from the top of the resulting page, 'Link Binary With Libraries', '+'.
I finally managed to get it to build after exhaustive googling by adding the following to the ping.c file (the one flagged with the errors):
#define IP_NO_IFT_CELLULAR 6969 /* for internal use only */
#define IP_NO_IFT_PDP IP_NO_IFT_CELLULAR /* deprecated */
#define SO_TRAFFIC_CLASS 0x1086 /* Traffic class (int)*/
#define SO_RECV_TRAFFIC_CLASS 0x1087 /* Receive traffic class (bool)*/
Which amusingly came from other open source Apple projects that Google had indexed.

Related

SIZEOF_UNSIGNED_CHAR header file or package in ubuntu(linux)?

I use ubuntu 20.04, when I compile an header file of code,I have error:
../../../../../../src/tool/omniidl/cxx/cccp/config.h:80:23: error: ‘SIZEOF_UNSIGNED_CHAR’ undeclared (first use in this function)
80 | #define BITS_PER_UNIT SIZEOF_UNSIGNED_CHAR
I just want to know which header file or which Linux package contains SIZEOF_UNSIGNED_CHAR defined?
It's 1 as it's the smallest unit you can use. If you prefer not to write #define ... 1 you can use sizeof.
I recommend you to read this, it's an interesting page.

Preprocessor: error: missing binary operator before token "("

we're curruntly working on a C project and we've downloaded and used the header dirent.h, the problem is the code was compiled successfully on my teammate laptop but in mine it doesn't compile, telling me this :
In file included from utils.c:6:0:
dirent.h: In function '_wopendir':
dirent.h:383:28: error: missing binary operator before token "("
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
^
dirent.h:405:28: error: missing binary operator before token "("
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
^
dirent.h:413:5: warning: implicit declaration of function 'wcsncpy_s' [-Wimplicit-function-declaration]
wcsncpy_s (dirp->patt, n+1, dirname, n);
^
I searched for the problem and find that it's a preproccessor error and currently on the #if
i've tried to add #define WINAPI_FAMILY_PARTITION(Partitions) but it doesn't work.
Please suggest me a solution to compile it successfully, and does the windows version affect on preprocessing?
WINAPI_FAMILY_PARTITION is defined in <winapifamily.h>, probably included by <windows.h>. Look at this question for more explanations, but windows intricacies are largely irrelevant for your compilation issue. You might want include <windows.h> before <dirent.h>?
You did not publish the source code for your program, nor did you specify what OS you compile for not what compiler you use, but you mention we've downloaded and used the header dirent.h... This sounds wrong: system include files such as <dirent.h> are automatically installed with the compiler, they are specific to the OS and compiler, you cannot just download one from the net and expect it to work on your system. It might work by chance on your teammate's PC because the OS might be different.

glib : glib 2.5 installation issue

I am working on Red Hat 6 with kernal version 2.6.32 , I am trying build glib 2.5 on my machine. And fail with following error:-
Log:-
../../gio/gfile.c: In function ‘splice_stream_with_progress’:
../../gio/gfile.c:3019: error: ‘F_SETPIPE_SZ’ undeclared (first use in this function)
../../gio/gfile.c:3019: error: (Each undeclared identifier is reported only once
../../gio/gfile.c:3019: error: for each function it appears in.)
../../gio/gfile.c:3023: error: ‘F_GETPIPE_SZ’ undeclared (first use in this function)
make[4]: *** [libgio_2_0_la-gfile.lo] Error 1
I can find the solution of at F_SETPIPE_SZ undeclared , placing #define _GNU_SOURCE before all includes in file gfile.c, But it didn't work. As mentioned in second answer: Older kernels (e.g. 2.6.32 as used in RHEL6) don't have them and we need bypass it in whatever you're building. How could we do that?
Appreciate your help .
Thanks in Advance.
The bug is fixed in this commit.
architectures without F_SETPIPE_SZ and F_GETPIPE_SZ such as or1k.
If those variables are undefined, put back previous behavior, buffer
size set to 1024 * 64
https://gitlab.gnome.org/GNOME/glib/-/commit/0beb62f564072f3585762c9c55fe894485993b62
You can apply the patch to your code.

How to get IP addresses of all interfaces on OS X using C

I am porting code from linux to OS X where I am getting these errors:
src/proxy_linux.c:784: error: 'SIOCGIFHWADDR' undeclared (first use in this function)
src/proxy_linux.c:784: error: (Each undeclared identifier is reported only once
src/proxy_linux.c:784: error: for each function it appears in.)
src/proxy_linux.c:788: error: 'struct ifreq' has no member named 'ifr_hwaddr'
I am using Mac OS X 10.7.5 (11G63) ) as development system.
SIOCGIFHWADDR is not supported on OS X and I am not able to find any credible source which can list out the ip addresses and MAC addresses of all interfaces. The only one I found on apple developer site uses "IOKit", which is also not backward compatible. Any help in this regard will be appreciated
If Sandbox or App Store is not involved you can parse the output of ifconfig -a yourself and extract the addresses. If so, well, you are out of luck as Apple won't allow this for privacy reasons.

Unknown type name - 'DEV_BROADCAST_DEVICEINTERFACE' in MINGW

I took this code
as example to write a service. And I made some changes in my main function in such a way to work with command line parameters and removed
#define UNICODE
#define WINVER 0x502
Am using "MINGW".
Am getting the following errors:
usb_detect.c: In function 'ServiceMain':
usb_detect.c:123:16: error: unknown type name 'DEV_BROADCAST_DEVICEINTERFACE'
usb_detect.c:132:41: error: request for member 'dbcc_size' in something not a structure or union
usb_detect.c:132:61: error: 'DEV_BROADCAST_DEVICEINTERFACE' undeclared (first use in this function)
usb_detect.c:132:61: note: each undeclared identifier is reported only once for each function it appears in
usb_detect.c:133:41: error: request for member 'dbcc_devicetype' in something not a structure or union
usb_detect.c:133:60: error: 'DBT_DEVTYP_DEVICEINTERFACE' undeclared (first use in this function)
usb_detect.c:136:117: error: 'DEVICE_NOTIFY_SERVICE_HANDLE' undeclared (first use in this function)
usb_detect.c:136:148: error: 'DEVICE_NOTIFY_ALL_INTERFACE_CLASSES' undeclared (first use in this function)
If I uncomment the unicode and winver there are no errors, but command line parameters are not working..
I included dbt.h too..
The DEV_BROADCAST_DEVICEINTERFACE structure is only supported on Windows XP and later (as well as some of the other APIs that this code relies upon). It won't be defined in the Windows headers unless you're targeting that version of Windows or later.
To make sure that it's defined, you need to explicitly specify your target version of Windows at the top of your header file before you include Windows.h.
The typical pattern looks something like this:
#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_WINXP
#include <SDKDDKVer.h>
The original version of the code you tried had this line, which you removed:
#define WINVER 0x502
That explicitly set the target Windows version to Windows Server 2003 (Windows NT v5.2). Removing it means that you revert to the lowest common denominator, which is a version of Windows prior to XP, where the DEV_BROADCAST_DEVICEINTERFACE structure is not defined.
It's also not clear why you're removing the UNICODE define. It's 2012—any app you're building should be targeting Unicode. Leave that defined as well.

Resources