const.go 631 B

1234567891011121314151617181920212223242526272829303132333435
  1. package model
  2. import "net"
  3. const (
  4. TypeIOS = "ios"
  5. TypeAndriod = "android"
  6. )
  7. // InetAtoN conver ip addr to uint32.
  8. func InetAtoN(s string) (sum uint32) {
  9. ip := net.ParseIP(s)
  10. if ip == nil {
  11. return
  12. }
  13. ip = ip.To4()
  14. if ip == nil {
  15. return
  16. }
  17. sum += uint32(ip[0]) << 24
  18. sum += uint32(ip[1]) << 16
  19. sum += uint32(ip[2]) << 8
  20. sum += uint32(ip[3])
  21. return sum
  22. }
  23. // InetNtoA conver uint32 to ip addr.
  24. func InetNtoA(sum uint32) string {
  25. ip := make(net.IP, net.IPv4len)
  26. ip[0] = byte((sum >> 24) & 0xFF)
  27. ip[1] = byte((sum >> 16) & 0xFF)
  28. ip[2] = byte((sum >> 8) & 0xFF)
  29. ip[3] = byte(sum & 0xFF)
  30. return ip.String()
  31. }