@@ -296,6 +296,70 @@ type VmnetNetwork struct {
296296 * pointer
297297}
298298
299+ // NewVmnetNetwork creates a new VmnetNetwork with config.
300+ // This is only supported on macOS 26 and newer, error will
301+ // be returned on older versions.
302+ func NewVmnetNetwork (config * VmnetNetworkConfiguration ) (* VmnetNetwork , error ) {
303+ if err := macOSAvailable (26 ); err != nil {
304+ return nil , err
305+ }
306+
307+ var status VmnetReturn
308+ ptr := C .VZVmnetNetworkCreate (
309+ objc .Ptr (config ),
310+ (* C .uint32_t )(unsafe .Pointer (& status )),
311+ )
312+ if ! errors .Is (status , ErrVmnetSuccess ) {
313+ return nil , fmt .Errorf ("failed to create VmnetNetwork: %w" , status )
314+ }
315+ network := & VmnetNetwork {
316+ pointer : objc .NewPointer (ptr ),
317+ }
318+ objc .SetFinalizer (network , func (self * VmnetNetwork ) {
319+ objc .Release (self )
320+ })
321+ return network , nil
322+ }
323+
324+ // NewVmnetNetworkWithSerialization creates a new VmnetNetwork from a serialized representation.
325+ // This is only supported on macOS 26 and newer, error will
326+ // be returned on older versions.
327+ // see: https://developer.apple.com/documentation/vmnet/vmnet_network_create_with_serialization(_:_:)?language=objc
328+ func NewVmnetNetworkWithSerialization (serialization uintptr ) (* VmnetNetwork , error ) {
329+ if err := macOSAvailable (26 ); err != nil {
330+ return nil , err
331+ }
332+
333+ var status VmnetReturn
334+ ptr := C .VZVmnetNetworkCreateWithSerialization (
335+ C .CFTypeRef (serialization ),
336+ (* C .uint32_t )(unsafe .Pointer (& status )),
337+ )
338+ if ! errors .Is (status , ErrVmnetSuccess ) {
339+ return nil , fmt .Errorf ("failed to create VmnetNetwork with serialization: %w" , status )
340+ }
341+ network := & VmnetNetwork {
342+ pointer : objc .NewPointer (ptr ),
343+ }
344+ objc .SetFinalizer (network , func (self * VmnetNetwork ) {
345+ objc .Release (self )
346+ })
347+ return network , nil
348+ }
349+
350+ // CopySerialization returns a pointer to a serialized representation of the vmnet network.
351+ func (n * VmnetNetwork ) CopySerialization () (uintptr , error ) {
352+ var status VmnetReturn
353+ ptr := C .VZVmnetNetwork_copySerialization (
354+ objc .Ptr (n ),
355+ (* C .uint32_t )(unsafe .Pointer (& status )),
356+ )
357+ if ! errors .Is (status , ErrVmnetSuccess ) {
358+ return 0 , fmt .Errorf ("failed to copy serialization: %w" , status )
359+ }
360+ return uintptr (ptr ), nil
361+ }
362+
299363// IPv6Prefix returns the IPv6 prefix of the network.
300364func (n * VmnetNetwork ) IPv6Prefix () (netip.Prefix , error ) {
301365 var prefix C.struct_in6_addr
@@ -345,28 +409,3 @@ func inAddrToIP(a C.struct_in_addr) net.IP {
345409 p := (* [4 ]byte )(unsafe .Pointer (& a ))
346410 return net .IPv4 (p [0 ], p [1 ], p [2 ], p [3 ])
347411}
348-
349- // NewVmnetNetwork creates a new VmnetNetwork with config.
350- // This is only supported on macOS 26 and newer, error will
351- // be returned on older versions.
352- func NewVmnetNetwork (config * VmnetNetworkConfiguration ) (* VmnetNetwork , error ) {
353- if err := macOSAvailable (26 ); err != nil {
354- return nil , err
355- }
356-
357- var status VmnetReturn
358- ptr := C .VZVmnetNetworkCreate (
359- objc .Ptr (config ),
360- (* C .uint32_t )(unsafe .Pointer (& status )),
361- )
362- if ! errors .Is (status , ErrVmnetSuccess ) {
363- return nil , fmt .Errorf ("failed to create VmnetNetwork: %w" , status )
364- }
365- network := & VmnetNetwork {
366- pointer : objc .NewPointer (ptr ),
367- }
368- objc .SetFinalizer (network , func (self * VmnetNetwork ) {
369- objc .Release (self )
370- })
371- return network , nil
372- }
0 commit comments