Announcement
Collapse
No announcement yet.
Class Method Problem
Collapse
X
-
You can't call the method just using ParseName, but you have to use ME.ParseName.
Leave a comment:
-
As far as I can see there is no problem with name and it is declared befored the actual method where it is used
Missing declaration - You specified that all variables must be declared before use, but this one was not declared. Use DIM, GLOBAL, INSTANCE, LOCAL, STATIC, or THREADED to declare the data type and dimensions, if an array. To declare Register Variables use the REGISTER statement.
> CLASS METHOD ParseName(VntDnsReply AS VARIANT, POS AS INTEGER) AS STRING
POS is a keyword. Maybe that is confusing the compiler.
MCM
Leave a comment:
-
Class Method Problem
I Keep getting a 519 error on a Class Method within a class. As far as I can see there is no problem with name and it is declared befored the actual method where it is used. So I am Stumped. Has any one got any Ideas ?
This is the code.
Code:#COMPILE EXE #DIM ALL #INCLUDE "wsock32.inc" %CLASS_IN = 1 'Internet class %DNS_QUERY_A= 1 'Host Address %DNS_QUERY_NS = 2 'Authoritative Name Server %DNS_QUERY_MD = 3 'Mail destination (obsolete) %DNS_QUERY_MF = 4 'Mail Forwarder (Obsolete) %DNS_QUERY_CNAME = 5 'Canonical name of an alias %DNS_QUERY_SOA = 6 'Start Zone of Authority %DNS_QUERY_MB = 7 'Mailbox Domain Name %DNS_QUERY_MG = 8 'Mail Group Member %DNS_QUERY_MR = 9 'Mail Rename Domain Name %DNS_QUERY_NULL = 10 'Null resource record %DNS_QUERY_WKS = 11 'Well Known Service description %DNS_QUERY_PTR = 12 'Domain Name Pointer %DNS_QUERY_HINFO = 13 'Host Information %DNS_QUERY_MINFO = 14 'Mailbox or Mail List information %DNS_QUERY_MX = 15 'Mail Exchange %DNS_QUERY_TXT = 16 'Text %DNS_QUERY_RP = 17 'Responsible Person %DNS_QUERY_AFSDB = 18 'AFS Data Base Location %DNS_QUERY_X25 = 19 'X.25 PSDN Address %DNS_QUERY_ISDN = 20 'ISDN Address %DNS_QUERY_RT = 21 'Route Through %DNS_QUERY_NSAP = 22 'NSAP Style A Record %DNS_QUERY_NSAP_PTR = 23 'NSAP Style A Record pointer %DNS_QUERY_SIG = 24 'Security Signature %DNS_QUERY_KEY = 25 'Security Key %DNS_QUERY_PX = 26 'X.400 Mail Mapping Information %DNS_QUERY_GPOS = 27 'Geographical Position %DNS_QUERY_AAAA = 28 'IP6 Address %DNS_QUERY_LOC = 29 'Location Information %DNS_QUERY_NXT = 30 'Next Domain %DNS_QUERY_EID = 31 'Endpoint Identifier %DNS_QUERY_NIMLOC = 32 'Nimrod Locator %DNS_QUERY_SRV = 33 'Server Selection %DNS_QUERY_IXFR = 251 'Incremental Transfer %DNS_QUERY_AXFR = 252 'Entire zone transfer %DNS_QUERY_MAILB = 253 'Mailbox-related RRs (MB, MG, or MR) %DNS_QUERY_MAILA = 254 'Mail Agent (obsolete) %DNS_QUERY_ALL = 255 'All Records %ERROR_NOERROR = 0 ' No Error %ERROR_FORMAT = 1 ' Format Error %ERROR_SERVFAIL = 2 ' Server Failure %ERROR_NXDOMAIN = 3 ' Non-Existent Domain %ERROR_NOTIMP = 4 ' Not Implemented %ERROR_REFUSED = 5 ' Query Refused %ERROR_YXDOMAIN = 6 ' Name Exists when it should not %ERROR_YXRRSET = 7 ' RR Set Exists when it should not %ERROR_NXRRSET = 8 ' RR Set that should exists does not %ERROR_NOTAUTH = 9 ' Server Not Authoritative for Zone %DNS_FLAG_QR = &H8000? %DNS_FLAG_AA = &H0800? %DNS_FLAG_TC = &H0400? %DNS_RFLAG = &H0100? %DNS_FLAG_RA = &H0100? %DNS_RCODE_MASK = &H000F? %DNS_OPCODE_MASK= &H7800? %PACKETSZ = 512 ' maximum packet size %MAXDNAME = 1025 ' maximum presentation domain name %MAXCDNAME = 255 ' maximum compressed domain name %MAXLABEL = 63 ' maximum length OF domain label %HFIXEDSZ = 12 ' bytes OF fixed data in header %QFIXEDSZ = 4 ' bytes OF fixed data in query %RRFIXEDSZ = 10 ' bytes OF fixed data in r record %INADDRSZ = 4 ' IPv4 %IN6ADDRSZ = 16 ' IPv6 T_AAAA %MAXALIASES = 35 %MAXADDRS = 35 %MAXDOMAINS = 35 %MAXSERVERS = 10 ' 'User returned error codes ' %ERROR_USER_NOERROR = 0 ' No Error or empty query %ERROR_USER_FORMAT = -9 ' Format Error %ERROR_USER_SERVFAIL = -8 ' Server Failure %ERROR_USER_NXDOMAIN = -7 ' Non-Existent Domain %ERROR_USER_NOTIMP = -6 ' Not Implemented %ERROR_USER_REFUSED = -5 ' Query Refused %ERROR_USER_YXDOMAIN = -4 ' Name Exists when it should not %ERROR_USER_YXRRSET = -3 ' RR Set Exists when it should not %ERROR_USER_NXRRSET = -2 ' RR Set that should exists does not %ERROR_USER_NOTAUTH = -1 ' Server Not Authoritative for Zone %ERROR_USER_NOQUERY = -10 ' Query length passed is null or not a query 'TODO -XXX define types for other TYPE queries TYPE MX_RECORD wPreference AS WORD szName AS ASCIIZ * 256 szDomain AS ASCIIZ * 256 szIp AS ASCIIZ * 16 END TYPE TYPE NS_RECORD szName AS ASCIIZ * 256 szDomain AS ASCIIZ * 256 END TYPE TYPE QR_REC wQueryType AS WORD wQueryClass AS WORD END TYPE TYPE DNS_HEADER 'fixed part = 12 bytes wId AS WORD ' 'Format of wBitFields is as follows 'Bit 0 (QR) 0 if Query, 1 if response 'Bits 1-4 (OPCODE) 0 if standard query, 1 if inverse query, 2 server status request 'Bit 5 (AA) if set server is authoritative 'Bit 6 (TC) if set reply size was > 512 bytes and only 512 bytes were returned (UDP only) 'Bit 7 (RD) if this bit is not set then recursion is denied 'Bit 8 (RA) if bit is set by responding server indicates that server can handle recursive queries 'Bits 9-11 (unused bits) 'Bits 12-15 (RCODE) 0 = no error, 1 malformed query, 2 server failed, 3 name does not exist ' 4 = query not supported, 5 = server refused to answer wBitFields AS WORD 'Question count wQCount AS WORD 'Answer Resource record count wARCount AS WORD 'Answer Authority record count wAAcount AS WORD 'Additional Resource record count wAAARCount AS WORD END TYPE TYPE DNS_RR_HEADER wType AS WORD 'Type code (A, MX, etc) wClass AS WORD 'Class code (IN for internet, etc) dwTTL AS DWORD 'Time to live wLength AS WORD 'Len of wRdata field (in octects) dwRData AS DWORD 'Field name address (variable length) END TYPE TYPE T_QUERY tHeader AS DNS_HEADER tQrRec AS QR_REC END TYPE UNION U_PARSE_PTR bPtr AS BYTE PTR wPtr AS WORD PTR lPtr AS LONG PTR dwPtr AS DWORD PTR END UNION TYPE sockaddralt sin_family AS INTEGER sin_port AS INTEGER sin_addr AS LONG sin_zero AS STRING * 8 END TYPE GLOBAL DNS_Root AS STRING GLOBAL DNS_Answers AS INTEGER GLOBAL DNS_AuthRRs AS INTEGER GLOBAL DNS_AddRRs AS INTEGER GLOBAL DNS_Answer() AS STRING GLOBAL DNS_Type() AS INTEGER GLOBAL DNS_AuthRR() AS STRING GLOBAL DNS_AddRR() AS STRING CLASS EmailClient INSTANCE Email AS STRING CLASS METHOD MakeQName(sDomain AS STRING) AS STRING ' Takes sDomain and converts it to the QNAME-type string, returns that. QNAME is how a ' DNS server expects the string. ' ' Ex... Pass - mail.com ' Returns - &H4mail&H3com '************************************************************************* LOCAL QName AS STRING LOCAL QTmp AS STRING LOCAL QPart AS STRING QName="" QTmp=sDomain DO UNTIL QTmp="" QPart = EXTRACT$(QTmp,".") QName = QName & CHR$(LEN(QPart)) & QPart QTmp = REMAIN$(QTmp,".") LOOP METHOD = QName END METHOD CLASS METHOD ParseName(VntDnsReply AS VARIANT, POS AS INTEGER) AS STRING LOCAL sName AS STRING LOCAL sTmp AS STRING LOCAL sLEN AS INTEGER LOCAL Cnt AS INTEGER LOCAL dnsReply() AS BYTE sName="" LET DnsReply() = VntDnsReply sLen=-1 DO UNTIL sLEN=0 sLEN=dnsReply(POS) IF sLEN<>0 AND sLEN < 192 THEN FOR Cnt=1 TO sLEN sName = sName & CHR$(dnsReply(POS+Cnt)) NEXT Cnt POS=POS + sLen + 1 sName = sName + "." ELSE IF sLEN>=192 THEN POS=((sLEN-192)*256) + dnsReply(POS+1) END IF LOOP METHOD = TRIM$(sName,".") END METHOD INTERFACE VerifyEmail INHERIT IUNKNOWN METHOD DNS_Query(DNSDomain AS STRING, DNSServer AS STRING, DNSQuery AS INTEGER, ErrorCode AS STRING) AS STRING LOCAL StartupData AS WSAdata LOCAL SocketBuffer AS sockaddralt LOCAL IpAddr AS LONG LOCAL iRC AS INTEGER LOCAL dnsHead AS DNS_HEADER LOCAL iSock AS INTEGER LOCAL DNSDomainTemp AS STRING LOCAL dnsQuery() AS BYTE LOCAL dnsReply() AS BYTE LOCAL dnsQueryLen AS INTEGER LOCAL dnsReplyLen AS INTEGER LOCAL sQName AS STRING LOCAL dnsQueryNdx AS INTEGER LOCAL dnsReplyNdx AS INTEGER LOCAL iTemp AS INTEGER LOCAL iNdx AS INTEGER LOCAL iAnCount AS INTEGER LOCAL I AS INTEGER LOCAL VntDnsReply AS VARIANT ' Initialise the Method METHOD = "" DNS_Root = DNSDomain ' ' Setup Buffers dnsQueryLen = 4096 dnsReplyLen = 8192 REDIM dnsQuery(dnsQueryLen) REDIM dnsReply(dnsReplyLen) DNSDomainTemp=TRIM$(DNSDomain) ' Initialize the Winsocket Winsock Version and point to the WSData structure ' it returns 0 if there was no problem a non zero value is an error iRC = WSAStartup(&H101, StartupData) IF iRC <> 0 THEN errorcode = "Startup Error +" + STR$(iRC): GOTO 999 ' Create a socket iSock = socket(%AF_INET, %SOCK_DGRAM, 0) IF iSock = %INVALID_SOCKET THEN ErrorCode = "Socket Failure": GOTO 900 ' get the ip address of dns server HOST ADDR DNSServer TO IpAddr IF IpAddr = -1 THEN ErrorCode = " Faulty DNS Server":GOTO 900 ' ' Setup the connnection parameters SocketBuffer.sin_family = %AF_INET SocketBuffer.sin_port = htons(53) SocketBuffer.sin_addr = IpAddr SocketBuffer.sin_zero = STRING$(8, 0) ' ' Set the DNS parameters dnsHead.wId = htons(&H11DF) ' dnsHead.qryID = htons(&H11DF) dnsHead.wBitFields = 1 ' dnsHead.options = DNS_RECURSION dnsHead.wQCount = htons(1) ' dnsHead.qdcount = htons(1) dnsHead.wARCount = 0 ' dnsHead.ancount = 0 dnsHead.wAAcount = 0 ' dnsHead.nscount = 0 dnsHead.wAAARCount = 0 ' dnsHead.arcount = 0 dnsQueryNdx = 0 ' Setup the dns structure to send the query in ' First goes the DNS header information MoveMemory BYVAL VARPTR(dnsQuery(dnsQueryNdx)) , BYVAL VARPTR(dnsHead), 12 dnsQueryNdx = dnsQueryNdx + 12 ' Then the domain name (as a QNAME) sQName = Me.MakeQName(DNSDomainTemp) + CHR$(0) FOR iNdx = 0 TO LEN(sQName)-1 dnsQuery(dnsQueryNdx + iNdx) = ASC(MID$(sQName, iNdx + 1, 1)) NEXT iNdx dnsQueryNdx = dnsQueryNdx + LEN(sQName) iTemp = htons(DNSQuery) MoveMemory BYVAL VARPTR(dnsQuery(dnsQueryNdx)), BYVAL VARPTR(iTemp), 2 dnsQueryNdx = dnsQueryNdx + LEN(iTemp) iTemp = htons(%CLASS_IN) MoveMemory BYVAL VARPTR(dnsQuery(dnsQueryNdx)), BYVAL VARPTR(iTemp), 2 dnsQueryNdx = dnsQueryNdx + LEN(iTemp) REDIM PRESERVE dnsQuery(dnsQueryNdx - 1) ' Send the query to the DNS server ' if the return value is the number of bytes then the process succeeded ' any thing else is an error iRC = sendto(iSock, dnsQuery(0), dnsQueryNdx + 1, 0, SocketBuffer, LEN(SocketBuffer)) 'msgbox str$(iRC) +":"+str$(LEN(SocketBuffer)) IF iRC <= LEN(SocketBuffer) THEN ErrorCode = " Socket Send Failure":GOTO 900 ' Wait for answer from the DNS server ' the return value is number of bytes received iRC = recvfrom(iSock, dnsReply(0), dnsReplyLen, 0, SocketBuffer, LEN(SocketBuffer)) 'MSGBOX STR$(iRC) +":"+STR$(LEN(SocketBuffer)) IF iRC <= LEN(SocketBuffer) THEN ErrorCode = "Socket Recv Failure":GOTO 900 ' Get Header MoveMemory BYVAL VARPTR(dnsHead) , BYVAL VARPTR(dnsReply(0)), 12 DNS_Answers = ntohs(dnsHead.wARCount) DNS_AuthRRs = ntohs(dnsHead.wAAcount) DNS_AddRRs = ntohs(dnsHead.wAAARCount) 'Move reply flag pass header + Domain Name + Type + Class dnsReplyNdx = 12 + LEN(sQName) + 2 + 2 'Answers IF DNS_Answers>0 THEN REDIM DNS_Answer(DNS_Answers) REDIM DNS_Type(DNS_Answers) FOR iANCount=1 TO DNS_Answers 'Skip Ptr and get Type MoveMemory BYVAL VARPTR(iTemp) , BYVAL VARPTR(dnsReply(dnsReplyNdx+2)), 2 DNS_Type(iAnCount)=ntohs(iTemp) 'Skip class + TTL and get length MoveMemory BYVAL VARPTR(iTemp) , BYVAL VARPTR(dnsReply(dnsReplyNdx+10)), 2 ' Get Record SELECT CASE DNS_Type(iAnCount) CASE %DNS_QUERY_A DNS_Answer(iAnCount) = TRIM$(STR$(dnsReplyNdx+12)) & "." & TRIM$(STR$(dnsReplyNdx+13)) & _ "." & TRIM$(STR$(dnsReplyNdx+14)) & "." & TRIM$(STR$(dnsReplyNdx+15)) CASE %DNS_QUERY_NS VntDnsReply = dnsReply() DNS_Answer(iAnCount) = ParseName(VntDnsReply,dnsReplyNdx+12) CASE %DNS_QUERY_MX VntDnsReply = dnsReply() DNS_Answer(iAnCount) = TRIM$(STR$((dnsReply(dnsReplyNdx+12)*256) + dnsReply(dnsReplyNdx+13))) & "," DNS_Answer(iAnCount) = DNS_Answer(iAnCount) + ParseName(VntDnsReply,dnsReplyNdx+14) CASE ELSE 'NOP DNS_Answer(iAnCount) = CopyDNSStream(dnsReply(),dnsReplyNdx+12,ntohs(iTemp)) END SELECT dnsReplyNdx = dnsReplyNdx + 12 + ntohs(iTemp) NEXT iANCount END IF 'Authorised RRs IF DNS_AuthRRs>0 THEN REDIM DNS_AuthRR(DNS_AuthRRs) FOR iANCount=0 TO DNS_AuthRRs-1 DNS_AuthRR(iAnCount) = TRIM$(STR$(dnsReplyNdx+12+(iANCount*16))) & "." & TRIM$(STR$(dnsReplyNdx+13+(iANCount*16))) & _ "." & TRIM$(STR$(dnsReplyNdx+14+(iANCount*16))) & "." & TRIM$(STR$(dnsReplyNdx+15+(iANCount*16))) NEXT iANCount dnsReplyNdx = dnsReplyNdx + (16 * DNS_AuthRRs) END IF 'Additional RRs IF DNS_AddRRs>0 THEN REDIM DNS_AddRR(DNS_AddRRs) FOR iANCount=0 TO DNS_AddRRs-1 DNS_AddRR(iAnCount) = TRIM$(STR$(dnsReplyNdx+12+(iANCount*16))) & "." & TRIM$(STR$(dnsReplyNdx+13+(iANCount*16))) & _ "." & TRIM$(STR$(dnsReplyNdx+14+(iANCount*16))) & "." & TRIM$(STR$(dnsReplyNdx+15+(iANCount*16))) NEXT iANCount dnsReplyNdx = dnsReplyNdx + (16 * DNS_AddRRs) END IF ' close the socket connection 900 closesocket iSock ' cleanup after the query 999 WSACleanup END METHOD END INTERFACE END CLASS FUNCTION PBMAIN () AS LONG END FUNCTION
Tags: None
Leave a comment: