Home | History | Annotate | Download | only in syscall
      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 // +build netbsd openbsd
      6 
      7 package syscall_test
      8 
      9 import (
     10 	"fmt"
     11 	"syscall"
     12 )
     13 
     14 func parseRoutingMessageHeader(m syscall.RoutingMessage) (addrFlags, error) {
     15 	switch m := m.(type) {
     16 	case *syscall.RouteMessage:
     17 		errno := syscall.Errno(uintptr(m.Header.Errno))
     18 		if errno != 0 {
     19 			return 0, fmt.Errorf("%T: %v, %#v", m, errno, m.Header)
     20 		}
     21 		return addrFlags(m.Header.Addrs), nil
     22 	case *syscall.InterfaceMessage:
     23 		return addrFlags(m.Header.Addrs), nil
     24 	case *syscall.InterfaceAddrMessage:
     25 		return addrFlags(m.Header.Addrs), nil
     26 	default:
     27 		panic(fmt.Sprintf("unknown routing message type: %T", m))
     28 	}
     29 }
     30 
     31 func parseRoutingSockaddrs(m syscall.RoutingMessage) ([]syscall.Sockaddr, error) {
     32 	switch m := m.(type) {
     33 	case *syscall.RouteMessage:
     34 		sas, err := syscall.ParseRoutingSockaddr(m)
     35 		if err != nil {
     36 			return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
     37 		}
     38 		if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
     39 			return nil, err
     40 		}
     41 		return sas, nil
     42 	case *syscall.InterfaceMessage:
     43 		sas, err := syscall.ParseRoutingSockaddr(m)
     44 		if err != nil {
     45 			return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
     46 		}
     47 		if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
     48 			return nil, err
     49 		}
     50 		return sas, nil
     51 	case *syscall.InterfaceAddrMessage:
     52 		sas, err := syscall.ParseRoutingSockaddr(m)
     53 		if err != nil {
     54 			return nil, fmt.Errorf("%T: %v, %#v", m, err, m.Data)
     55 		}
     56 		if err = sockaddrs(sas).match(addrFlags(m.Header.Addrs)); err != nil {
     57 			return nil, err
     58 		}
     59 		return sas, nil
     60 	default:
     61 		panic(fmt.Sprintf("unknown routing message type: %T", m))
     62 	}
     63 }
     64