Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Add missing network declaration for Solaris.
Browse files Browse the repository at this point in the history
These are required to compile std.socket.
  • Loading branch information
redstar committed Nov 21, 2014
1 parent 0088d0b commit 7a16090
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 29 deletions.
28 changes: 28 additions & 0 deletions src/core/sys/posix/arpa/inet.d
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,30 @@ else version( FreeBSD )
const(char)* inet_ntop(int, in void*, char*, socklen_t);
int inet_pton(int, in char*, void*);
}
else version( Solaris )
{
alias uint16_t in_port_t;
alias uint32_t in_addr_t;

struct in_addr
{
in_addr_t s_addr;
}
enum INET_ADDRSTRLEN = 16;

@trusted pure
{
uint32_t htonl(uint32_t);
uint16_t htons(uint16_t);
uint32_t ntohl(uint32_t);
uint16_t ntohs(uint16_t);
}

in_addr_t inet_addr(in char*);
char* inet_ntoa(in_addr);
const(char)* inet_ntop(int, in void*, char*, socklen_t);
int inet_pton(int, in char*, void*);
}
else version( Android )
{
alias uint32_t in_addr_t;
Expand Down Expand Up @@ -187,6 +211,10 @@ else version( FreeBSD )
{
enum INET6_ADDRSTRLEN = 46;
}
else version( Solaris )
{
enum INET6_ADDRSTRLEN = 46;
}
else version( Android )
{
enum INET6_ADDRSTRLEN = 46;
Expand Down
148 changes: 148 additions & 0 deletions src/core/sys/posix/netinet/in_.d
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,38 @@ else version( FreeBSD )

//enum INET_ADDRSTRLEN = 16;
}
else version( Solaris )
{
struct sockaddr_in
{
sa_family_t sin_family;
in_port_t sin_port;
in_addr sin_addr;
ubyte[8] sin_zero;
}

enum
{
IPPROTO_IP = 0,
IPPROTO_ICMP = 1,
IPPROTO_IGMP = 2,
IPPROTO_GGP = 3,
IPPROTO_TCP = 6,
IPPROTO_PUP = 12,
IPPROTO_UDP = 17,
IPPROTO_IDP = 22,
IPPROTO_ND = 77,
IPPROTO_MAX = 256
}

enum : uint
{
INADDR_ANY = 0x00000000,
INADDR_BROADCAST = 0xffffffff,
INADDR_LOOPBACK = 0x7f000001,
INADDR_NONE = 0xffffffff
}
}
else version( Android )
{
private enum __SOCK_SIZE__ = 16;
Expand Down Expand Up @@ -676,6 +708,118 @@ else version( FreeBSD )
__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_GLOBAL;
}
}
else version( Solaris )
{
struct in6_addr
{
union
{
uint8_t[16] s6_addr;
uint8_t[16] s6_addr8;
uint32_t[4] s6_addr32;
}
}

struct sockaddr_in6
{
sa_family_t sin6_family;
in_port_t sin6_port;
uint32_t sin6_flowinfo;
in6_addr sin6_addr;
uint32_t sin6_scope_id;
uint32_t __sin6_src_id;
}

extern __gshared immutable in6_addr in6addr_any;
extern __gshared immutable in6_addr in6addr_loopback;

struct ipv6_mreq
{
in6_addr ipv6mr_multiaddr;
uint ipv6mr_interface;
}

enum : uint
{
IPPROTO_IPV6 = 41,

//INET6_ADDRSTRLEN = 46,

IPV6_JOIN_GROUP = 9,
IPV6_LEAVE_GROUP = 10,
IPV6_MULTICAST_HOPS = 7,
IPV6_MULTICAST_IF = 6,
IPV6_MULTICAST_LOOP = 8,
IPV6_UNICAST_HOPS = 5,
IPV6_V6ONLY = 39,
}

// macros
extern (D) int IN6_IS_ADDR_UNSPECIFIED( in in6_addr* a ) pure
{
return (a.s6_addr32[0] == 0) && (a.s6_addr32[1] == 0) &&
(a.s6_addr32[2] == 0) && (a.s6_addr32[3] == 0);
}

extern (D) int IN6_IS_ADDR_LOOPBACK( in in6_addr* a ) pure
{
return (a.s6_addr32[0] == 0) && (a.s6_addr32[1] == 0) &&
(a.s6_addr32[2] == 0) && (a.s6_addr32[3] == ntohl(1));
}

extern (D) int IN6_IS_ADDR_V4COMPAT( in in6_addr* a ) pure
{
return (a.s6_addr32[0] == 0) && (a.s6_addr32[1] == 0) &&
(a.s6_addr32[2] == 0) && (a.s6_addr32[3] != 0) &&
(a.s6_addr32[3] != ntohl(1));
}

extern (D) int IN6_IS_ADDR_V4MAPPED( in in6_addr* a ) pure
{
return (a.s6_addr32[0] == 0) && (a.s6_addr32[1] == 0) &&
(a.s6_addr32[2] == ntohl(0x0000ffff));
}

extern (D) int IN6_IS_ADDR_LINKLOCAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xfe && (a.s6_addr8[1] & 0xc0) == 0x80;
}

extern (D) int IN6_IS_ADDR_SITELOCAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xfe && (a.s6_addr8[1] & 0xc0) == 0xc0;
}

extern (D) int IN6_IS_ADDR_MULTICAST( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xff;
}

extern (D) int IN6_IS_ADDR_MC_NODELOCAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xff && (a.s6_addr8[1] & 0x0f) == 0x01;
}

extern (D) int IN6_IS_ADDR_MC_LINKLOCAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xff && (a.s6_addr8[1] & 0x0f) == 0x02;
}

extern (D) int IN6_IS_ADDR_MC_SITELOCAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xff && (a.s6_addr8[1] & 0x0f) == 0x05;
}

extern (D) int IN6_IS_ADDR_MC_ORGLOCAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xff && (a.s6_addr8[1] & 0x0f) == 0x08;
}

extern (D) int IN6_IS_ADDR_MC_GLOBAL( in in6_addr* a ) pure
{
return a.s6_addr8[0] == 0xff && (a.s6_addr8[1] & 0x0f) == 0x0e;
}
}
else version( Android )
{
struct in6_addr
Expand Down Expand Up @@ -840,6 +984,10 @@ else version( FreeBSD )
{
enum uint IPPROTO_RAW = 255;
}
else version( Solaris )
{
enum uint IPPROTO_RAW = 255;
}
else version( Android )
{
enum uint IPPROTO_RAW = 255;
Expand Down
4 changes: 4 additions & 0 deletions src/core/sys/posix/netinet/tcp.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ else version( FreeBSD )
{
enum TCP_NODELAY = 1;
}
else version( Solaris )
{
enum TCP_NODELAY = 1;
}
else version( Android )
{
enum TCP_NODELAY = 1;
Expand Down
71 changes: 42 additions & 29 deletions src/core/sys/posix/sys/socket.d
Original file line number Diff line number Diff line change
Expand Up @@ -849,8 +849,13 @@ else version (Solaris)

alias double sockaddr_maxalign_t;

private enum _SS_PAD1SIZE = sockaddr_maxalign_t.sizeof - sa_family_t.sizeof;
private enum _SS_PAD2SIZE = 256 - sa_family_t.sizeof + _SS_PAD1SIZE + sockaddr_maxalign_t.sizeof;
private
{
enum _SS_ALIGNSIZE = sockaddr_maxalign_t.sizeof;
enum _SS_MAXSIZE = 256;
enum _SS_PAD1SIZE = _SS_ALIGNSIZE - sa_family_t.sizeof;
enum _SS_PAD2SIZE = _SS_MAXSIZE - sa_family_t.sizeof + _SS_PAD1SIZE + _SS_ALIGNSIZE;
}

struct sockaddr_storage
{
Expand Down Expand Up @@ -880,9 +885,11 @@ else version (Solaris)

enum : uint
{
SCM_RIGHTS = 0x1011
SCM_RIGHTS = 0x1010
}

// FIXME: CMSG_DATA, CMSG_NXTHDR, CMSG_FIRSTHDR missing

struct linger
{
int l_onoff;
Expand All @@ -904,22 +911,26 @@ else version (Solaris)

enum : uint
{
SO_ACCEPTCONN = 0x0002,
SO_BROADCAST = 0x0020,
SO_DEBUG = 0x0001,
SO_DONTROUTE = 0x0010,
SO_ERROR = 0x1007,
SO_KEEPALIVE = 0x0008,
SO_LINGER = 0x0080,
SO_OOBINLINE = 0x0100,
SO_RCVBUF = 0x1002,
SO_RCVLOWAT = 0x1004,
SO_RCVTIMEO = 0x1006,
SO_REUSEADDR = 0x0004,
SO_SNDBUF = 0x1001,
SO_SNDLOWAT = 0x1003,
SO_SNDTIMEO = 0x1005,
SO_TYPE = 0x1008
SO_ACCEPTCONN = 0x0002,
SO_BROADCAST = 0x0020,
SO_DEBUG = 0x0001,
SO_DONTROUTE = 0x0010,
SO_ERROR = 0x1007,
SO_KEEPALIVE = 0x0008,
SO_LINGER = 0x0080,
SO_OOBINLINE = 0x0100,
SO_RCVBUF = 0x1002,
SO_RCVLOWAT = 0x1004,
SO_RCVTIMEO = 0x1006,
SO_REUSEADDR = 0x0004,
SO_SNDBUF = 0x1001,
SO_SNDLOWAT = 0x1003,
SO_SNDTIMEO = 0x1005,
SO_TYPE = 0x1008,

SO_USELOOPBACK = 0x0040, // non-standard
SO_DGRAM_ERRIND = 0x0200, // non-standard
SO_RECVUCRED = 0x0400, // non-standard
}

enum
Expand All @@ -929,20 +940,22 @@ else version (Solaris)

enum : uint
{
MSG_CTRUNC = 0x10,
MSG_DONTROUTE = 0x4,
MSG_EOR = 0x8,
MSG_OOB = 0x1,
MSG_PEEK = 0x2,
MSG_TRUNC = 0x20,
MSG_WAITALL = 0x40
MSG_CTRUNC = 0x10,
MSG_DONTROUTE = 0x4,
MSG_EOR = 0x8,
MSG_OOB = 0x1,
MSG_PEEK = 0x2,
MSG_TRUNC = 0x20,
MSG_WAITALL = 0x40
}

enum
{
AF_INET = 2,
AF_UNIX = 1,
AF_UNSPEC = 0
AF_IPX = 23,
AF_APPLETALK = 16,
AF_INET = 2,
AF_UNIX = 1,
AF_UNSPEC = 0
}

enum
Expand Down
8 changes: 8 additions & 0 deletions src/core/sys/posix/sys/un.d
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ else version( FreeBSD )
byte[104] sun_path;
}
}
else version( Solaris )
{
struct sockaddr_un
{
sa_family_t sun_family;
char[108] sun_path;
}
}
else version( Android )
{
enum UNIX_PATH_MAX = 108;
Expand Down

0 comments on commit 7a16090

Please sign in to comment.