Socket::IPAddress

struct Socket::IPAddress

Overview

IP address representation.

Holds a binary representation of an IP address, either translated from a String, or directly received from an opened connection (e.g. Socket#local_address, Socket#receive).

Example:

Socket::IPAddress.new("127.0.0.1", 8080)
Socket::IPAddress.new("fe80::2ab2:bdff:fe59:8e2c", 1234)

IPAddress won't resolve domains, including localhost. If you must resolve an IP, or don't know whether a String constains an IP or a domain name, you should use Addrinfo.resolve instead.

Defined in:

socket/address.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.from(sockaddr : Pointer(LibC::Sockaddr), addrlen) : IPAddressSource

Creates an IPAddress from the internal OS representation. Supports both INET and INET6 families.

def self.new(address : String, port : Int32)Source

def self.new(sockaddr : Pointer(LibC::SockaddrIn6), size)Source

def self.new(sockaddr : Pointer(LibC::SockaddrIn), size)Source

Instance Method Detail

def ==(other : IPAddress)Source

def addressSource

Returns a String representation of the IP address.

Example:

ip_address = socket.remote_address
ip_address.address # => "127.0.0.1"

def port : Int32Source

def to_s(io)Source

def to_unsafe : Pointer(LibC::Sockaddr)Source

© 2012–2017 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.22.0/Socket/IPAddress.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部