-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02a2e69
commit 79bdd17
Showing
17 changed files
with
624 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{% skip_file if flag?(:win32) %} | ||
# TODO | ||
# {% skip_file if flag?(:win32) %} | ||
|
||
require "crystal/thread_local_value" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "../winnt" | ||
|
||
lib LibC | ||
fun inet_ntop(family : INT, pAddr : PVOID, pStringBuf : PSTR, stringBufSize : SizeT) : PCSTR | ||
fun inet_pton(family : INT, pszAddrString : PCSTR, pAddrBuf : PVOID) : INT | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require "./sys/socket" | ||
|
||
lib LibC | ||
O_RDONLY = 0x0000 | ||
O_WRONLY = 0x0001 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# DIFF | ||
# require "./netinet/in" | ||
# require "./stdint" | ||
require "./sys/socket" | ||
|
||
#@[Link(ldflags: "WS2tcpip.obj")] | ||
@[Link("Kernel32")] | ||
lib LibC | ||
AI_PASSIVE = 0x0001 | ||
AI_CANONNAME = 0x0002 | ||
AI_NUMERICHOST = 0x0004 | ||
AI_ALL = 0x0100 | ||
AI_ADDRCONFIG = 0x0400 | ||
AI_V4MAPPED = 0x0800 | ||
AI_NON_AUTHORITATIVE = 0x04000 | ||
AI_SECURE = 0x08000 | ||
AI_RETURN_PREFERRED_NAMES = 0x010000 | ||
AI_FQDN = 0x00020000 | ||
AI_FILESERVER = 0x00040000 | ||
|
||
# lin | ||
AI_NUMERICSERV = 0x0400 | ||
|
||
# move to sys/socket | ||
AF_UNSPEC = 0 | ||
AF_INET = 2 | ||
AF_IPX = 6 | ||
AF_APPLETALK = 16 | ||
AF_NETBIOS = 17 | ||
AF_INET6 = 23 | ||
AF_IRDA = 26 | ||
AF_BTH = 32 | ||
|
||
# lin | ||
PF_INET = 2 | ||
PF_INET6 = 10 | ||
PF_UNIX = LibC::PF_LOCAL | ||
PF_UNSPEC = 0 | ||
PF_LOCAL = 1 | ||
AF_UNIX = LibC::PF_UNIX | ||
|
||
## lin | ||
EAI_AGAIN = -3 | ||
EAI_BADFLAGS = -1 | ||
EAI_FAIL = -4 | ||
EAI_FAMILY = -6 | ||
EAI_MEMORY = -10 | ||
EAI_NONAME = -2 | ||
EAI_SERVICE = -8 | ||
EAI_SOCKTYPE = -7 | ||
EAI_SYSTEM = -11 | ||
EAI_OVERFLOW = -12 | ||
|
||
# move to sys/socket | ||
SOCK_STREAM = 1 | ||
SOCK_DGRAM = 2 | ||
SOCK_RAW = 3 | ||
SOCK_RDM = 4 | ||
SOCK_SEQPACKET = 5 | ||
|
||
# move to netinet/in | ||
IPPROTO_TCP = 6 | ||
IPPROTO_UDP = 17 | ||
IPPROTO_RM = 113 | ||
IPPROTO_IGMP = 2 | ||
# ipcp | ||
BTHPROTO_RFCOMM = 3 | ||
IPPROTO_ICMPV6 = 58 | ||
|
||
## lin | ||
IPPROTO_IP = 0 | ||
IPPROTO_RAW = 255 | ||
IPPROTO_ICMP = 1 | ||
|
||
struct Addrinfo | ||
ai_flags : Int | ||
ai_family : Int | ||
ai_socktype : Int | ||
ai_protocol : Int | ||
ai_addrlen : SizeT | ||
ai_canonname : UInt8* | ||
ai_addr : Sockaddr* | ||
ai_next : Addrinfo* | ||
end | ||
|
||
alias ADDRINFOA = Addrinfo | ||
alias PADDRINFOA = Addrinfo* | ||
|
||
fun freeaddrinfo(pAddrInfo : PADDRINFOA) : VOID | ||
fun getaddrinfo(pNodeName : PCSTR, pServiceName : PCSTR, pHints : ADDRINFOA*, ppResult : PADDRINFOA*) : INT | ||
fun getnameinfo(pSockaddr : SOCKADDR*, sockaddrLength : SocklenT, pNodeBuffer : PCHAR, nodeBufferSize : DWORD, pServiceBuffer : PCHAR, serviceBufferSize : DWORD, flags : INT) : INT | ||
#fun gai_strerror = gai_strerrorA(ecode : Int) : UInt8* | ||
fun formatMessageA = FormatMessageA(dwFlags : DWORD, lpSource : LPCVOID, dwMessageId : DWORD, dwLanguageId : DWORD, lpBuffer : LPSTR, nSize : DWORD, ...) : DWORD | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require "../sys/socket" | ||
require "../winnt.cr" | ||
|
||
lib LibC | ||
struct SUnB | ||
s_b1 : UCHAR | ||
s_b2 : UCHAR | ||
s_b3 : UCHAR | ||
s_b4 : UCHAR | ||
end | ||
|
||
struct SUnW | ||
s_w1 : USHORT | ||
s_w2 : USHORT | ||
end | ||
|
||
union InAddrU | ||
s_un_b : SUnB | ||
s_un_w : SUnW | ||
s_addr : ULONG | ||
end | ||
|
||
struct InAddr | ||
s_un : InAddrU | ||
end | ||
|
||
union In6AddrIn6U | ||
byte : StaticArray(UCHAR, 16) | ||
word : StaticArray(USHORT, 8) | ||
end | ||
|
||
struct In6Addr | ||
u : In6AddrIn6U | ||
end | ||
|
||
struct SockaddrIn6 | ||
sin6_family : SHORT | ||
sin6_port : USHORT | ||
sin6_flowinfo : ULONG | ||
sin6_addr : In6Addr | ||
sin6_scope_id : ULONG | ||
end | ||
|
||
struct SockaddrIn | ||
sin_family : SHORT | ||
sin_port : USHORT | ||
sin_addr : InAddr | ||
sin_zero : StaticArray(CHAR, 8) | ||
end | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require "./types" | ||
|
||
@[Link("WS2_32")] | ||
lib LibC | ||
alias SocklenT = UInt | ||
alias SaFamilyT = UShort | ||
|
||
SO_REUSEADDR = 0x0004 | ||
SO_BROADCAST = 0x0020 | ||
SOL_SOCKET = 0xFFFF | ||
|
||
struct Sockaddr | ||
sa_family : SaFamilyT | ||
sa_data : StaticArray(Char, 14) | ||
end | ||
|
||
alias SOCKADDR = Sockaddr | ||
|
||
FIONBIO = -2147195266 # -2147195266 is the value after convertion to long, actual value 2147772030 with type unsigned | ||
|
||
alias SOCKET = UInt | ||
fun socket(af : Int, type : Int, protocol : Int) : SOCKET | ||
fun bind(s : SOCKET, addr : Sockaddr*, namelen : Int) : Int | ||
fun closesocket(s : SOCKET) : Int | ||
fun send(s : SOCKET, buf : UInt8*, len : Int, flags : Int) : Int | ||
fun setsockopt(s : SOCKET, level : Int, optname : Int, optval : UInt8*, len : Int) : Int | ||
fun ioctlsocket(s : SOCKET, cmd : Int, argp : UInt32*) : Int | ||
fun listen(s : SOCKET, backlog : Int) : Int | ||
fun accept(s : SOCKET, addr : Sockaddr*, addrlen : Int*) : SOCKET | ||
fun getpeername(s : SOCKET, name : Sockaddr*, namelen : Int*) : Int | ||
fun ntohs(netshort : UShort) : UShort | ||
fun recv(s : SOCKET, buf : UInt8*, len : Int, flags : Int) : Int | ||
fun connect(s : SOCKET, name : Sockaddr*, namelen : Int) : Int | ||
fun getsockname(s : SOCKET, name : Sockaddr*, namelen : Int*) : Int | ||
fun htons(hostshort : UShort) : UShort | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.