Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fmt:

.PHONY: test
test:
go test -p 1 -exec "go run $(PWD)/cmd/codesign" ./... -timeout 2m -v
go test -p 1 -exec "go run $(PWD)/cmd/codesign" ./... -timeout 3m -v

.PHONY: test/run
test/run:
Expand Down
1 change: 1 addition & 0 deletions example/macOS/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ require github.com/Code-Hex/vz/v3 v3.0.0-00010101000000-000000000000
require (
github.com/Code-Hex/go-infinity-channel v1.0.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sys v0.36.0 // indirect
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ require (
golang.org/x/mod v0.22.0
)

require golang.org/x/sys v0.36.0 // indirect
require golang.org/x/sys v0.36.0
48 changes: 47 additions & 1 deletion network.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package vz

/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization -framework vmnet
# include "virtualization_11.h"
# include "virtualization_13.h"
# include "virtualization_26.h"
*/
import "C"
import (
"fmt"
"net"
"os"
"syscall"
"unsafe"

"github.com/Code-Hex/vz/v3/internal/objc"
)
Expand Down Expand Up @@ -260,6 +262,50 @@ func (f *FileHandleNetworkDeviceAttachment) MaximumTransmissionUnit() int {
return f.mtu
}

// VmnetNetworkDeviceAttachment represents a vmnet network device attachment.
//
// This attachment is used to connect a virtual machine to a vmnet network.
// The attachment is created with a VmnetNetwork and can be used with a VirtioNetworkDeviceConfiguration.
// see: https://developer.apple.com/documentation/virtualization/vzvmnetnetworkdeviceattachment?language=objc
//
// This is only supported on macOS 26 and newer, error will
// be returned on older versions.
type VmnetNetworkDeviceAttachment struct {
*pointer

*baseNetworkDeviceAttachment
}

func (*VmnetNetworkDeviceAttachment) String() string {
return "VmnetNetworkDeviceAttachment"
}

func (v *VmnetNetworkDeviceAttachment) Network() unsafe.Pointer {
return C.VZVmnetNetworkDeviceAttachment_network(objc.Ptr(v))
}

var _ NetworkDeviceAttachment = (*VmnetNetworkDeviceAttachment)(nil)

// NewVmnetNetworkDeviceAttachment creates a new VmnetNetworkDeviceAttachment with network.
//
// This is only supported on macOS 26 and newer, error will
// be returned on older versions.
func NewVmnetNetworkDeviceAttachment(network unsafe.Pointer) (*VmnetNetworkDeviceAttachment, error) {
if err := macOSAvailable(26); err != nil {
return nil, err
}

attachment := &VmnetNetworkDeviceAttachment{
pointer: objc.NewPointer(
C.newVZVmnetNetworkDeviceAttachment(network),
),
}
objc.SetFinalizer(attachment, func(self *VmnetNetworkDeviceAttachment) {
objc.Release(self)
})
return attachment, nil
}

// NetworkDeviceAttachment for a network device attachment.
// see: https://developer.apple.com/documentation/virtualization/vznetworkdeviceattachment?language=objc
type NetworkDeviceAttachment interface {
Expand Down
Loading