// Copyright 2013 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 ipv6

import (
	
	

	
)

// BUG(mikio): On Windows, the JoinSourceSpecificGroup,
// LeaveSourceSpecificGroup, ExcludeSourceSpecificGroup and
// IncludeSourceSpecificGroup methods of PacketConn are not
// implemented.

// A Conn represents a network endpoint that uses IPv6 transport.
// It allows to set basic IP-level socket options such as traffic
// class and hop limit.
type Conn struct {
	genericOpt
}

type genericOpt struct {
	*socket.Conn
}

func ( *genericOpt) () bool { return  != nil && .Conn != nil }

// PathMTU returns a path MTU value for the destination associated
// with the endpoint.
func ( *Conn) () (int, error) {
	if !.ok() {
		return 0, errInvalidConn
	}
	,  := sockOpts[ssoPathMTU]
	if ! {
		return 0, errNotImplemented
	}
	, ,  := .getMTUInfo(.Conn)
	if  != nil {
		return 0, 
	}
	return , nil
}

// NewConn returns a new Conn.
func ( net.Conn) *Conn {
	,  := socket.NewConn()
	return &Conn{
		genericOpt: genericOpt{Conn: },
	}
}

// A PacketConn represents a packet network endpoint that uses IPv6
// transport. It is used to control several IP-level socket options
// including IPv6 header manipulation. It also provides datagram
// based network I/O methods specific to the IPv6 and higher layer
// protocols such as OSPF, GRE, and UDP.
type PacketConn struct {
	genericOpt
	dgramOpt
	payloadHandler
}

type dgramOpt struct {
	*socket.Conn
}

func ( *dgramOpt) () bool { return  != nil && .Conn != nil }

// SetControlMessage allows to receive the per packet basis IP-level
// socket options.
func ( *PacketConn) ( ControlFlags,  bool) error {
	if !.payloadHandler.ok() {
		return errInvalidConn
	}
	return setControlMessage(.dgramOpt.Conn, &.payloadHandler.rawOpt, , )
}

// SetDeadline sets the read and write deadlines associated with the
// endpoint.
func ( *PacketConn) ( time.Time) error {
	if !.payloadHandler.ok() {
		return errInvalidConn
	}
	return .payloadHandler.SetDeadline()
}

// SetReadDeadline sets the read deadline associated with the
// endpoint.
func ( *PacketConn) ( time.Time) error {
	if !.payloadHandler.ok() {
		return errInvalidConn
	}
	return .payloadHandler.SetReadDeadline()
}

// SetWriteDeadline sets the write deadline associated with the
// endpoint.
func ( *PacketConn) ( time.Time) error {
	if !.payloadHandler.ok() {
		return errInvalidConn
	}
	return .payloadHandler.SetWriteDeadline()
}

// Close closes the endpoint.
func ( *PacketConn) () error {
	if !.payloadHandler.ok() {
		return errInvalidConn
	}
	return .payloadHandler.Close()
}

// NewPacketConn returns a new PacketConn using c as its underlying
// transport.
func ( net.PacketConn) *PacketConn {
	,  := socket.NewConn(.(net.Conn))
	return &PacketConn{
		genericOpt:     genericOpt{Conn: },
		dgramOpt:       dgramOpt{Conn: },
		payloadHandler: payloadHandler{PacketConn: , Conn: },
	}
}