Rev 1155 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1155 | Rev 1197 | ||
---|---|---|---|
Line 673... | Line 673... | ||
673 | ; query class = IN (internet IPv4 address) = 1 |
673 | ; query class = IN (internet IPv4 address) = 1 |
674 | ; Note that network byte order is big-endian. |
674 | ; Note that network byte order is big-endian. |
675 | mov eax, 0x01000100 |
675 | mov eax, 0x01000100 |
676 | stosd |
676 | stosd |
677 | ; 7. Get DNS server address. |
677 | ; 7. Get DNS server address. |
- | 678 | ; Get number of running cards. |
|
678 | mcall 52, 13 |
679 | mcall 73, -1 |
- | 680 | xchg eax, edx |
|
- | 681 | ; Loop for all initialized network cards, scanning for initialized DNS address. |
|
- | 682 | mov ebx, 0x00000004 ; protocol IP=0, device number=0, function=get DNS address |
|
- | 683 | .get_dns_loop: |
|
- | 684 | mcall 75 |
|
- | 685 | cmp eax, -1 |
|
- | 686 | jz .get_dns_next |
|
- | 687 | test ecx, ecx |
|
- | 688 | jnz .got_dns |
|
- | 689 | dec edx |
|
- | 690 | jz .get_dns_done |
|
- | 691 | .get_dns_next: |
|
- | 692 | inc bh |
|
- | 693 | jnz .get_dns_loop |
|
- | 694 | ; all possible devices were checked, none found - return error |
|
- | 695 | .get_dns_done: |
|
- | 696 | jmp .ret.dnserr |
|
- | 697 | .got_dns: |
|
679 | xchg esi, eax ; put server address to esi |
698 | mov esi, ecx ; put server address to esi |
680 | ; 8. Open UDP socket to DNS server, port 53. |
699 | ; 8. Open UDP socket to DNS server, port 53. |
- | 700 | ; 8a. Create new socket. |
|
681 | mcall 53, 0, 0, 53 |
701 | mcall 74, 0, AF_INET, IPPROTO_UDP |
682 | cmp eax, -1 ; error? |
702 | cmp eax, -1 ; error? |
683 | jz .ret.dnserr |
703 | jz .ret.dnserr |
684 | xchg ecx, eax ; put socket handle to ecx |
704 | xchg ecx, eax ; put socket handle to ecx |
- | 705 | ; 8b. Create sockaddr structure on the stack. |
|
- | 706 | push 0 |
|
- | 707 | push 0 ; sin_zero |
|
- | 708 | push esi ; sin_addr |
|
- | 709 | push AF_INET + (53 shl 24) |
|
- | 710 | ; sin_family and sin_port in network byte order |
|
- | 711 | ; 8c. Call the system. |
|
- | 712 | mcall 74, 4, , esp, sizeof.sockaddr_in |
|
- | 713 | ; 8d. Restore the stack, undo 8b. |
|
- | 714 | add esp, esi |
|
- | 715 | ; 8e. Check result. |
|
- | 716 | cmp eax, -1 |
|
- | 717 | jz .ret.close |
|
685 | ; 9. Send DNS request packet. |
718 | ; 9. Send DNS request packet. |
686 | sub edi, esp ; get packet length |
719 | sub edi, esp ; get packet length |
- | 720 | mov esi, edi |
|
- | 721 | xor edi, edi |
|
687 | mcall 53, 4, , edi, esp |
722 | mcall 74, 6, , esp |
688 | cmp eax, -1 |
723 | cmp eax, -1 |
689 | jz .ret.close |
724 | jz .ret.close |
690 | mov eax, [.reqdata] |
725 | mov eax, [.reqdata] |
691 | mov [eax+__gai_reqdata.socket], ecx |
726 | mov [eax+__gai_reqdata.socket], ecx |
692 | push -1 |
727 | push -1 |
693 | pop eax ; return status: more processing required |
728 | pop eax ; return status: more processing required |
694 | jmp .ret.dns |
729 | jmp .ret.dns |
695 | .ret.close: |
730 | .ret.close: |
696 | mcall 53, 1 |
731 | mcall 74, 1 |
697 | .ret.dnserr: |
732 | .ret.dnserr: |
698 | push EAI_AGAIN |
733 | push EAI_AGAIN |
699 | pop eax |
734 | pop eax |
700 | .ret.dns: |
735 | .ret.dns: |
701 | ; 6. Restore stack pointer and return. |
736 | ; 6. Restore stack pointer and return. |
Line 740... | Line 775... | ||
740 | ; 1. Save used registers for __stdcall. |
775 | ; 1. Save used registers for __stdcall. |
741 | push ebx esi edi |
776 | push ebx esi edi |
742 | mov edi, [.reqdata] |
777 | mov edi, [.reqdata] |
743 | ; 2. Read UDP datagram. |
778 | ; 2. Read UDP datagram. |
744 | mov ecx, [edi+__gai_reqdata.socket] |
779 | mov ecx, [edi+__gai_reqdata.socket] |
- | 780 | push edi |
|
745 | mcall 53, 11, , , 512 |
781 | mcall 74, 6, , , 512, 0 |
- | 782 | pop edi |
|
746 | ; 3. Ignore events for other sockets (return if no data read) |
783 | ; 3. Ignore events for other sockets (return if no data read) |
747 | test eax, eax |
784 | test eax, eax |
748 | jz .ret.more_processing_required |
785 | jz .ret.more_processing_required |
749 | ; 4. Sanity check: discard too short packets. |
786 | ; 4. Sanity check: discard too short packets. |
750 | xchg ecx, eax ; save packet length in ecx |
787 | xchg ecx, eax ; save packet length in ecx |
Line 900... | Line 937... | ||
900 | .ret.close: |
937 | .ret.close: |
901 | ; 15. Close socket. |
938 | ; 15. Close socket. |
902 | push eax |
939 | push eax |
903 | mov ecx, [.reqdata] |
940 | mov ecx, [.reqdata] |
904 | mov ecx, [ecx+__gai_reqdata.socket] |
941 | mov ecx, [ecx+__gai_reqdata.socket] |
905 | mcall 53, 1 |
942 | mcall 74, 1 |
906 | pop eax |
943 | pop eax |
907 | ; 16. Restore used registers, destroy stack frame and return. |
944 | ; 16. Restore used registers, destroy stack frame and return. |
908 | .ret: |
945 | .ret: |
909 | pop edi esi ebx |
946 | pop edi esi ebx |
910 | mov esp, ebp |
947 | mov esp, ebp |
Line 1153... | Line 1190... | ||
1153 | mov byte [edi+addrinfo.ai_family], PF_INET |
1190 | mov byte [edi+addrinfo.ai_family], PF_INET |
1154 | mov byte [edi+addrinfo.ai_addrlen], sizeof.sockaddr_in |
1191 | mov byte [edi+addrinfo.ai_addrlen], sizeof.sockaddr_in |
1155 | lea ecx, [edi+sizeof.addrinfo] |
1192 | lea ecx, [edi+sizeof.addrinfo] |
1156 | mov [edi+addrinfo.ai_addr], ecx |
1193 | mov [edi+addrinfo.ai_addr], ecx |
1157 | ; 5. Fill struct sockaddr_in. |
1194 | ; 5. Fill struct sockaddr_in. |
1158 | mov byte [ecx+sockaddr_in.sin_len], sizeof.sockaddr_in |
- | |
1159 | mov byte [ecx+sockaddr_in.sin_family], PF_INET |
1195 | mov byte [ecx+sockaddr_in.sin_family], PF_INET |
1160 | pop eax |
1196 | pop eax |
1161 | mov [ecx+sockaddr_in.sin_addr], eax |
1197 | mov [ecx+sockaddr_in.sin_addr], eax |
1162 | ; 6. Append new item to the list. |
1198 | ; 6. Append new item to the list. |
1163 | mov [esi], edi |
1199 | mov [esi], edi |
Line 1201... | Line 1237... | ||
1201 | ; 0. Save used registers for __stdcall. |
1237 | ; 0. Save used registers for __stdcall. |
1202 | push ebx |
1238 | push ebx |
1203 | ; 1. Allocated resources: only socket, so close it and return. |
1239 | ; 1. Allocated resources: only socket, so close it and return. |
1204 | mov eax, [esp+8] |
1240 | mov eax, [esp+8] |
1205 | mov ecx, [eax+__gai_reqdata.socket] |
1241 | mov ecx, [eax+__gai_reqdata.socket] |
1206 | mcall 53, 1 |
1242 | mcall 74, 1 |
1207 | ; 2. Restore used registers and return. |
1243 | ; 2. Restore used registers and return. |
1208 | pop ebx |
1244 | pop ebx |
1209 | ret 4 |
1245 | ret 4 |
Line 1210... | Line 1246... | ||
1210 | 1246 |