localaddr:string;\r
localport:string;\r
proto:string;\r
- udp:boolean;\r
+ udp,dgram:boolean;\r
listenqueue:integer;\r
{$ifdef secondlistener}\r
secondlistener:tlsocket;\r
\r
procedure tlsocket.realconnect;\r
var\r
- a:integer;\r
-\r
+ a,b:integer;\r
begin\r
// writeln('trying to connect to ',ipbintostr(biniplist_get(biniplist,currentip)),'#',port);\r
makeinaddrv(biniplist_get(biniplist,currentip),port,inaddr);\r
inc(currentip);\r
if (currentip >= biniplist_getcount(biniplist)) then trymoreips := false;\r
- udp := uppercase(proto) = 'UDP';\r
- if udp then a := SOCK_DGRAM else a := SOCK_STREAM;\r
- a := Socket(inaddr.inaddr.family,a,0);\r
+\r
+ udp := false;\r
+ if (uppercase(proto) = 'UDP') then begin\r
+ b := IPPROTO_UDP;\r
+ a := SOCK_DGRAM;\r
+ udp := true;\r
+ dgram := true;\r
+ end else if (uppercase(proto) = 'TCP') then begin\r
+ b := IPPROTO_TCP;\r
+ a := SOCK_STREAM;\r
+ dgram := false;\r
+ end else begin\r
+ b := strtointdef(proto,IPPROTO_ICMP);\r
+ a := SOCK_RAW;\r
+ dgram := true;\r
+ end;\r
+\r
+ a := Socket(inaddr.inaddr.family,a,b);\r
//writeln(ord(inaddr.inaddr.family));\r
if a = -1 then begin\r
lasterror := {$ifdef win32}getlasterror{$else}socketerror{$endif};\r
try\r
dup(a);\r
bindsocket;\r
- if udp then begin\r
+ if dgram then begin\r
{$ifndef win32}\r
SetSocketOptions(fdhandleout, SOL_SOCKET, SO_BROADCAST, 'TRUE', Length('TRUE'));\r
{$endif}\r
\r
procedure tlsocket.sendstr(const str : string);\r
begin\r
- if udp then begin\r
+ if dgram then begin\r
send(@str[1],length(str))\r
end else begin\r
inherited sendstr(str);\r
\r
function tlsocket.send(data:pointer;len:integer):integer;\r
begin\r
- if udp then begin\r
+ if dgram then begin\r
// writeln('sending to '+ipbintostr(inaddrvtobinip(inaddr)),' ',htons(inaddr.inaddr.port),' ',len,' bytes');\r
result := sendto(inaddr,getaddrsize,data,len);\r
\r
\r
function tlsocket.receive(Buf:Pointer;BufSize:integer):integer;\r
begin\r
- if udp then begin\r
+ if dgram then begin\r
{$ifdef secondlistener}\r
if lastsessionfromsecond then begin\r
result := secondlistener.receive(buf,bufsize);\r
localaddr := '0.0.0.0';\r
end;\r
//gethostbyname(localaddr,host);\r
-\r
inaddrtempsize := makeinaddrv(forwardlookup(localaddr,0),localport,inaddrtemp);\r
\r
If Bind(fdhandlein,inaddrtempx,inaddrtempsize)<> {$ifdef win32}0{$else}true{$endif} Then begin\r
eventcore.rmasterclr(fdhandlein);\r
if assigned(onsessionAvailable) then onsessionAvailable(self,0);\r
end;\r
- if udp and readtrigger then begin\r
+ if dgram and readtrigger then begin\r
if assigned(ondataAvailable) then ondataAvailable(self,0);\r
{!!!test}\r
exit;\r