title: Dial with a specific address / interface ? Golang
body: <p>I have two network interfaces on my computer ( eth0 and eth1) and I'm trying to Dial a connection using a specific one (eth1). Given the statement that Go is a system language I assumed so but is it really possible with the current standard library? </p>
  
  <p>So far I've got to get the interface by name <a href="http://golang.org/pkg/net/#InterfaceByName" rel="noreferrer"><code>InterfaceByName</code></a> (<code>eth1</code>) then I range over the <a href="http://golang.org/pkg/net/#Interface.Addrs" rel="noreferrer"><code>Addrs</code></a> method and extracted the first address [0] which seems to be the source address of eth1 interface (e.g. xxx.xxx.xxx/24); the other one is the ipv6 address.<br>
   I've created a new <a href="http://golang.org/pkg/net/#Dialer" rel="noreferrer"><code>Dialer</code></a> and set <a href="http://golang.org/src/pkg/net/dial.go?s=1060:1271#L7" rel="noreferrer"><code>Dialer.LocalAddr</code></a> with the address extracted. However I get this error <code>mismatched local address type</code> wich seems related to dialSingle function from <a href="http://golang.org/src/pkg/net/dial.go" rel="noreferrer">dial.go</a></p>
  
  <p><strong>Edit</strong>
  Some code:</p>
  
  <pre><code>package main
  import (
          "net"
          "log"
  )
  
  func main(){
          ief, err := net.InterfaceByName("eth1")
          if err !=nil{
                  log.Fatal(err)
          }
          addrs, err := ief.Addrs()
          if err !=nil{
                  log.Fatal(err)
          }
          d := net.Dialer{LocalAddr: addrs[0]}
          _, err = d.Dial("tcp", "google.com:80")
          if err != nil {
                  log.Fatal(err)
          }
  }
  </code></pre>
  
  <p>Output: 
     <code>2014/12/10 17:11:48 dial tcp 216.58.208.32:80: mismatched local address type ip+net</code></p>