dongyan1974 2018-11-25 06:10
浏览 163

尝试分配本地地址值时出错

I'm trying to set the local address of an http request like so:

localAddr, err := net.ResolveIPAddr("ip6", laddr)

if err != nil {
    log.Fatal(err)
}

localTCPAddr := net.TCPAddr{
    IP: localAddr.IP,
}

client := &http.Client{
    Transport: &http.Transport{
        Proxy: http.ProxyFromEnvironment,
        DialContext: (&net.Dialer{
            LocalAddr: &localTCPAddr,
            Timeout:   30 * time.Second,
            KeepAlive: 30 * time.Second,
            DualStack: true,
        }).DialContext,
        MaxIdleConns:          100,
        IdleConnTimeout:       90 * time.Second,
        TLSHandshakeTimeout:   10 * time.Second,
        ExpectContinueTimeout: 1 * time.Second,
    },
}

For reference: the laddr variable would look like this:

 2620:13a:c020:0016:1f7b:169c:846f:218a:49152

The error occurs when trying to send the request, and this is the error: 2018/11/25 00:17:58 lookup 2620:13a:c020:0016:1f7b:169c:846f:218a:49152: no such host.

I'm not sure whats causing this error. Some details about my environment: its a Ubuntu fresh VPS, with almost nothing installed.

EDIT: Even when removing the port as pointed out below I still get this error: dial tcp [2620:13a:c020:16:1f7b:169c:846f:218a]:0 ->[remoteip]:[remoteport] bind: cannot assign requested address

  • 写回答

2条回答 默认 最新

  • duansang8388 2018-11-25 06:40
    关注

    This 2620:13a:c020:0016:1f7b:169c:846f:218a:49152 is not a valid IPv6 address. You have an extra 49152 which is not even a valid IPv6 hextet. This 2620:13a:c020:0016:1f7b:169c:846f:218a is a valid IPv6 address.

    Validator

    Edit

    Address resolution is not the same as making a connection. If you want to make a connection rather than resolving the address, that is the time that you need the port.

    e.g.

    net.Dial("tcp", "[2620:13a:c020:16:1f7b:169c:846f:218a]:49152")
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图