现在想在iOS上支持SMB的客户端,目前找不到太多的资料。不知道是否可以做到
2条回答 默认 最新
- 烟台马大马 2018-05-08 01:29关注
目前移动端的客户端SMB库有libdsm这是一个C语言写的移动端客户端的SMB库。
我们的目标就是把libdsm编译成iOS端可以使用的.a静态库
现在大部分库都会做跨平台的依赖环境处理,所以基本上都会使用GUN的AutoTools工具来编译。这个也就很大程度上减少了我们来编译静态库的成本,基本编译过程为:./configure && make && make install
//我的Xcode是8.3的,iPhoneSDK是10.3
$ export CFLAGS="-arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -miphoneos-version-min=10.0 -fembed-bitcode -DNDEBUG -Wno-sign-compare"
//这里定义了CFLAGS这个标志,代表的我们使用的编译器相关的内容。//host: 交叉编译的库所运行的系统, prefix: 库存放位置,默认为/usr/local/P
$ ./configure --host=arm-apple-darwin --prefix=$PWD/^ld/arm64
//默认会打出静态包(.a)和分享包(.dylib)$ make && make install
//netbios_ns.h是用来搜寻局域网中的遵循NetBios接口的设备
//Swift File:
class Netbios {
var netbiosServer:OpaquePointer?//注1
func discoverNetbiosEntry(){
netbiosServer = netbios_ns_new() //netbios_ns_new为netbios_ns提供的初始化方法//创建一个callbacks的struct,struck是相通的 var callbacks:netbios_ns_discover_callbacks = netbios_ns_discover_callbacks() callbacks.p_opaque = Unmanaged.passUnretained(self).toOpaque()//将self转变为不透明指针的方法 //调用类方法的方法 callbacks.pf_on_entry_added = {p_op,netbios_entry in //将不透明指针转化为当前类,并且不增加计数 let mySelf = Unmanaged<Netbios>.fromOpaque(p_op!).takeUnretainedValue() //调用函数方法 mySelf.addEntry(p_op: p_op, netbios_entry: netbios_entry) } //注2 callbacks.pf_on_entry_removed = { p_op,netbios_entry in let enterName = String.init(cString: netbios_ns_entry_name(netbios_entry)) debugPrint("nox --add-- \(enterName)") } //有一部分C类型可以直接在Swift中表示,具体看注3 let timeOut:CUnsignedInt = 4 //netbios_ns_discover_start为netbios_ns提供的搜索接口 let result = netbios_ns_discover_start(netbiosServer, timeOut, &callbacks); debugPrint("nox -- discover-- come one \(result)"); } //回调函数,当有发现新的入口时,调用 func addEntry(p_op:UnsafeMutableRawPointer?, netbios_entry:OpaquePointer?) -> Void { let enterName = String.init(cString: netbios_ns_entry_name(netbios_entry)) let ipA = netbios_ns_entry_ip(netbios_entry) name.text = enterName + "\n" + ipA.description let addr = in_addr.init(s_addr: netbios_ns_entry_ip(netbios_entry)) //inet_ntoa为Drawing提供的方法,将uint32转化为ip地址 let ipAStr = String.init(cString: inet_ntoa(addr)) debugPrint("nox --add-- \(enterName) ip: \(ipAStr)") }
}
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报