github.com/code-reading/golang@v0.0.0-20220303082512-ba5bc0e589a3/go/src/net/internal/socktest/switch_posix.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build !plan9 6 // +build !plan9 7 8 package socktest 9 10 import ( 11 "fmt" 12 "syscall" 13 ) 14 15 func familyString(family int) string { 16 switch family { 17 case syscall.AF_INET: 18 return "inet4" 19 case syscall.AF_INET6: 20 return "inet6" 21 case syscall.AF_UNIX: 22 return "local" 23 default: 24 return fmt.Sprintf("%d", family) 25 } 26 } 27 28 func typeString(sotype int) string { 29 var s string 30 switch sotype & 0xff { 31 case syscall.SOCK_STREAM: 32 s = "stream" 33 case syscall.SOCK_DGRAM: 34 s = "datagram" 35 case syscall.SOCK_RAW: 36 s = "raw" 37 case syscall.SOCK_SEQPACKET: 38 s = "seqpacket" 39 default: 40 s = fmt.Sprintf("%d", sotype&0xff) 41 } 42 if flags := uint(sotype) & ^uint(0xff); flags != 0 { 43 s += fmt.Sprintf("|%#x", flags) 44 } 45 return s 46 } 47 48 func protocolString(proto int) string { 49 switch proto { 50 case 0: 51 return "default" 52 case syscall.IPPROTO_TCP: 53 return "tcp" 54 case syscall.IPPROTO_UDP: 55 return "udp" 56 default: 57 return fmt.Sprintf("%d", proto) 58 } 59 }