跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Rust] 学习 Rust 做了个模拟自动应答机的小玩具

发表于

https://github.com/libook/net-ssr

把树莓派接入了一个网络,但不知道它被分配到了什么 IP ,需要接显示器或者做个自动上报 IP 。

当然要想解决我的问题有很多方法,但我只是想写写代码玩玩。

突发奇想做个自动应答机。树莓派上跑一个应答端,我在电脑上装个询问端,询问端在网络内广播 UDP 数据,应答机收到后自动应答自己的 IP 和 hostname 。

探索了一下 Rust 中的回调函数实现方式、clap 命令行库、build.rs 脚本的用法,对 Rust 的 crate 和 mod 机制有了更多的了解。

比如需要 build.rs 共用 src 里的一些代码的时候,尝试了 include!宏直接引入包含共享代码的文件,会产生一些难以解决的 dead code warning ;尝试了将共用代码分成独立 crate 再从 build.rs 和程序里 use ,但拆分出来的 crate 必须要单独 publish 而不能被携带在主 crate 的源代码中;尝试了软连接但是对 Windows 的兼容性可能不好。最终我发现了有人使用#[path=]这个属性在 build.rs 中引入共享代码,尝试了一下完美解决 dead code warning 的问题。

再比如 bin 入口文件中直接使用 mod 指令引入其他非 lib.rs 文件也会出现 dead code warning ,貌似 rust 编译器推荐所有库文件都最好在 lib.rs 中 pub mod 出来,再给 bin 入口文件引入使用。

这个程序在 Windows 上编译需要 Packet.lib ,要安装 Npcap ,完全不熟悉 Windows 的环境变量和链接库机制,调试环境变量调试了好久……

Featured Replies

没有可显示的帖子

创建帐户或登录来提出意见

Account

导航

搜索

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.