{"record":{"id":"2aaad6c27500e32a","repo":"ipfs/kubo","slug":"address-does-not-contain-tcp-or-udp-protocol","errorCode":null,"errorMessage":"address does not contain tcp or udp protocol","messagePattern":"address does not contain tcp or udp protocol","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/commands/p2p.go","lineNumber":398,"sourceCode":"\t\t}),\n\t},\n}\n\n// checkPort checks whether target multiaddr contains tcp or udp protocol\n// and whether the port is equal to 0\nfunc checkPort(target ma.Multiaddr) error {\n\t// get tcp or udp port from multiaddr\n\tgetPort := func() (string, error) {\n\t\tsport, _ := target.ValueForProtocol(ma.P_TCP)\n\t\tif sport != \"\" {\n\t\t\treturn sport, nil\n\t\t}\n\n\t\tsport, _ = target.ValueForProtocol(ma.P_UDP)\n\t\tif sport != \"\" {\n\t\t\treturn sport, nil\n\t\t}\n\t\treturn \"\", errors.New(\"address does not contain tcp or udp protocol\")\n\t}\n\n\tsport, err := getPort()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tport, err := strconv.Atoi(sport)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif port == 0 {\n\t\treturn errors.New(\"port can not be 0\")\n\t}\n\n\treturn nil\n}","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/commands/p2p.go#L380-L416","documentation":"When setting up an `ipfs p2p` listener/forward, kubo derives the local port from the listen or target multiaddr by looking up the TCP then the UDP protocol value. If the multiaddr contains neither /tcp/ nor /udp/, no port can be determined and this error is returned.","triggerScenarios":"Passing a listen or target multiaddr without a tcp/udp transport, e.g. `/ip4/127.0.0.1` alone, a `/unix/` path, or a quic/webtransport-only address to a p2p command that requires a host-side tcp/udp port.","commonSituations":"Typos dropping the `/tcp/<port>` component; using a Unix socket address; assuming QUIC addresses work for local forwarding when the command expects a TCP/UDP port to bind or connect.","solutions":["Include a tcp or udp transport with a nonzero port in the multiaddr, e.g. `/ip4/127.0.0.1/tcp/8080` or `/ip4/127.0.0.1/udp/8080/quic-v1`.","Check for typos that removed the `/tcp/<n>` or `/udp/<n>` component.","If you meant a unix socket or non-tcp/udp transport, that target type is unsupported by this command; use a tcp/udp endpoint instead."],"exampleFix":"// before\nipfs p2p forward /p2p/x/1.0.0 /ip4/127.0.0.1 <target>\n// after\nipfs p2p forward /p2p/x/1.0.0 /ip4/127.0.0.1/tcp/8080 <target>","handlingStrategy":"validation","validationCode":"m, err := multiaddr.NewMultiaddr(addr)\nif err != nil {\n    return err\n}\ntcpPort, _ := m.ValueForProtocol(multiaddr.P_TCP)\nudpPort, _ := m.ValueForProtocol(multiaddr.P_UDP)\nif tcpPort == \"\" && udpPort == \"\" {\n    return errors.New(\"multiaddr needs a /tcp/ or /udp/ component\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build listen/target multiaddrs with an explicit tcp or udp transport and port.","Validate multiaddrs at config-load time, before command invocation.","Do not use /unix/ or QUIC-only addresses for host-side p2p endpoints."],"tags":["p2p","multiaddr","validation"],"backgroundTag":"missing-tcp-udp-transport","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}