-function longip(s:string):longint;{$ifdef fpc}inline;{$endif}\r
-var\r
- l:longint;\r
- a,b:integer;\r
-\r
-function convertbyte(const s:string):integer;{$ifdef fpc}inline;{$endif}\r
-begin\r
- result := strtointdef(s,-1);\r
- if result < 0 then exit;\r
- if result > 255 then exit;\r
-\r
- {01 exception}\r
- if (result <> 0) and (s[1] = '0') then begin\r
- result := -1;\r
- exit;\r
- end;\r
-\r
- {+1 exception}\r
- if not (s[1] in ['0'..'9']) then begin\r
- result := -1;\r
- exit\r
- end;\r
-end;\r
-\r
-begin\r
- result := 0;\r
- a := pos('.',s);\r
- if a = 0 then exit;\r
- b := convertbyte(copy(s,1,a-1));if (b < 0) then exit;\r
- l := b shl 24;\r
- s := copy(s,a+1,256);\r
- a := pos('.',s);\r
- if a = 0 then exit;\r
- b := convertbyte(copy(s,1,a-1));if (b < 0) then exit;\r
- l := l or b shl 16;\r
- s := copy(s,a+1,256);\r
- a := pos('.',s);\r
- if a = 0 then exit;\r
- b := convertbyte(copy(s,1,a-1));if (b < 0) then exit;\r
- l := l or b shl 8;\r
- s := copy(s,a+1,256);\r
- b := convertbyte(copy(s,1,256));if (b < 0) then exit;\r
- l := l or b;\r
- result := l;\r
-end;\r
-\r
-(*!!!\r
-function longipdns(s:string):longint;\r
-var\r
- host : thostentry;\r
-begin\r
- if s = '0.0.0.0' then begin\r
- result := 0;\r
- end else begin\r
- result := longip(s);\r
- if result = 0 then begin\r
- if gethostbyname(s,host) then begin;\r
- result := htonl(Longint(Host.Addr));\r
- end;\r
- //writeln(inttohex(longint(host.addr),8))\r
- end;\r
- if result = 0 then begin\r
- if resolvehostbyname(s,host) then begin;\r
- result := htonl(Longint(Host.Addr));\r
- end;\r
- //writeln(inttohex(longint(host.addr),8))\r
- end;\r
- end;\r
-end;\r
-*)\r
-\r
-\r
-function htons(w:word):word;\r
-begin\r
- {$ifndef ENDIAN_BIG}\r
- result := ((w and $ff00) shr 8) or ((w and $ff) shl 8);\r
- {$else}\r
- result := w;\r
- {$endif}\r
-end;\r
-\r
-function htonl(i:integer):integer;\r
-begin\r
- {$ifndef ENDIAN_BIG}\r
- result := (i shr 24) or (i shr 8 and $ff00) or (i shl 8 and $ff0000) or (i shl 24 and $ff000000);\r
- {$else}\r
- result := i;\r
- {$endif}\r
-end;\r