如何在 MAC 中以编程方式设置 VPN 连接?

发布于 2024-11-29 06:55:59 字数 336 浏览 1 评论 0原文

经过一段时间的搜索,我发现在 mac 中以编程方式建立 VPN 连接的唯一最佳来源是

http://lists.apple.com/archives/Macnetworkprog/2011/May/msg00032.html

但我很震惊编码时的第五点是关于 kSCNetworkProtocolTypePPP 的,但没有这样的事情......

有人做到了,如上面的链接所示 或者还有其他可用的来源吗...?

after searching for a while i found that the only best source available to establish a vpn connection programmatically in mac is at

http://lists.apple.com/archives/Macnetworkprog/2011/May/msg00032.html

but i was struck at the 5th point while coding which says about kSCNetworkProtocolTypePPP and there is no such thing...

has anybody done it as shown in the above link
or is there any other source available...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忆依然 2024-12-06 06:55:59

但我在编码时看到第五点,其中提到了 kSCNetworkProtocolTypePPP,但没有这样的事情......

不需要获取 PPP 协议,您可以将设置直接应用到您创建的界面。如果您创建了这样的界面:

interface = SCNetworkInterfaceCreateWithInterface(bottomInterface, kSCNetworkInterfaceTypePPP);

您可以直接使用 PPP 选项:

SCNetworkInterfaceSetConfiguration(interface, myOptions)

您必须使用以下方式应用共享密钥

SCNetworkInterfaceSetExtendedConfiguration(interface, CFSTR("IPSec"), myOptions)

如果您想启用“通过 VPN 发送所有流量”,您需要通过以下方式应用这些设置:首先获取 IPv4 协议:

SCNetworkProtocolRef protocol = SCNetworkServiceCopyProtocol(service, kSCNetworkProtocolTypeIPv4);
SCNetworkProtocolSetConfiguration(protocol, myOptions)

此答案中提到的源代码提取自 https://github.com/halo/macosvpn/blob/master/macosvpn/Classes/VPNController.m 您可以在其中找到完整内容。

but i was struck at the 5th point while coding which says about kSCNetworkProtocolTypePPP and there is no such thing...

There is no need to fetch the PPP protocol, you can apply the settings directly to the interface you created. If you created the interface like this:

interface = SCNetworkInterfaceCreateWithInterface(bottomInterface, kSCNetworkInterfaceTypePPP);

you can apply the PPP options directly using:

SCNetworkInterfaceSetConfiguration(interface, myOptions)

You'll have to apply the shared secret using

SCNetworkInterfaceSetExtendedConfiguration(interface, CFSTR("IPSec"), myOptions)

And if you want to enable "Send all traffic over VPN", you'll need to apply those settings by fetching the IPv4 protocol first:

SCNetworkProtocolRef protocol = SCNetworkServiceCopyProtocol(service, kSCNetworkProtocolTypeIPv4);
SCNetworkProtocolSetConfiguration(protocol, myOptions)

The source code mentioned in this answer was extracted from https://github.com/halo/macosvpn/blob/master/macosvpn/Classes/VPNController.m where you can find it in its entirety.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文