MCPcopy Index your code
hub / github.com/coder/coder / getRemoteAddress

Function getRemoteAddress

coderd/httpmw/realip.go:191–207  ·  view source on GitHub ↗

getRemoteAddress extracts the IP address from the given string. If the string contains commas, it assumes that the first part is the original address.

(address string)

Source from the content-addressed store, hash-verified

189// the string contains commas, it assumes that the first part is the
190// original address.
191func getRemoteAddress(address string) net.IP {
192 // X-Forwarded-For may contain multiple addresses, in case the
193 // proxies are chained; the first value is the client address
194 i := strings.IndexByte(address, ',')
195 if i == -1 {
196 i = len(address)
197 }
198
199 // If the address contains a port, remove it
200 firstAddress := address[:i]
201 host, _, err := net.SplitHostPort(firstAddress)
202 if err != nil {
203 // This will error if there is no port, so try to parse the address
204 return net.ParseIP(firstAddress)
205 }
206 return net.ParseIP(host)
207}
208
209// isContainedIn checks that the given address is contained in the given
210// network.

Callers 4

ExtractRealIPAddressFunction · 0.85
EffectiveHostFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected