ReactOS 0.4.16-dev-2491-g3dc6630
utility.c File Reference
#include "nslookup.h"
#include <assert.h>
Include dependency graph for utility.c:

Go to the source code of this file.

Functions

BOOL SendRequest (PCHAR pInBuffer, ULONG InBufferLength, PCHAR pOutBuffer, PULONG pOutBufferLength)
 
void ReverseIP (PCHAR pIP, PCHAR pReturn)
 
BOOL IsValidIP (PCHAR pInput)
 
int ExtractName (PCHAR pBuffer, PCHAR pOutput, USHORT Offset, UCHAR Limit)
 
int ExtractIP (PCHAR pBuffer, PCHAR pOutput, USHORT Offset)
 
void PrintD2 (PCHAR pBuffer, DWORD BufferLength)
 
void PrintDebug (PCHAR pBuffer, DWORD BufferLength)
 
PCHAR OpcodeIDtoOpcodeName (UCHAR Opcode)
 
PCHAR RCodeIDtoRCodeName (UCHAR RCode)
 
PCHAR TypeIDtoTypeName (USHORT TypeID)
 
USHORT TypeNametoTypeID (PCHAR TypeName)
 
PCHAR ClassIDtoClassName (USHORT ClassID)
 
USHORT ClassNametoClassID (PCHAR ClassName)
 

Function Documentation

◆ ClassIDtoClassName()

PCHAR ClassIDtoClassName ( USHORT  ClassID)

Definition at line 839 of file utility.c.

840{
841 switch( ClassID )
842 {
843 case CLASS_IN:
844 return ClassIN;
845
846 case CLASS_ANY:
847 return ClassAny;
848
849 default:
850 return "Unknown";
851 }
852}
#define CLASS_IN
Definition: nslookup.h:36
#define ClassAny
Definition: nslookup.h:34
#define CLASS_ANY
Definition: nslookup.h:37
#define ClassIN
Definition: nslookup.h:33

Referenced by PrintD2(), and PrintDebug().

◆ ClassNametoClassID()

USHORT ClassNametoClassID ( PCHAR  ClassName)

Definition at line 854 of file utility.c.

855{
856 if( !strncmp( ClassName, ClassIN, strlen( ClassIN ) ) ) return CLASS_IN;
857 if( !strncmp( ClassName, ClassAny, strlen( ClassAny ) ) ) return CLASS_ANY;
858
859 return 0;
860}
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1592
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3330

Referenced by PerformLookup().

◆ ExtractIP()

int ExtractIP ( PCHAR  pBuffer,
PCHAR  pOutput,
USHORT  Offset 
)

Definition at line 403 of file utility.c.

404{
405 int c = 0, l = 0, i = 0, v = 0;
406
407 i = Offset;
408
409 v = (UCHAR)pBuffer[i];
410 l += 1;
411 i += 1;
412
413 sprintf( &pOutput[c], "%d.", v );
414 c += strlen( &pOutput[c] );
415
416 v = (UCHAR)pBuffer[i];
417 l += 1;
418 i += 1;
419
420 sprintf( &pOutput[c], "%d.", v );
421 c += strlen( &pOutput[c] );
422
423 v = (UCHAR)pBuffer[i];
424 l += 1;
425 i += 1;
426
427 sprintf( &pOutput[c], "%d.", v );
428 c += strlen( &pOutput[c] );
429
430 v = (UCHAR)pBuffer[i];
431 l += 1;
432 i += 1;
433
434 sprintf( &pOutput[c], "%d", v );
435 c += strlen( &pOutput[c] );
436
437 pOutput[c] = '\0';
438
439 return l;
440}
r l[0]
Definition: byte_order.h:168
const GLdouble * v
Definition: gl.h:2040
const GLubyte * c
Definition: glext.h:8905
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define c
Definition: ke_i.h:80
#define sprintf
Definition: sprintf.c:45
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PVOID pBuffer
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by PerformInternalLookup(), PerformLookup(), and PrintDebug().

◆ ExtractName()

int ExtractName ( PCHAR  pBuffer,
PCHAR  pOutput,
USHORT  Offset,
UCHAR  Limit 
)

Definition at line 349 of file utility.c.

350{
351 int c = 0, d = 0, i = 0, j = 0, k = 0, l = 0, m = 0;
352
353 i = Offset;
354
355 /* If Limit == 0, then we assume "no" limit. */
356 d = Limit;
357 if( 0 == Limit ) d = 255;
358
359 while( d > 0 )
360 {
361 l = pBuffer[i] & 0xFF;
362 i += 1;
363 if( !m ) c += 1;
364
365 if( 0xC0 == l )
366 {
367 if( !m ) c += 1;
368 m = 1;
369 d += (255 - Limit);
370 i = pBuffer[i];
371 }
372 else
373 {
374 for( j = 0; j < l; j += 1 )
375 {
376 pOutput[k] = pBuffer[i];
377
378 i += 1;
379 if( !m ) c += 1;
380 k += 1;
381 d -= 1;
382 }
383
384 d -= 1;
385
386 if( !pBuffer[i] || (d < 1) ) break;
387
388 pOutput[k] = '.';
389 k += 1;
390 }
391 };
392
393 if( !m )
394 {
395 if( !Limit ) c += 1;
396 }
397
398 pOutput[k] = '\0';
399
400 return c;
401}
const GLfloat * m
Definition: glext.h:10848
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define d
Definition: ke_i.h:81
int k
Definition: mpi.c:3369
_In_ LONG _In_ LONG Limit
Definition: kefuncs.h:304

Referenced by PerformInternalLookup(), PerformLookup(), PrintD2(), and PrintDebug().

◆ IsValidIP()

BOOL IsValidIP ( PCHAR  pInput)

Definition at line 312 of file utility.c.

313{
314 int i = 0, l = 0, b = 0, c = 1;
315
316 /* Max length of an IP, e.g. 255.255.255.255, is 15 characters. */
317 l = strlen( pInput );
318 if( l > 15 ) return FALSE;
319
320 /* 'b' is the count of the current segment. It gets reset after seeing a
321 '.'. */
322 for( ; i < l; i += 1 )
323 {
324 if( '.' == pInput[i] )
325 {
326 if( !b ) return FALSE;
327 if( b > 3 ) return FALSE;
328
329 b = 0;
330 c += 1;
331 }
332 else
333 {
334 b += 1;
335
336 if( (pInput[i] < '0') || (pInput[i] > '9') ) return FALSE;
337 }
338 }
339
340 if( b > 3 ) return FALSE;
341
342 /* 'c' is the number of segments seen. If it's less than 4, then it's not
343 a valid IP. */
344 if( c < 4 ) return FALSE;
345
346 return TRUE;
347}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLboolean GLboolean GLboolean b
Definition: glext.h:6204

Referenced by ParseCommandLine(), PerformInternalLookup(), and PerformLookup().

◆ OpcodeIDtoOpcodeName()

PCHAR OpcodeIDtoOpcodeName ( UCHAR  Opcode)

Definition at line 747 of file utility.c.

748{
749 switch( Opcode & 0x0F )
750 {
751 case OPCODE_QUERY:
752 return OpcodeQuery;
753
754 case OPCODE_IQUERY:
755 return OpcodeIQuery;
756
757 case OPCODE_STATUS:
758 return OpcodeStatus;
759
760 default:
761 return OpcodeReserved;
762 }
763}
_In_ PVOID _In_ ULONG Opcode
Definition: hubbusif.h:331
#define OpcodeQuery
Definition: nslookup.h:43
#define OpcodeReserved
Definition: nslookup.h:46
#define OPCODE_STATUS
Definition: nslookup.h:41
#define OpcodeStatus
Definition: nslookup.h:45
#define OpcodeIQuery
Definition: nslookup.h:44
#define OPCODE_QUERY
Definition: nslookup.h:39
#define OPCODE_IQUERY
Definition: nslookup.h:40

Referenced by PrintD2(), and PrintDebug().

◆ PrintD2()

void PrintD2 ( PCHAR  pBuffer,
DWORD  BufferLength 
)

Definition at line 442 of file utility.c.

443{
445 UCHAR Header1, Header2;
446 USHORT NumQuestions, NumAnswers, NumAuthority, NumAdditional;
448 CHAR pName[255];
449 int i = 0, k = 0;
450
451 RequestID = ntohs( ((PUSHORT)&pBuffer[i])[0] );
452 i += 2;
453
454 Header1 = pBuffer[i];
455 i += 1;
456
457 Header2 = pBuffer[i];
458 i += 1;
459
460 NumQuestions = ntohs( ((PSHORT)&pBuffer[i])[0] );
461 i += 2;
462
463 NumAnswers = ntohs( ((PSHORT)&pBuffer[i])[0] );
464 i += 2;
465
466 NumAuthority = ntohs( ((PUSHORT)&pBuffer[i])[0] );
467 i += 2;
468
469 NumAdditional = ntohs( ((PUSHORT)&pBuffer[i])[0] );
470 i += 2;
471
472 _tprintf( _T("------------\n") );
473 _tprintf( _T("SendRequest(), len %d\n"), (int)BufferLength );
474 _tprintf( _T(" HEADER:\n") );
475 _tprintf( _T(" opcode = %s, id = %d, rcode = %s\n"),
476 OpcodeIDtoOpcodeName( (Header1 & 0x78) >> 3 ),
477 (int)RequestID,
478 RCodeIDtoRCodeName( Header2 & 0x0F ) );
479
480 _tprintf( _T(" header flags: query") );
481 if( Header1 & 0x01 ) _tprintf( _T(", want recursion") );
482 _tprintf( _T("\n") );
483
484 _tprintf( _T(" questions = %d, answers = %d,"
485 " authority records = %d, additional = %d\n\n"),
486 (int)NumQuestions,
487 (int)NumAnswers,
488 (int)NumAuthority,
489 (int)NumAdditional );
490
491 if( NumQuestions )
492 {
493 _tprintf( _T(" QUESTIONS:\n") );
494
495 for( k = 0; k < NumQuestions; k += 1 )
496 {
497 i += ExtractName( pBuffer, pName, i, 0 );
498
499 _tprintf( _T(" %s"), pName );
500
501 Type = ntohs( ((PUSHORT)&pBuffer[i])[0] );
502 i += 2;
503
504 Class = ntohs( ((PUSHORT)&pBuffer[i])[0] );
505 i += 2;
506
507 _tprintf( _T(", type = %s, class = %s\n"),
510 }
511 }
512
513 _tprintf( _T("\n------------\n") );
514}
Type
Definition: Type.h:7
PCHAR TypeIDtoTypeName(USHORT TypeID)
Definition: utility.c:792
PCHAR RCodeIDtoRCodeName(UCHAR RCode)
Definition: utility.c:765
PCHAR OpcodeIDtoOpcodeName(UCHAR Opcode)
Definition: utility.c:747
int ExtractName(PCHAR pBuffer, PCHAR pOutput, USHORT Offset, UCHAR Limit)
Definition: utility.c:349
PCHAR ClassIDtoClassName(USHORT ClassID)
Definition: utility.c:839
#define _tprintf
Definition: tchar.h:506
#define ntohs(x)
Definition: module.h:210
static LPSTR pName
Definition: security.c:116
ULONG RequestID
Definition: nslookup.c:16
unsigned short USHORT
Definition: pedump.c:61
int16_t * PSHORT
Definition: typedefs.h:55
uint16_t * PUSHORT
Definition: typedefs.h:56
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3777
char CHAR
Definition: xmlstorage.h:175

Referenced by SendRequest().

◆ PrintDebug()

void PrintDebug ( PCHAR  pBuffer,
DWORD  BufferLength 
)

Definition at line 516 of file utility.c.

517{
518 USHORT ResponseID;
519 UCHAR Header1, Header2;
520 USHORT NumQuestions, NumAnswers, NumAuthority, NumAdditional;
522 ULONG TTL;
523 CHAR pName[255];
524 int d = 0, i = 0, k = 0;
525
526 ResponseID = ntohs( ((PUSHORT)&pBuffer[i])[0] );
527 i += 2;
528
529 Header1 = pBuffer[i];
530 i += 1;
531
532 Header2 = pBuffer[i];
533 i += 1;
534
535 NumQuestions = ntohs( ((PSHORT)&pBuffer[i])[0] );
536 i += 2;
537
538 NumAnswers = ntohs( ((PSHORT)&pBuffer[i])[0] );
539 i += 2;
540
541 NumAuthority = ntohs( ((PUSHORT)&pBuffer[i])[0] );
542 i += 2;
543
544 NumAdditional = ntohs( ((PUSHORT)&pBuffer[i])[0] );
545 i += 2;
546
547 _tprintf( _T("------------\n") );
548 _tprintf( _T("Got answer (%d bytes):\n"), (int)BufferLength );
549 _tprintf( _T(" HEADER:\n") );
550 _tprintf( _T(" opcode = %s, id = %d, rcode = %s\n"),
551 OpcodeIDtoOpcodeName( (Header1 & 0x78) >> 3 ),
552 (int)ResponseID,
553 RCodeIDtoRCodeName( Header2 & 0x0F ) );
554
555 _tprintf( _T(" header flags: response") );
556 if( Header1 & 0x01 ) _tprintf( _T(", want recursion") );
557 if( Header2 & 0x80 ) _tprintf( _T(", recursion avail.") );
558 _tprintf( _T("\n") );
559
560 _tprintf( _T(" questions = %d, answers = %d, "
561 "authority records = %d, additional = %d\n\n"),
562 (int)NumQuestions,
563 (int)NumAnswers,
564 (int)NumAuthority,
565 (int)NumAdditional );
566
567 if( NumQuestions )
568 {
569 _tprintf( _T(" QUESTIONS:\n") );
570
571 for( k = 0; k < NumQuestions; k += 1 )
572 {
573 i += ExtractName( pBuffer, pName, i, 0 );
574
575 _tprintf( _T(" %s"), pName );
576
577 Type = ntohs( ((PUSHORT)&pBuffer[i])[0] );
578 i += 2;
579
580 Class = ntohs( ((PUSHORT)&pBuffer[i])[0] );
581 i += 2;
582
583 _tprintf( _T(", type = %s, class = %s\n"),
586 }
587 }
588
589 if( NumAnswers )
590 {
591 _tprintf( _T(" ANSWERS:\n") );
592
593 for( k = 0; k < NumAnswers; k += 1 )
594 {
595 _tprintf( _T(" -> ") );
596
597 /* Print out the name. */
598 i += ExtractName( pBuffer, pName, i, 0 );
599
600 _tprintf( _T("%s\n"), pName );
601
602 /* Print out the type, class and data length. */
603 Type = ntohs( ((PUSHORT)&pBuffer[i])[0] );
604 i += 2;
605
606 Class = ntohs( ((PUSHORT)&pBuffer[i])[0] );
607 i += 2;
608
609 TTL = ntohl( ((PULONG)&pBuffer[i])[0] );
610 i += 4;
611
612 d = ntohs( ((PUSHORT)&pBuffer[i])[0] );
613 i += 2;
614
615 _tprintf( _T(" type = %s, class = %s, dlen = %d\n"),
618 d );
619
620 /* Print out the answer. */
621 if( TYPE_A == Type )
622 {
623 i += ExtractIP( pBuffer, pName, i );
624
625 _tprintf( _T(" internet address = %s\n"), pName );
626 }
627 else
628 {
629 i += ExtractName( pBuffer, pName, i, d );
630
631 _tprintf( _T(" name = %s\n"), pName );
632 }
633
634 _tprintf( _T(" ttl = %d ()\n"), (int)TTL );
635 }
636 }
637
638 if( NumAuthority )
639 {
640 _tprintf( _T(" AUTHORITY RECORDS:\n") );
641
642 for( k = 0; k < NumAuthority; k += 1 )
643 {
644 /* Print out the zone name. */
645 i += ExtractName( pBuffer, pName, i, 0 );
646
647 _tprintf( _T(" -> %s\n"), pName );
648
649 /* Print out the type, class, data length and TTL. */
650 Type = ntohs( ((PUSHORT)&pBuffer[i])[0] );
651 i += 2;
652
653 Class = ntohs( ((PUSHORT)&pBuffer[i])[0] );
654 i += 2;
655
656 TTL = ntohl( ((PULONG)&pBuffer[i])[0] );
657 i += 4;
658
659 d = ntohs( ((PUSHORT)&pBuffer[i])[0] );
660 i += 2;
661
662 _tprintf( _T(" type = %s, class = %s, dlen = %d\n"),
665 d );
666
667 /* TODO: There might be more types? */
668 if( TYPE_NS == Type )
669 {
670 /* Print out the NS. */
671 i += ExtractName( pBuffer, pName, i, d );
672
673 _tprintf( _T(" nameserver = %s\n"), pName );
674
675 _tprintf( _T(" ttl = %d ()\n"), (int)TTL );
676 }
677 else if( TYPE_SOA == Type )
678 {
679 _tprintf( _T(" ttl = %d ()\n"), (int)TTL );
680
681 /* Print out the primary NS. */
682 i += ExtractName( pBuffer, pName, i, 0 );
683
684 _tprintf( _T(" primary name server = %s\n"), pName );
685
686 /* Print out the responsible mailbox. */
687 i += ExtractName( pBuffer, pName, i, 0 );
688
689 _tprintf( _T(" responsible mail addr = %s\n"), pName );
690
691 /* Print out the serial, refresh, retry, expire and default TTL. */
692 _tprintf( _T(" serial = ()\n") );
693 _tprintf( _T(" refresh = ()\n") );
694 _tprintf( _T(" retry = ()\n") );
695 _tprintf( _T(" expire = ()\n") );
696 _tprintf( _T(" default TTL = ()\n") );
697 i += 20;
698 }
699 }
700 }
701
702 if( NumAdditional )
703 {
704 _tprintf( _T(" ADDITIONAL:\n") );
705
706 for( k = 0; k < NumAdditional; k += 1 )
707 {
708 /* Print the name. */
709 i += ExtractName( pBuffer, pName, i, 0 );
710
711 _tprintf( _T(" -> %s\n"), pName );
712
713 /* Print out the type, class, data length and TTL. */
714 Type = ntohs( ((PUSHORT)&pBuffer[i])[0] );
715 i += 2;
716
717 Class = ntohs( ((PUSHORT)&pBuffer[i])[0] );
718 i += 2;
719
720 TTL = ntohl( ((PULONG)&pBuffer[i])[0] );
721 i += 4;
722
723 d = ntohs( ((PUSHORT)&pBuffer[i])[0] );
724 i += 2;
725
726 _tprintf( _T(" type = %s, class = %s, dlen = %d\n"),
729 d );
730
731 /* TODO: There might be more types? */
732 if( TYPE_A == Type )
733 {
734 /* Print out the NS. */
735 i += ExtractIP( pBuffer, pName, i );
736
737 _tprintf( _T(" internet address = %s\n"), pName );
738
739 _tprintf( _T(" ttl = %d ()\n"), (int)TTL );
740 }
741 }
742 }
743
744 _tprintf( _T("\n------------\n") );
745}
int ExtractIP(PCHAR pBuffer, PCHAR pOutput, USHORT Offset)
Definition: utility.c:403
#define TYPE_A
Definition: ftp_var.h:36
#define ntohl(x)
Definition: module.h:205
#define TYPE_SOA
Definition: nslookup.h:27
#define TYPE_NS
Definition: nslookup.h:25
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59

Referenced by SendRequest().

◆ RCodeIDtoRCodeName()

PCHAR RCodeIDtoRCodeName ( UCHAR  RCode)

Definition at line 765 of file utility.c.

766{
767 switch( RCode & 0x0F )
768 {
769 case RCODE_NOERROR:
770 return RCodeNOERROR;
771
772 case RCODE_FORMERR:
773 return RCodeFORMERR;
774
775 case RCODE_FAILURE:
776 return RCodeFAILURE;
777
778 case RCODE_NXDOMAIN:
779 return RCodeNXDOMAIN;
780
781 case RCODE_NOTIMP:
782 return RCodeNOTIMP;
783
784 case RCODE_REFUSED:
785 return RCodeREFUSED;
786
787 default:
788 return RCodeReserved;
789 }
790}
#define RCODE_NOTIMP
Definition: nslookup.h:52
#define RCodeNOTIMP
Definition: nslookup.h:59
#define RCODE_FAILURE
Definition: nslookup.h:50
#define RCODE_FORMERR
Definition: nslookup.h:49
#define RCodeReserved
Definition: nslookup.h:61
#define RCodeNOERROR
Definition: nslookup.h:55
#define RCODE_NOERROR
Definition: nslookup.h:48
#define RCodeREFUSED
Definition: nslookup.h:60
#define RCODE_REFUSED
Definition: nslookup.h:53
#define RCodeFORMERR
Definition: nslookup.h:56
#define RCodeNXDOMAIN
Definition: nslookup.h:58
#define RCodeFAILURE
Definition: nslookup.h:57
#define RCODE_NXDOMAIN
Definition: nslookup.h:51

Referenced by PrintD2(), and PrintDebug().

◆ ReverseIP()

void ReverseIP ( PCHAR  pIP,
PCHAR  pReturn 
)

Definition at line 250 of file utility.c.

251{
252 int i;
253 int j;
254 int k = 0;
255
256 assert(pReturn != pIP);
257
258 j = strlen( pIP ) - 1;
259 i = j;
260
261 /* We have A.B.C.D
262 We will turn this into D.C.B.A and stick it in pReturn */
263
264 /* A */
265 for( ; i > 0; i -= 1 ) if( '.' == pIP[i] ) break;
266
267 if (j != i)
268 strncpy( &pReturn[k], &pIP[i + 1], (j - i) );
269 k += (j - i);
270
271 pReturn[k] = '.';
272 k += 1;
273
274 i -= 1;
275 j = i;
276
277 /* B */
278 for( ; i > 0; i -= 1 ) if( '.' == pIP[i] ) break;
279
280 if (j != i)
281 strncpy( &pReturn[k], &pIP[i + 1], (j - i) );
282 k += (j - i);
283
284 pReturn[k] = '.';
285 k += 1;
286
287 i -= 1;
288 j = i;
289
290 /* C */
291 for( ; i > 0; i -= 1 ) if( '.' == pIP[i] ) break;
292
293 if (j != i)
294 strncpy( &pReturn[k], &pIP[i + 1], (j - i) );
295 k += (j - i);
296
297 pReturn[k] = '.';
298 k += 1;
299
300 i -= 1;
301 j = i;
302
303 /* D */
304 for( ; i > 0; i -= 1 );
305
306 strncpy( &pReturn[k], &pIP[i], (j - i) + 1 );
307 k += (j - i) + 1;
308
309 pReturn[k] = '\0';
310}
#define assert(_expr)
Definition: assert.h:32
strncpy
Definition: string.h:335

Referenced by PerformInternalLookup(), and PerformLookup().

◆ SendRequest()

BOOL SendRequest ( PCHAR  pInBuffer,
ULONG  InBufferLength,
PCHAR  pOutBuffer,
PULONG  pOutBufferLength 
)

Definition at line 12 of file utility.c.

16{
17 int j;
18 USHORT RequestID, ResponseID;
19 BOOL bWait;
20 SOCKET s;
21 SOCKADDR_IN RecAddr, RecAddr2, SendAddr;
22 int SendAddrLen = sizeof(SendAddr);
23
24 RtlZeroMemory( &RecAddr, sizeof(SOCKADDR_IN) );
25 RtlZeroMemory( &RecAddr2, sizeof(SOCKADDR_IN) );
26 RtlZeroMemory( &SendAddr, sizeof(SOCKADDR_IN) );
27
28 /* Pull the request ID from the buffer. */
29 RequestID = ntohs( ((PSHORT)&pInBuffer[0])[0] );
30
31 /* If D2 flags is enabled, then display D2 information. */
32 if( State.d2 ) PrintD2( pInBuffer, InBufferLength );
33
34 /* Create the sockets for both send and receive. */
36
37 if (s == INVALID_SOCKET)
38 return FALSE;
39
40 /* Set up the structure to tell it where we are going. */
41 RecAddr.sin_family = AF_INET;
42 RecAddr.sin_port = htons( State.port );
43 RecAddr.sin_addr.s_addr = inet_addr( State.DefaultServerAddress );
44
45 /* Set up the structure to tell it what port to listen on. */
46 RecAddr2.sin_family = AF_INET;
47 RecAddr2.sin_port = htons( State.port );
48 RecAddr2.sin_addr.s_addr = htonl( INADDR_ANY );
49
50 /* Bind the receive socket. */
51 bind( s, (SOCKADDR*)&RecAddr2, sizeof(RecAddr2) );
52
53 /* Send the datagram to the DNS server. */
54 j = sendto( s,
55 pInBuffer,
56 InBufferLength,
57 0,
58 (SOCKADDR*)&RecAddr,
59 sizeof(RecAddr) );
60 if( j == SOCKET_ERROR )
61 {
62 switch( WSAGetLastError() )
63 {
65 _tprintf( _T("sendto() failed with WSANOTINITIALIZED\n") );
66 break;
67 case WSAENETDOWN:
68 _tprintf( _T("sendto() failed with WSAENETDOWN\n") );
69 break;
70 case WSAEACCES:
71 _tprintf( _T("sendto() failed with WSAEACCES\n") );
72 break;
73 case WSAEINVAL:
74 _tprintf( _T("sendto() failed with WSAEINVAL\n") );
75 break;
76 case WSAEINTR:
77 _tprintf( _T("sendto() failed with WSAEINTR\n") );
78 break;
79 case WSAEINPROGRESS:
80 _tprintf( _T("sendto() failed with WSAEINPROGRESS\n") );
81 break;
82 case WSAEFAULT:
83 _tprintf( _T("sendto() failed with WSAEFAULT\n") );
84 break;
85 case WSAENETRESET:
86 _tprintf( _T("sendto() failed with WSAENETRESET\n") );
87 break;
88 case WSAENOBUFS:
89 _tprintf( _T("sendto() failed with WSAENOBUFS\n") );
90 break;
91 case WSAENOTCONN:
92 _tprintf( _T("sendto() failed with WSAENOTCONN\n") );
93 break;
94 case WSAENOTSOCK:
95 _tprintf( _T("sendto() failed with WSAENOTSOCK\n") );
96 break;
97 case WSAEOPNOTSUPP:
98 _tprintf( _T("sendto() failed with WSAEOPNOTSUPP\n") );
99 break;
100 case WSAESHUTDOWN:
101 _tprintf( _T("sendto() failed with WSAESHUTDOWN\n") );
102 break;
103 case WSAEWOULDBLOCK:
104 _tprintf( _T("sendto() failed with WSAEWOULDBLOCK\n") );
105 break;
106 case WSAEMSGSIZE:
107 _tprintf( _T("sendto() failed with WSAEMSGSIZE\n") );
108 break;
109 case WSAEHOSTUNREACH:
110 _tprintf( _T("sendto() failed with WSAEHOSTUNREACH\n") );
111 break;
112 case WSAECONNABORTED:
113 _tprintf( _T("sendto() failed with WSAECONNABORTED\n") );
114 break;
115 case WSAECONNRESET:
116 _tprintf( _T("sendto() failed with WSAECONNRESET\n") );
117 break;
118 case WSAEADDRNOTAVAIL:
119 _tprintf( _T("sendto() failed with WSAEADDRNOTAVAIL\n") );
120 break;
121 case WSAEAFNOSUPPORT:
122 _tprintf( _T("sendto() failed with WSAEAFNOSUPPORT\n") );
123 break;
124 case WSAEDESTADDRREQ:
125 _tprintf( _T("sendto() failed with WSAEDESTADDRREQ\n") );
126 break;
127 case WSAENETUNREACH:
128 _tprintf( _T("sendto() failed with WSAENETUNREACH\n") );
129 break;
130 case WSAETIMEDOUT:
131 _tprintf( _T("sendto() failed with WSAETIMEDOUT\n") );
132 break;
133 default:
134 _tprintf( _T("sendto() failed with unknown error\n") );
135 }
136
137 closesocket( s );
138 return FALSE;
139 }
140
141 bWait = TRUE;
142
143 while( bWait )
144 {
145 /* Wait for the DNS reply. */
146 j = recvfrom( s,
147 pOutBuffer,
148 *pOutBufferLength,
149 0,
150 (SOCKADDR*)&SendAddr,
151 &SendAddrLen );
152 if( j == SOCKET_ERROR )
153 {
154 switch( WSAGetLastError() )
155 {
157 _tprintf( _T("recvfrom() failed with WSANOTINITIALIZED\n") );
158 break;
159 case WSAENETDOWN:
160 _tprintf( _T("recvfrom() failed with WSAENETDOWN\n") );
161 break;
162 case WSAEACCES:
163 _tprintf( _T("recvfrom() failed with WSAEACCES\n") );
164 break;
165 case WSAEINVAL:
166 _tprintf( _T("recvfrom() failed with WSAEINVAL\n") );
167 break;
168 case WSAEINTR:
169 _tprintf( _T("recvfrom() failed with WSAEINTR\n") );
170 break;
171 case WSAEINPROGRESS:
172 _tprintf( _T("recvfrom() failed with WSAEINPROGRESS\n") );
173 break;
174 case WSAEFAULT:
175 _tprintf( _T("recvfrom() failed with WSAEFAULT\n") );
176 break;
177 case WSAENETRESET:
178 _tprintf( _T("recvfrom() failed with WSAENETRESET\n") );
179 break;
180 case WSAENOBUFS:
181 _tprintf( _T("recvfrom() failed with WSAENOBUFS\n") );
182 break;
183 case WSAENOTCONN:
184 _tprintf( _T("recvfrom() failed with WSAENOTCONN\n") );
185 break;
186 case WSAENOTSOCK:
187 _tprintf( _T("recvfrom() failed with WSAENOTSOCK\n") );
188 break;
189 case WSAEOPNOTSUPP:
190 _tprintf( _T("recvfrom() failed with WSAEOPNOTSUPP\n") );
191 break;
192 case WSAESHUTDOWN:
193 _tprintf( _T("recvfrom() failed with WSAESHUTDOWN\n") );
194 break;
195 case WSAEWOULDBLOCK:
196 _tprintf( _T("recvfrom() failed with WSAEWOULDBLOCK\n") );
197 break;
198 case WSAEMSGSIZE:
199 _tprintf( _T("recvfrom() failed with WSAEMSGSIZE\n") );
200 break;
201 case WSAEHOSTUNREACH:
202 _tprintf( _T("recvfrom() failed with WSAEHOSTUNREACH\n") );
203 break;
204 case WSAECONNABORTED:
205 _tprintf( _T("recvfrom() failed with WSAECONNABORTED\n") );
206 break;
207 case WSAECONNRESET:
208 _tprintf( _T("recvfrom() failed with WSAECONNRESET\n") );
209 break;
210 case WSAEADDRNOTAVAIL:
211 _tprintf( _T("recvfrom() failed with WSAEADDRNOTAVAIL\n") );
212 break;
213 case WSAEAFNOSUPPORT:
214 _tprintf( _T("recvfrom() failed with WSAEAFNOSUPPORT\n") );
215 break;
216 case WSAEDESTADDRREQ:
217 _tprintf( _T("recvfrom() failed with WSAEDESTADDRREQ\n") );
218 break;
219 case WSAENETUNREACH:
220 _tprintf( _T("recvfrom() failed with WSAENETUNREACH\n") );
221 break;
222 case WSAETIMEDOUT:
223 _tprintf( _T("recvfrom() failed with WSAETIMEDOUT\n") );
224 break;
225 default:
226 _tprintf( _T("recvfrom() failed with unknown error\n") );
227 }
228
229 closesocket( s );
230 return FALSE;
231 }
232
233 ResponseID = ntohs( ((PSHORT)&pOutBuffer[0])[0] );
234
235 if( ResponseID == RequestID ) bWait = FALSE;
236 }
237
238 /* We don't need the sockets anymore. */
239 closesocket( s );
240
241 /* If debug information then display debug information. */
242 if( State.debug ) PrintDebug( pOutBuffer, j );
243
244 /* Return the real output buffer length. */
245 *pOutBufferLength = j;
246
247 return TRUE;
248}
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
Definition: addrconv.c:71
void PrintDebug(PCHAR pBuffer, DWORD BufferLength)
Definition: utility.c:516
void PrintD2(PCHAR pBuffer, DWORD BufferLength)
Definition: utility.c:442
INT WSAAPI recvfrom(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags, OUT LPSOCKADDR from, IN OUT INT FAR *fromlen)
Definition: recv.c:87
INT WSAAPI sendto(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags, IN CONST struct sockaddr *to, IN INT tolen)
Definition: send.c:82
#define IPPROTO_UDP
Definition: ip.h:198
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLdouble s
Definition: gl.h:2039
#define INADDR_ANY
Definition: inet.h:80
#define htons(x)
Definition: module.h:215
#define htonl(x)
Definition: module.h:214
#define closesocket
Definition: ncftp.h:477
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
struct in_addr sin_addr
Definition: winsock.h:506
short sin_family
Definition: winsock.h:504
u_short sin_port
Definition: winsock.h:505
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define WSAEADDRNOTAVAIL
Definition: winerror.h:2865
#define WSAEOPNOTSUPP
Definition: winerror.h:2861
#define WSAEHOSTUNREACH
Definition: winerror.h:2881
#define WSANOTINITIALISED
Definition: winerror.h:2894
#define WSAEWOULDBLOCK
Definition: winerror.h:2851
#define WSAEINVAL
Definition: winerror.h:2845
#define WSAENOTSOCK
Definition: winerror.h:2854
#define WSAECONNABORTED
Definition: winerror.h:2869
#define WSAENETDOWN
Definition: winerror.h:2866
#define WSAENOBUFS
Definition: winerror.h:2871
#define WSAETIMEDOUT
Definition: winerror.h:2876
#define WSAEMSGSIZE
Definition: winerror.h:2856
#define WSAECONNRESET
Definition: winerror.h:2870
#define WSAEACCES
Definition: winerror.h:2843
#define WSAEDESTADDRREQ
Definition: winerror.h:2855
#define WSAESHUTDOWN
Definition: winerror.h:2874
#define WSAENETUNREACH
Definition: winerror.h:2867
#define WSAEAFNOSUPPORT
Definition: winerror.h:2863
#define WSAENOTCONN
Definition: winerror.h:2873
#define WSAEINPROGRESS
Definition: winerror.h:2852
#define WSAENETRESET
Definition: winerror.h:2868
#define WSAEFAULT
Definition: winerror.h:2844
#define WSAEINTR
Definition: winerror.h:2841
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:131
#define INVALID_SOCKET
Definition: winsock.h:326
#define SOCK_DGRAM
Definition: winsock.h:330
UINT_PTR SOCKET
Definition: winsock.h:41
#define SOCKET_ERROR
Definition: winsock.h:327

Referenced by AddrFileFree(), PerformInternalLookup(), and PerformLookup().

◆ TypeIDtoTypeName()

PCHAR TypeIDtoTypeName ( USHORT  TypeID)

Definition at line 792 of file utility.c.

793{
794 switch( TypeID )
795 {
796 case TYPE_A:
797 return TypeA;
798
799 case TYPE_NS:
800 return TypeNS;
801
802 case TYPE_CNAME:
803 return TypeCNAME;
804
805 case TYPE_SOA:
806 return TypeSOA;
807
808 case TYPE_WKS:
809 return TypeSRV;
810
811 case TYPE_PTR:
812 return TypePTR;
813
814 case TYPE_MX:
815 return TypeMX;
816
817 case TYPE_ANY:
818 return TypeAny;
819
820 default:
821 return "Unknown";
822 }
823}
#define TYPE_PTR
Definition: nslookup.h:29
#define TypeMX
Definition: nslookup.h:18
#define TYPE_WKS
Definition: nslookup.h:28
#define TypePTR
Definition: nslookup.h:20
#define TypeSRV
Definition: nslookup.h:22
#define TypeNS
Definition: nslookup.h:19
#define TypeAny
Definition: nslookup.h:16
#define TYPE_CNAME
Definition: nslookup.h:26
#define TYPE_ANY
Definition: nslookup.h:31
#define TypeCNAME
Definition: nslookup.h:17
#define TypeA
Definition: nslookup.h:13
#define TYPE_MX
Definition: nslookup.h:30
#define TypeSOA
Definition: nslookup.h:21

Referenced by PrintD2(), and PrintDebug().

◆ TypeNametoTypeID()

USHORT TypeNametoTypeID ( PCHAR  TypeName)

Definition at line 825 of file utility.c.

826{
827 if( !strncmp( TypeName, TypeA, strlen( TypeA ) ) ) return TYPE_A;
828 if( !strncmp( TypeName, TypeNS, strlen( TypeNS ) ) ) return TYPE_NS;
829 if( !strncmp( TypeName, TypeCNAME, strlen( TypeCNAME ) ) ) return TYPE_CNAME;
830 if( !strncmp( TypeName, TypeSOA, strlen( TypeSOA ) ) ) return TYPE_SOA;
831 if( !strncmp( TypeName, TypeSRV, strlen( TypeSRV ) ) ) return TYPE_WKS;
832 if( !strncmp( TypeName, TypePTR, strlen( TypePTR ) ) ) return TYPE_PTR;
833 if( !strncmp( TypeName, TypeMX, strlen( TypeMX ) ) ) return TYPE_MX;
834 if( !strncmp( TypeName, TypeAny, strlen( TypeAny ) ) ) return TYPE_ANY;
835
836 return 0;
837}

Referenced by PerformLookup().