问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/8776527/mac-network-ping-source-code-compile-error