|
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
namespace posix #import "<unistd.h>" #import "<sys/ioctl.h>" #import "<sys/types.h>" #import "<sys/socket.h>" #import "<netdb.h>" #import "<errno.h>" #import "<libc>" Using libc extern Class sockaddr Extends Void End Class sockaddr_in Extends sockaddr Field sin_family:Short Field sin_port:UShort Field sin_addr:ULong Field pad0:Int Field pad1:Int End Class sockaddr_in6 Extends sockaddr Field sin6_family:Ushort Field sin6_port:UShort Field sin6_flowinfo:UInt Field sin6_addr:int Field sin6_addr1:Int Field sin6_addr2:Int Field sin6_addr3:Int Field sin6_scopeid:Int End Class addrinfo Extends Void Field ai_flags:Int ' input flags Field ai_family:Int ' protocol family for socket Field ai_socktype:Int ' socket type Field ai_protocol:Int ' protocol for socket Field ai_addrlen:Int ' length of socket-address Field ai_addr:sockaddr ' socket-address for socket Field ai_canonname:char_t ptr ' canonical name for service location Field ai_next:addrinfo ' pointer to next in list end Function open:Int( path:CString,mode:Int ) function ioctl:int( fd:int,request:uint,memory:void ptr) function ioctl:int( fd:int,request:uint,value:int) function read:int( fd:int,buffer:void ptr,count:uint) function write:int( fd:int,buffer:void ptr,count:uint) Function close:Int( fd:int) Function connect:int(sock:Int,addr:sockaddr,addrlen:Int) Function listen:int(fd:Int,backlog:Int) Function bind:Int(fd:Int,addr:sockaddr,addrlen:Int) Function setsockopt:Int(fd:Int,level:Int,name:Int,val:Void Ptr,size:Int) Function accept:Int(fd:Int,addr:sockaddr,addrlen:uInt Ptr) Function recv:Int(fd:int,buffer:Void ptr,BufferSize:int,flags:Int) Function send:Int(fd:int,buffer:Void ptr,BufferSize:int,flags:Int) Function getaddrinfo:Int(hostname:CString, servername:CString, hints:addrinfo, res:addrinfo ptr) Function freeaddrinfo(ai:addrinfo) Function socket:Int(domain:Int,socketType:Int,socketProtocol:Int) Global errno:Int Global AF_INET:Int Global AF_INET6:int Global PF_INET6:int Global SOCK_STREAM:int Function strerror:char_t Ptr(error:Int) Public Function ErrorString:String() Local result:=errno Local s:=strerror(errno) Return String.FromCString(s) end |
Due to a respite in employment conditions I have been continuing to focus on linux pi skills and knowledge.
https://github.com/nitrologic/m2/tree/master/vhost
I suspect some subtle difference between linux and macos on the socket front but am happy with the basic tcp and udp implementations.
It is interesting to see what works in ipv6 and what doesn’t so there is still some stuff to do on the socket encapsulation.
]]>