I am trying to send pid_t type value from swift language application to kernel space through IOKit by using C++ library.
While I am printing 'pid_t' value in swift application it is showing proper value but it is not showing same value in C++ library function.
I have declared variable with type pid_t in both swift application and c++ library.
I tried same for other type variable like Int32 in swift and int in C++ library. Here values are showing properly.
Is there any difference between swift and C++ for pid_t type?
When you assign Swift String into fixed-sized char array of C, Swift compiler does not help and you may need to call strlcpy (or some other byte transfer function if appropriate) explicitly.But I am facing with compilation error
Something like this:
Code Block var event_info = ne_event_info_t( lport: Int32(localEndpoint.port) ?? 0, rport: Int32(remoteEndpoint.port) ?? 0, ip_size: Int32(remoteEndpoint.hostname.count), ip: (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0), //<- pid: flow.pid, direction: dir == 2 ? 1 : 0) //To set Swift String into `char` array of C, you need to call `strlcpy` _ = withUnsafeMutableBytes(of: &event_info.ip) {ipBuf in strlcpy(ipBuf.baseAddress!.assumingMemoryBound(to: Int8.self), remoteEndpoint.hostname, ipBuf.count) }