From: plugwash Date: Sun, 30 Mar 2008 01:33:59 +0000 (+0000) Subject: * add method to tell if a string is a biniplist X-Git-Url: http://www.lcore.org/git/lcore.git/commitdiff_plain/495c276d681a5b3f79d4b2af2ed36e8e5d9e993d * add method to tell if a string is a biniplist * allow a biniplist to be used for the addr field in a tlsocket git-svn-id: file:///svnroot/lcore/trunk@8 b1de8a11-f9be-4011-bde0-cc7ace90066a --- diff --git a/binipstuff.pas b/binipstuff.pas index 0c23533..59d123b 100755 --- a/binipstuff.pas +++ b/binipstuff.pas @@ -124,6 +124,7 @@ procedure biniplist_setcount(var l:tbiniplist;newlen:integer); procedure biniplist_free(var l:tbiniplist); procedure biniplist_addlist(var l:tbiniplist;const l2:tbiniplist); function biniplist_tostr(const l:tbiniplist):string; +function isbiniplist(const l:tbiniplist):boolean; function htons(w:word):word; function htonl(i:uint32):uint32; @@ -512,11 +513,15 @@ begin {$endif} end; -{------------------------------------------------------------------------------} +{-----------biniplist stuff--------------------------------------------------} + +const + biniplist_prefix='bipl'#0; + biniplist_prefixlen=length(biniplist_prefix); function biniplist_new:tbiniplist; begin - result := ''; + result := biniplist_prefix; end; procedure biniplist_add(var l:tbiniplist;ip:tbinip); @@ -530,7 +535,7 @@ end; function biniplist_getcount(const l:tbiniplist):integer; begin - result := length(l) div sizeof(tbinip); + result := (length(l)-biniplist_prefixlen) div sizeof(tbinip); end; function biniplist_get(const l:tbiniplist;index:integer):tbinip; @@ -539,18 +544,18 @@ begin fillchar(result,sizeof(result),0); exit; end; - move(l[index*sizeof(tbinip)+1],result,sizeof(result)); + move(l[index*sizeof(tbinip)+1+biniplist_prefixlen],result,sizeof(result)); end; procedure biniplist_set(var l:tbiniplist;index:integer;ip:tbinip); begin uniquestring(l); - move(ip,l[index*sizeof(tbinip)+1],sizeof(ip)); + move(ip,l[index*sizeof(tbinip)+1+biniplist_prefixlen],sizeof(ip)); end; procedure biniplist_setcount(var l:tbiniplist;newlen:integer); begin - setlength(l,sizeof(tbinip)*newlen); + setlength(l,(sizeof(tbinip)*newlen)+biniplist_prefixlen); end; procedure biniplist_free(var l:tbiniplist); @@ -575,4 +580,17 @@ begin result := result + ')'; end; +function isbiniplist(const l:tbiniplist):boolean; +var + i : integer; +begin + for i := 1 to biniplist_prefixlen do begin + if biniplist_prefix[i] <> l[i] then begin + result := false; + exit; + end; + end; + result := true; +end; + end. diff --git a/lcoretest.dpr b/lcoretest.dpr index f6fe72b..9c4ec7c 100755 --- a/lcoretest.dpr +++ b/lcoretest.dpr @@ -115,9 +115,15 @@ begin end; procedure tsc.dnsrequestdone(sender:tobject;error : word); +var + tempbinip : tbinip; + tempbiniplist : tbiniplist; begin writeln('irc.ipv6.p10link.net resolved to '+das.dnsresult+' connecting client socket there'); - clientsocket.addr := das.dnsresult; + das.dnsresultbin(tempbinip); + tempbiniplist := biniplist_new; + biniplist_add(tempbiniplist,tempbinip); + clientsocket.addr := tempbiniplist; clientsocket.port := '6667'; clientsocket.connect; writeln(clientsocket.getxaddr); diff --git a/lsocket.pas b/lsocket.pas index e56a25d..f4c8349 100755 --- a/lsocket.pas +++ b/lsocket.pas @@ -218,8 +218,7 @@ var begin if state <> wsclosed then close; //prevtime := 0; - - biniplist := forwardlookuplist(addr,0); + if isbiniplist(addr) then biniplist := addr else biniplist := forwardlookuplist(addr,0); if biniplist_getcount(biniplist) = 0 then raise exception.create('unable to resolve '+addr); //makeinaddrv(addr,port,inaddr); @@ -321,7 +320,7 @@ begin {$endif} addr := '0.0.0.0'; end; - biniptemp := forwardlookup(addr,10); + if isbiniplist(addr) then biniptemp := biniplist_get(addr,0) else biniptemp := forwardlookup(addr,10); addr := ipbintostr(biniptemp); fdhandlein := socket(biniptemp.family,socktype,0); {$ifdef ipv6}