github.com/google/osv-scalibr@v0.4.1/extractor/standalone/os/netports/metadata.go (about) 1 // Copyright 2025 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package netports 16 17 import ( 18 pb "github.com/google/osv-scalibr/binary/proto/scan_result_go_proto" 19 ) 20 21 // Metadata contains metadata about a given open port. 22 type Metadata struct { 23 // The port number. 24 Port uint32 25 // The protocol (tcp, udp). 26 Protocol string 27 // The command line of the process listening on the port, if available. 28 Cmdline string 29 } 30 31 // SetProto sets the NetportsMetadata field in the Package proto. 32 func (m *Metadata) SetProto(p *pb.Package) { 33 if m == nil { 34 return 35 } 36 if p == nil { 37 return 38 } 39 40 p.Metadata = &pb.Package_NetportsMetadata{ 41 NetportsMetadata: &pb.NetportsMetadata{ 42 Port: m.Port, 43 Protocol: m.Protocol, 44 CommandLine: m.Cmdline, 45 }, 46 } 47 } 48 49 // ToStruct converts the NetportsMetadata proto to a Metadata struct. 50 func ToStruct(m *pb.NetportsMetadata) *Metadata { 51 if m == nil { 52 return nil 53 } 54 55 return &Metadata{ 56 Port: m.GetPort(), 57 Protocol: m.GetProtocol(), 58 Cmdline: m.GetCommandLine(), 59 } 60 }