github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/pkg/specgenutil/ports.go (about)

     1  package specgenutil
     2  
     3  import (
     4  	"github.com/docker/go-connections/nat"
     5  	"github.com/pkg/errors"
     6  )
     7  
     8  func verifyExpose(expose []string) error {
     9  	// add the expose ports from the user (--expose)
    10  	// can be single or a range
    11  	for _, expose := range expose {
    12  		// support two formats for expose, original format <portnum>/[<proto>] or <startport-endport>/[<proto>]
    13  		_, port := nat.SplitProtoPort(expose)
    14  		// parse the start and end port and create a sequence of ports to expose
    15  		// if expose a port, the start and end port are the same
    16  		_, _, err := nat.ParsePortRange(port)
    17  		if err != nil {
    18  			return errors.Wrapf(err, "invalid range format for --expose: %s", expose)
    19  		}
    20  	}
    21  	return nil
    22  }