lan_unix.go 590 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2015 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at http://mozilla.org/MPL/2.0/.
  6. // +build !windows
  7. package osutil
  8. import (
  9. "net"
  10. )
  11. func GetLans() ([]*net.IPNet, error) {
  12. addrs, err := net.InterfaceAddrs()
  13. if err != nil {
  14. return nil, err
  15. }
  16. nets := make([]*net.IPNet, 0, len(addrs))
  17. for _, addr := range addrs {
  18. net, ok := addr.(*net.IPNet)
  19. if ok {
  20. nets = append(nets, net)
  21. }
  22. }
  23. return nets, nil
  24. }