1 module tango.sys.linux.consts.socket;
2     import tango.sys.linux.consts.fcntl: F_GETFL, F_SETFL,O_NONBLOCK;
3     enum {SOCKET_ERROR = -1}
4     enum
5     {
6         SO_DEBUG = 1 , /* turn on debugging info recording */
7         SO_BROADCAST = 6 , /* permit sending of broadcast msgs */
8         SO_REUSEADDR = 2 , /* allow local address reuse */
9         SO_LINGER = 13 , /* linger on close if data present */
10         SO_DONTLINGER = ~(13),
11         SO_OOBINLINE = 10 , /* leave received OOB data in line */
12         SO_ACCEPTCONN = 30, /* socket has had listen() */
13         SO_KEEPALIVE = 9 , /* keep connections alive */
14         SO_DONTROUTE = 5 , /* just use interface addresses */
15         SO_TYPE = 3 , /* get socket type */
16         /*
17          * Additional options, not kept in so_options.
18          */
19         SO_SNDBUF = 7, /* send buffer size */
20         SO_RCVBUF = 8, /* receive buffer size */
21         SO_ERROR = 4 , /* get error status and clear */
22         // OptionLevel.IP settings
23         IP_MULTICAST_TTL = 33 ,
24         IP_MULTICAST_LOOP = 34 ,
25         IP_ADD_MEMBERSHIP = 35 ,
26         IP_DROP_MEMBERSHIP = 36,
27         // OptionLevel.TCP settings
28         TCP_NODELAY = 1 ,
29     }
30     enum
31     {
32         SOL_SOCKET = 1,
33     }
34     enum {
35         SOCK_STREAM = 1 , /++ sequential, reliable +/
36         SOCK_DGRAM = 2 , /++ connectionless unreliable, max length +/
37         SOCK_SEQPACKET = 5, /++ sequential, reliable, max length +/
38         SOCK_RAW = 3 , /++ raw protocol +/
39         SOCK_RDM = 4 , /++ reliable messages +/
40         SOCK_PACKET = 10, /++ linux specific packets at dev level +/
41     }
42     /* Standard well-defined IP protocols.  */
43     enum
44       {
45         IPPROTO_IP = 0, /* Dummy protocol for TCP.  */
46         IPPROTO_IPV4 = 0, /* Dummy protocol for TCP.  */
47         IPPROTO_IPV6 = 41, /* IPv6 header.  */
48         IPPROTO_ICMP = 1, /* Internet Control Message Protocol.  */
49         IPPROTO_IGMP = 2, /* Internet Group Management Protocol. */
50         IPPROTO_TCP = 6, /* Transmission Control Protocol.  */
51         IPPROTO_PUP = 12, /* PUP protocol.  */
52         IPPROTO_UDP = 17, /* User Datagram Protocol.  */
53         IPPROTO_IDP = 22, /* XNS IDP protocol.  */
54         /+
55         // undefined for cross platform reasons, if you need some of these ask
56         IPPROTO_HOPOPTS = 0, /* IPv6 Hop-by-Hop options.  */
57         IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94).  */
58         IPPROTO_EGP = 8, /* Exterior Gateway Protocol.  */
59         IPPROTO_TP = 29, /* SO Transport Protocol Class 4.  */
60         IPPROTO_ROUTING = 43, /* IPv6 routing header.  */
61         IPPROTO_FRAGMENT = 44, /* IPv6 fragmentation header.  */
62         IPPROTO_RSVP = 46, /* Reservation Protocol.  */
63         IPPROTO_GRE = 47, /* General Routing Encapsulation.  */
64         IPPROTO_ESP = 50, /* encapsulating security payload.  */
65         IPPROTO_AH = 51, /* authentication header.  */
66         IPPROTO_ICMPV6 = 58, /* ICMPv6.  */
67         IPPROTO_NONE = 59, /* IPv6 no next header.  */
68         IPPROTO_DSTOPTS = 60, /* IPv6 destination options.  */
69         IPPROTO_MTP = 92, /* Multicast Transport Protocol.  */
70         IPPROTO_ENCAP = 98, /* Encapsulation Header.  */
71         IPPROTO_PIM = 103, /* Protocol Independent Multicast.  */
72         IPPROTO_COMP = 108, /* Compression Header Protocol.  */
73         IPPROTO_SCTP = 132, /* Stream Control Transmission Protocol.  */
74         IPPROTO_RAW = 255, /* Raw IP packets.  */
75         IPPROTO_MAX +/
76       }
77     enum
78     {
79         AF_UNSPEC = 0 ,
80         AF_UNIX = 1 ,
81         AF_INET = 2 ,
82         AF_IPX = 4 ,
83         AF_APPLETALK = 5 ,
84         AF_INET6 = 10 ,
85     }
86     enum : uint
87     {
88         SCM_RIGHTS = 0x01
89     }
90     enum
91     {
92         SOMAXCONN       = 128,
93     }
94     enum : uint
95     {
96         MSG_CTRUNC      = 0x08,
97         MSG_DONTROUTE   = 0x04,
98         MSG_EOR         = 0x80,
99         MSG_OOB         = 0x01,
100         MSG_PEEK        = 0x02,
101         MSG_TRUNC       = 0x20,
102         MSG_WAITALL     = 0x100
103     }
104     /* The following constants should be used for the second parameter of
105        `shutdown'.  */
106     enum
107     {
108       SHUT_RD = 0, /* No more receptions.  */
109       SHUT_WR, /* No more transmissions.  */
110       SHUT_RDWR /* No more receptions or transmissions.  */
111     }
112                                 
113 enum: int
114 {
115         AI_PASSIVE      = 0x0001,       /// Socket address is intended for `bind'
116         AI_CANONNAME =  0x0002, /// Request for canonical name.
117         AI_NUMERICHOST = 0x0004,        /// Don't use name resolution.
118         AI_V4MAPPED = 0x0008,   /// IPv4 mapped addresses are acceptable.
119         AI_ALL = 0x0010,        /// Return IPv4 mapped and IPv6 addresses.
120         AI_ADDRCONFIG = 0x0020, /// Use configuration of this host to choose returned address type.
121         AI_NUMERICSERV = 0x0400,        /// Don't use name resolution.  
122         AI_MASK = (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_ADDRCONFIG),
123         AI_DEFAULT = (AI_V4MAPPED | AI_ADDRCONFIG),
124 }
125 
126 enum
127 {
128         EAI_BADFLAGS = -1,      /// Invalid value for `ai_flags' field.
129         EAI_NONAME = -2,        /// NAME or SERVICE is unknown.
130         EAI_AGAIN = -3, /// Temporary failure in name resolution.
131         EAI_FAIL = -4,  /// Non-recoverable failure in name res.
132         EAI_NODATA = -5,        /// No address associated with NAME.
133         EAI_FAMILY = -6,        /// `ai_family' not supported.
134         EAI_SOCKTYPE = -7,      /// `ai_socktype' not supported.
135         EAI_SERVICE = -8,       /// SERVICE not supported for `ai_socktype'.
136         EAI_MEMORY = -10,       /// Memory allocation failure.
137 }       
138 
139 enum
140 {
141         NI_MAXHOST = 1025,
142         NI_MAXSERV = 32,
143         NI_NUMERICHOST = 1,     /// Don't try to look up hostname.
144         NI_NUMERICSERV = 2,     /// Don't convert port number to name.
145         NI_NOFQDN = 4,  /// Only return nodename portion.
146         NI_NAMEREQD = 8,        /// Don't return numeric addresses.
147         NI_DGRAM = 16,  /// Look up UDP service rather than TCP.
148 }       
149 
150         
151     // non cross platform.
152     /+
153         /* Bits in the FLAGS argument to `send', `recv', et al.  */
154         enum :uint
155           {
156             MSG_PROXY = 0x10, /* Supply or ask second address.  */
157             MSG_DONTWAIT = 0x40, /* Nonblocking IO.  */
158             MSG_WAITALL = 0x100, /* Wait for a full request.  */
159             MSG_FIN = 0x200,
160             MSG_SYN = 0x400,
161             MSG_CONFIRM = 0x800, /* Confirm path validity.  */
162             MSG_RST = 0x1000,
163             MSG_ERRQUEUE = 0x2000, /* Fetch message from error queue.  */
164             MSG_NOSIGNAL = 0x4000, /* Do not generate SIGPIPE.  */
165             MSG_MORE = 0x8000, /* Sender will send more.  */
166             MSG_CMSG_CLOEXEC = 0x40000000 /* Set close_on_exit for file
167                                                    descriptor received through
168                                                    SCM_RIGHTS.  */
169           }
170     /* Standard well-known ports.  */
171     enum
172       {
173         IPPORT_ECHO = 7, /* Echo service.  */
174         IPPORT_DISCARD = 9, /* Discard transmissions service.  */
175         IPPORT_SYSTAT = 11, /* System status service.  */
176         IPPORT_DAYTIME = 13, /* Time of day service.  */
177         IPPORT_NETSTAT = 15, /* Network status service.  */
178         IPPORT_FTP = 21, /* File Transfer Protocol.  */
179         IPPORT_TELNET = 23, /* Telnet protocol.  */
180         IPPORT_SMTP = 25, /* Simple Mail Transfer Protocol.  */
181         IPPORT_TIMESERVER = 37, /* Timeserver service.  */
182         IPPORT_NAMESERVER = 42, /* Domain Name Service.  */
183         IPPORT_WHOIS = 43, /* Internet Whois service.  */
184         IPPORT_MTP = 57,
185         IPPORT_TFTP = 69, /* Trivial File Transfer Protocol.  */
186         IPPORT_RJE = 77,
187         IPPORT_FINGER = 79, /* Finger service.  */
188         IPPORT_TTYLINK = 87,
189         IPPORT_SUPDUP = 95, /* SUPDUP protocol.  */
190         IPPORT_EXECSERVER = 512, /* execd service.  */
191         IPPORT_LOGINSERVER = 513, /* rlogind service.  */
192         IPPORT_CMDSERVER = 514,
193         IPPORT_EFSSERVER = 520,
194         /* UDP ports.  */
195         IPPORT_BIFFUDP = 512,
196         IPPORT_WHOSERVER = 513,
197         IPPORT_ROUTESERVER = 520,
198         /* Ports less than this value are reserved for privileged processes.  */
199         IPPORT_RESERVED = 1024,
200         /* Ports greater this value are reserved for (non-privileged) servers.  */
201         IPPORT_USERRESERVED = 5000
202       }
203     enum
204     {
205       TCP_ESTABLISHED = 1,
206       TCP_SYN_SENT,
207       TCP_SYN_RECV,
208       TCP_FIN_WAIT1,
209       TCP_FIN_WAIT2,
210       TCP_TIME_WAIT,
211       TCP_CLOSE,
212       TCP_CLOSE_WAIT,
213       TCP_LAST_ACK,
214       TCP_LISTEN,
215       TCP_CLOSING /* now a valid state */
216     } +/