Source file src/net/internal/socktest/switch_posix.go

     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  
     7  package socktest
     8  
     9  import (
    10  	"fmt"
    11  	"syscall"
    12  )
    13  
    14  func familyString(family int) string {
    15  	switch family {
    16  	case syscall.AF_INET:
    17  		return "inet4"
    18  	case syscall.AF_INET6:
    19  		return "inet6"
    20  	case syscall.AF_UNIX:
    21  		return "local"
    22  	default:
    23  		return fmt.Sprintf("%d", family)
    24  	}
    25  }
    26  
    27  func typeString(sotype int) string {
    28  	var s string
    29  	switch sotype & 0xff {
    30  	case syscall.SOCK_STREAM:
    31  		s = "stream"
    32  	case syscall.SOCK_DGRAM:
    33  		s = "datagram"
    34  	case syscall.SOCK_RAW:
    35  		s = "raw"
    36  	case syscall.SOCK_SEQPACKET:
    37  		s = "seqpacket"
    38  	default:
    39  		s = fmt.Sprintf("%d", sotype&0xff)
    40  	}
    41  	if flags := uint(sotype) & ^uint(0xff); flags != 0 {
    42  		s += fmt.Sprintf("|%#x", flags)
    43  	}
    44  	return s
    45  }
    46  
    47  func protocolString(proto int) string {
    48  	switch proto {
    49  	case 0:
    50  		return "default"
    51  	case syscall.IPPROTO_TCP:
    52  		return "tcp"
    53  	case syscall.IPPROTO_UDP:
    54  		return "udp"
    55  	default:
    56  		return fmt.Sprintf("%d", proto)
    57  	}
    58  }
    59  

View as plain text