2009-11-01 12:15:34 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package net
|
|
|
|
|
2009-11-02 19:37:30 -07:00
|
|
|
// UnixAddr represents the address of a Unix domain socket end point.
|
|
|
|
type UnixAddr struct {
|
2011-01-19 12:21:58 -07:00
|
|
|
Name string
|
|
|
|
Net string
|
2009-11-02 19:37:30 -07:00
|
|
|
}
|
|
|
|
|
2013-03-22 16:39:43 -06:00
|
|
|
// Network returns the address's network name, "unix", "unixgram" or
|
|
|
|
// "unixpacket".
|
2011-01-19 12:21:58 -07:00
|
|
|
func (a *UnixAddr) Network() string {
|
|
|
|
return a.Net
|
2009-11-02 19:37:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *UnixAddr) String() string {
|
|
|
|
if a == nil {
|
2009-11-09 13:07:39 -07:00
|
|
|
return "<nil>"
|
2009-11-02 19:37:30 -07:00
|
|
|
}
|
2009-12-15 16:35:38 -07:00
|
|
|
return a.Name
|
2009-11-02 19:37:30 -07:00
|
|
|
}
|
|
|
|
|
2015-05-29 16:33:16 -06:00
|
|
|
func (a *UnixAddr) isWildcard() bool {
|
|
|
|
return a == nil || a.Name == ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *UnixAddr) opAddr() Addr {
|
|
|
|
if a == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2009-11-02 19:37:30 -07:00
|
|
|
// ResolveUnixAddr parses addr as a Unix domain socket address.
|
2011-01-19 12:21:58 -07:00
|
|
|
// The string net gives the network name, "unix", "unixgram" or
|
|
|
|
// "unixpacket".
|
2011-11-01 20:05:34 -06:00
|
|
|
func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
|
2009-11-02 19:37:30 -07:00
|
|
|
switch net {
|
2013-03-22 16:39:43 -06:00
|
|
|
case "unix", "unixgram", "unixpacket":
|
|
|
|
return &UnixAddr{Name: addr, Net: net}, nil
|
2009-11-02 19:37:30 -07:00
|
|
|
default:
|
2009-11-09 13:07:39 -07:00
|
|
|
return nil, UnknownNetworkError(net)
|
2009-11-02 19:37:30 -07:00
|
|
|
}
|
|
|
|
}
|