Mac network ping source code compile error

蹲街弑〆低调 提交于 2019-12-24 11:34:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!