tango.net.device.Berkeley

enum #
enum SocketOption #
enum SocketOptionLevel #
enum SocketType #
STREAM #
sequential, reliable
DGRAM #
connectionless unreliable, max length
SEQPACKET #
sequential, reliable, max length
enum ProtocolType #
IP #
default internet protocol (probably 4 for compatibility)
IPV4 #
internet protocol version 4
IPV6 #
internet protocol version 6
ICMP #
internet control message protocol
IGMP #
internet group management protocol
TCP #
transmission control protocol
PUP #
PARC universal packet protocol
UDP #
user datagram protocol
IDP #
Xerox NS protocol
enum AddressFamily #
enum SocketShutdown #
enum SocketFlags #
OOB #
out of band
PEEK #
only for receiving
DONTROUTE #
only for sending
NOSIGNAL #
inhibit signals
int function(char* node, char* service, Address.addrinfo* hints, Address.addrinfo** res) getaddrinfo [private, extern(Windows)] #
The gai_strerror function translates error codes of getaddrinfo, freeaddrinfo and getnameinfo to a human readable string, suitable for error reporting. (C) MAN
Given node and service, which identify an Internet host and a service, getaddrinfo() returns one or more addrinfo structures, each of which contains an Internet address that can be specified in a call to bind or connect. The getaddrinfo() function combines the functionality provided by the getservbyname and getservbyport functions into a single interface, but unlike the latter functions, getaddrinfo() is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies.(C) MAN
void function(Address.addrinfo *res) freeaddrinfo [private, extern(Windows)] #
The freeaddrinfo() function frees the memory that was allocated for the dynamically allocated linked list res. (C) MAN
int function(Address.sockaddr* sa, int salen, char* host, int hostlen, char* serv, int servlen, int flags) getnameinfo [private, extern(Windows)] #
The getnameinfo() function is the inverse of getaddrinfo: it converts a socket address to a corresponding host and service, in a protocol- independent manner. It combines the functionality of gethostbyaddr and getservbyport, but unlike those functions, getaddrinfo is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies. (C) MAN
struct Berkeley [public] #
void open(AddressFamily family, SocketType type, ProtocolType protocol, bool create = true) #
Configure this instance
void reopen(socket_t sock = sock.init) #
Open/reopen a native socket for this instance
void detach() #
calling shutdown() before this is recommended for connection- oriented sockets
socket_t handle() #
Return the underlying OS handle of this Conduit
int error() #
Return socket error status
int lastError() [static] #
Return the last error
bool isAlive() #
Is this socket still alive? A closed socket is considered to be dead, but a shutdown socket is still alive.
AddressFamily addressFamily() #
Berkeley* bind(Address addr) #
Berkeley* connect(Address to) #
Berkeley* listen(int backlog) #
need to bind() first
void accept(ref Berkeley target) #
need to bind() first
Berkeley* shutdown(SocketShutdown how) #
The shutdown function shuts down the connection of the socket. Depending on the argument value, it will:
- stop receiving data for this socket. If further data arrives, it is rejected.

- stop trying to transmit data from this socket. Also discards any data waiting to be sent. Stop looking for acknowledgement of data already sent; don't retransmit if any data is lost.

Berkeley* linger(int period) #
set linger timeout
Berkeley* addressReuse(bool enabled) #
enable/disable address reuse
Berkeley* noDelay(bool enabled) #
enable/disable noDelay option (nagle)
void joinGroup(IPv4Address address, bool onOff) #
Helper function to handle the adding and dropping of group membership.
Address newFamilyObject() #
char[] hostName() [static] #
return the hostname
uint hostAddress() [static] #
return the default host address (IPv4)
Address remoteAddress() #
return the remote address of the current connection (IPv4)
Address localAddress() #
return the local address of the current connection (IPv4)
int send(void[] buf, SocketFlags flags = SocketFlags.NONE) #
Send data on the connection. Returns the number of bytes actually sent, or ERROR on failure. If the socket is blocking and there is no buffer space left, send waits.
Returns number of bytes actually sent, or -1 on error
int sendTo(void[] buf, SocketFlags flags, Address to) #
int sendTo(void[] buf, Address to) #
Send data to a specific destination Address. If the destination address is not specified, a connection must have been made and that address is used. If the socket is blocking and there is no buffer space left, sendTo waits.
int sendTo(void[] buf, SocketFlags flags = SocketFlags.NONE) #
ditto - assumes you connect()ed
int sendTo(void[] buf, int flags, Address.sockaddr* to, int len) [private] #
Send data to a specific destination Address. If the destination address is not specified, a connection must have been made and that address is used. If the socket is blocking and there is no buffer space left, sendTo waits.
int receive(void[] buf, SocketFlags flags = SocketFlags.NONE) #
Receive data on the connection. Returns the number of bytes actually received, 0 if the remote side has closed the connection, or ERROR on failure. If the socket is blocking, receive waits until there is data to be received.
Returns number of bytes actually received, 0 on connection closure, or -1 on error
int receiveFrom(void[] buf, SocketFlags flags, Address from) #
int receiveFrom(void[] buf, Address from) #
Receive data and get the remote endpoint Address. Returns the number of bytes actually received, 0 if the remote side has closed the connection, or ERROR on failure. If the socket is blocking, receiveFrom waits until there is data to be received.
int receiveFrom(void[] buf, SocketFlags flags = SocketFlags.NONE) #
ditto - assumes you connect()ed
int getOption(SocketOptionLevel level, SocketOption option, void[] result) #
returns the length, in bytes, of the actual result - very different from getsockopt()
Berkeley* setOption(SocketOptionLevel level, SocketOption option, void[] value) #
bool blocking() #
getter
void blocking(bool yes) #
setter
void exception(char[] msg) [static] #
void badArg(char[] msg) [protected, static] #
class Address [public, abstract] #
ushort ntohs(ushort x) [private, static] #
Internal usage
uint ntohl(uint x) [private, static] #
Internal usage
char[] fromInt(char[] tmp, int i) [private, static] #
Internal usage
int toInt(char[] s) [private, static] #
Internal usage
void exception(char[] msg) [static] #

Tango:

added this common function
Address create(sockaddr* sa) [static] #
Address factory
Address resolve(char[] host, char[] service = null, AddressFamily af = AddressFamily.UNSPEC, AIFlags flags = cast(AIFlags)0) [static] #
Address resolve(char[] host, ushort port, AddressFamily af = AddressFamily.UNSPEC, AIFlags flags = cast(AIFlags)0) [static] #
Address[] resolveAll(char[] host, char[] service = null, AddressFamily af = AddressFamily.UNSPEC, AIFlags flags = cast(AIFlags)0) [static] #
Address[] resolveAll(char host[] host, ushort port, AddressFamily af = AddressFamily.UNSPEC, AIFlags flags = cast(AIFlags)0) [static] #
Address passive(char[] service, AddressFamily af = AddressFamily.UNSPEC, AIFlags flags = cast(AIFlags)0) [static] #
Address passive(ushort port, AddressFamily af = AddressFamily.UNSPEC, AIFlags flags = cast(AIFlags)0) [static] #
char[] toAddrString() #
char[] toPortString() #
char[] toString() #
AddressFamily addressFamily() #
class UnknownAddress : Address [public] #
sockaddr* name() #
int nameLen() #
AddressFamily addressFamily() #
char[] toString() #
class IPv4Address : Address [public] #
enum #
struct sockaddr_in #
this() [protected] #
this(ushort port) #
this(uint addr, ushort port) #
this(char[] addr, ushort port = PORT_ANY) #
-port- can be PORT_ANY -addr- is an IP address or host name
this(sockaddr* addr) #
sockaddr* name() #
int nameLen() #
AddressFamily addressFamily() #
ushort port() #
uint addr() #
char[] toAddrString() #
char[] toPortString() #
char[] toString() #
uint parse(char[] addr) [static] #
-addr- is an IP address in the format "a.b.c.d" returns ADDR_NONE on failure
class IPv6Address : Address #
IPv6 is the next-generation Internet Protocol version designated as the successor to IPv4, the first implementation used in the Internet that is still in dominant use currently.
More information: http://ipv6.com/

IPv6 supports 128-bit address space as opposed to 32-bit address space of IPv4.

IPv6 is written as 8 blocks of 4 octal digits (16 bit) separated by a colon (":"). Zero block can be replaced by "::".

For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0000:0000:0000:0000:0000:0000:0000:0001
is equal
::0001
is equal
::1
is analogue IPv4 127.0.0.1

0000:0000:0000:0000:0000:0000:0000:0000
is equal
::
is analogue IPv4 0.0.0.0

2001:cdba:0000:0000:0000:0000:3257:9652
is equal
2001:cdba::3257:9652

IPv4 address can be submitted through IPv6 as ::ffff:xx.xx.xx.xx,
where xx.xx.xx.xx 32-bit IPv4 addresses.

::ffff:51b0:ec6d
is equal
::ffff:81.176.236.109
is analogue IPv4 81.176.236.109

The URL for the IPv6 address will be of the form:
http://[2001:cdba:0000:0000:0000:0000:3257:9652]/

If needed to specify a port, it will be listed after the
closing square bracket followed by a colon.

http://[2001:cdba:0000:0000:0000:0000:3257:9652]:8080/
address: "2001:cdba:0000:0000:0000:0000:3257:9652"
port: 8080

IPv6Address can be used as well as IPv4Address.

scope addr = new IPv6Address(8080);
address: "::"
port: 8080

scope addr_2 = new IPv6Address("::1", 8081);
address: "::1"
port: 8081

scope addr_3 = new IPv6Address("::1");
address: "::1"
port: PORT_ANY

Also in the IPv6Address constructor can specify the service name
or port as string

scope addr_3 = new IPv6Address("::", "ssh");
address: "::"
port: 22 (ssh service port)

scope addr_4 = new IPv6Address("::", "8080");
address: "::"
port: 8080
struct sockaddr_in6 [protected] #
this() [protected] #
this(sockaddr* sa) [protected] #
sockaddr* name() [protected] #
int nameLen() [protected] #
AddressFamily addressFamily() [public] #
ushort port() [public] #
this(int port) [public] #
Create IPv6Address with zero address
this(char[] addr, int port = PORT_ANY) [public] #
-port- can be PORT_ANY -addr- is an IP address or host name
this(char[] addr, char[] service) [public] #
-service- can be a port number or service name -addr- is an IP address or host name
ubyte[] addr() [public] #
char[] toPortString() [public] #
char[] toString() [public] #
class NetHost [public] #
struct hostent #
void validHostent(hostent* he) [protected] #
void populate(hostent* he) #
bool getHostByName(char[] name) #
bool getHostByAddr(uint addr) #
bool getHostByAddr(char[] addr) #
class SocketSet [public] #
a set of sockets for Berkeley.select()
int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, timeval* tv) [public, static] #
SocketSet's are updated to include only those sockets which an event occured.
Returns the number of events, 0 on timeout, or -1 on error

for a connect()ing socket, writeability means connected for a listen()ing socket, readability means listening

Winsock:

possibly internally limited to 64 sockets per set
int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, long microseconds) [public, static] #
select with specified timeout
int select(SocketSet checkRead, SocketSet checkWrite, SocketSet checkError) [public, static] #
select with maximum timeout