X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/4782a5c5afee47721cc617daa40dd29828342c2b..f8e139db970666e906db30417763f81e2ae5e801:/unixstuff.inc?ds=sidebyside diff --git a/unixstuff.inc b/unixstuff.inc index 76a7f52..0eb9b3d 100755 --- a/unixstuff.inc +++ b/unixstuff.inc @@ -8,6 +8,21 @@ linux.dup(original,result); end; {$define gettimeofdaysec := gettimeofday} + const + IPPROTO_UDP=17; + IPPROTO_ICMP=1; + function ntohs(invalue:word):word;inline; + var + invaluebytes : array[0..1] of byte absolute invalue; + resultbytes : array[0..1] of byte absolute result; + begin + {$ifdef endian_little} + resultbytes[0] := invaluebytes[1]; + resultbytes[1] := invaluebytes[0]; + {$else} + result := invalue; + {$endif} + end; {$else} {$define sigprocmask := fpsigprocmask} @@ -26,16 +41,75 @@ {$define dup2 := fpdup2} {$ifndef ver1_9_2} {$define flock := fpflock} - {$ifndef ver1_9_4} - procedure Execl(Todo:string);inline; - var - p : ppchar; - begin - p := unixutil.StringToPPChar(Todo,1); - if (p=nil) or (p^=nil) then exit; - fpexecv(p^,p); - end; - {$endif} + {$ifndef ver1_9_4} + procedure Execl(Todo:string);inline; + var + p : ppchar; + begin + p := unixutil.StringToPPChar(Todo,1); + if (p=nil) or (p^=nil) then exit; + fpexecv(p^,p); + end; + function SendTo(Sock: LongInt; const Buf;BufLen: LongInt;Flags: LongInt;var Addr;AddrLen: LongInt):LongInt; + begin + result := fpsendto(sock,@buf,buflen,flags,@addr,addrlen); + end; + function RecvFrom(Sock: LongInt;var Buf;Buflen: LongInt;Flags: LongInt;var Addr;var addrlen: Longint):LongInt; + begin + result := fprecvfrom(sock,@buf,buflen,flags,@addr,@addrlen); + end; + {$define socket := fpsocket} + function Bind(Sock: LongInt;const Addr;AddrLen: LongInt):Boolean; + begin + result := fpbind(sock,@addr,addrlen) = 0; + end; + function SetSocketOptions(Sock: LongInt;Level: LongInt;OptName: LongInt;const OptVal;optlen: LongInt):LongInt; + begin + result := fpsetsockopt(sock,level,optname,@optval,optlen); + end; + function Connect(Sock: LongInt;const Addr;Addrlen: LongInt):Boolean; + begin + result := fpconnect(sock,@addr,addrlen) >= 0; + end; + function listen(Sock: LongInt;MaxConnect: LongInt):Boolean; + begin + result := fplisten(sock,maxconnect) = 0; + end; + function GetPeerName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt; + begin + result := fpgetpeername(sock,@addr,@addrlen); + end; + function GetSocketName(Sock: LongInt; var Addr;var Addrlen: LongInt):LongInt; + begin + result := fpgetsockname(sock,@addr,@addrlen); + end; + function Accept(Sock: LongInt; var Addr; var Addrlen: LongInt):LongInt; + begin + result := fpaccept(sock,@addr,@addrlen); + end; + {$endif} + {$endif} + {$ifdef ver2_0} + const + IPPROTO_UDP=17; + IPPROTO_ICMP=1; + {$endif} + {$ifdef ver1_9} + const + IPPROTO_UDP=17; + IPPROTO_ICMP=1; + function ntohs(invalue:word):word;inline; + var + invaluebytes : array[0..1] of byte absolute invalue; + resultbytes : array[0..1] of byte absolute result; + begin + {$ifdef endian_little} + resultbytes[0] := invaluebytes[1]; + resultbytes[1] := invaluebytes[0]; + {$else} + result := invalue; + {$endif} + end; {$endif} procedure gettimeofday(var tv:ttimeval);inline; begin