1
0
mirror of https://github.com/golang/go synced 2024-11-20 10:54:49 -07:00
go/src/pkg/net/unixsock.go
Mikio Hara a64bea5c99 net: make UnixAddr implement sockaddr interface
This is in preparation for runtime-integrated network pollster for BSD
variants.

Update #5199

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/11932044
2013-07-28 16:15:07 +09:00

37 lines
886 B
Go

// 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
// UnixAddr represents the address of a Unix domain socket end point.
type UnixAddr struct {
Name string
Net string
}
// Network returns the address's network name, "unix", "unixgram" or
// "unixpacket".
func (a *UnixAddr) Network() string {
return a.Net
}
func (a *UnixAddr) String() string {
if a == nil {
return "<nil>"
}
return a.Name
}
// ResolveUnixAddr parses addr as a Unix domain socket address.
// The string net gives the network name, "unix", "unixgram" or
// "unixpacket".
func ResolveUnixAddr(net, addr string) (*UnixAddr, error) {
switch net {
case "unix", "unixgram", "unixpacket":
return &UnixAddr{Name: addr, Net: net}, nil
default:
return nil, UnknownNetworkError(net)
}
}