Can we create socket device ?
amit-bst opened this issue · comments
Hi,
I was trying to create a socket device
In getVMConfig function :-
VZVirtioSocketDeviceConfiguration *socketVirtioConf = [[VZVirtioSocketDeviceConfiguration alloc] init];
NSArray *socketVirtioArray = [NSArray arrayWithObject:socketVirtioConf];
[conf setSocketDevices:socketVirtioArray];
In main after VZVirtualMachine init
VZVirtioSocketDevice *socketDevice = (VZVirtioSocketDevice *)[vm.socketDevices objectAtIndex:0]
I am able to get the socketDevice. But when i try to call [socketDevice setSocketListener:listener forPort:19923]; I get illegal hardware exception. Can you help me out ?
Same here. Are you using an M1 or Intel Mac?
@amit-bst @JonasGessner It took me a long time to figure this out. I had the same problem, but I was able to get passed this: what you need to pay attention to is that the setSocketListener:forPort:
call must be performed on the same dispatch queue as all the other calls that interact with the virtual machine.
However, after I passed this point, I still have no clue on how to actually access connections. I have a delegate object for the listener (VZVirtioSocketListenerDelegate), but the protocol only has one method which says if you want to allow or reject connections. But I don't see any way to actually access the connection once I return true from there. (And trying to access the file descriptor from the object as passed into the function give me a bad file descriptor error.)
@mheese yes that was the issue, we were able to move forward, sorry forgot to post it here. Thank you so much !!
@amit-bst were you able to use the listener though? I still can't figure this out...
If you initialized VZVirtualMachine with the initWithConfiguration:queue:
method, you need to call those methods on the same dispatch queue which is used when initialization.
Sorry for hijacking the thread, has anyone has any success implementing a VZVirtioSocketListenerDelegate
in swift? I can get the connection in but it gets abruptly closed in the VM before it can write any date.
@dmarkey @mheese Could you guys figure out how to open the connection to the VM? Anything I do, when I call connect(toPort:, completionHandler:)
I get "Error Domain=NSPOSIXErrorDomain Code=54 "Connection reset by peer".
I start to suspect, that the setSocketListener:forPort
part have to be run inside of the VM as a "guest application" listener, and call connect
from the host application, but I have no idea how to reference the VZVirtualMachine from code within the actual Virtual Machine. I am stuck.
I wouldn't even need this whole setSocketListener:forPort
/ connect(toPort:, completionHandler:)
memery, if Apple would provide an easy way to get the VM's ip address
I wouldn't even need this whole
setSocketListener:forPort
/connect(toPort:, completionHandler:)
memery, if Apple would provide an easy way to get the VM's ip address
I don't know if there's an official API/documentation for this, but you can go from VM mac address to IP rather easily by parsing /var/db/dhcpd_leases
I wouldn't even need this whole
setSocketListener:forPort
/connect(toPort:, completionHandler:)
memery, if Apple would provide an easy way to get the VM's ip addressI don't know if there's an official API/documentation for this, but you can go from VM mac address to IP rather easily by parsing
/var/db/dhcpd_leases
Documentation: https://developer.apple.com/documentation/virtualization/sockets
Yup, I choose the MAC address way as well