141 return MapError(err, *aErrno); |
141 return MapError(err, *aErrno); |
142 } |
142 } |
143 } |
143 } |
144 |
144 |
145 RHostResolver hr; |
145 RHostResolver hr; |
146 /* Get the default RConnection instance and use it if configured. |
146 /* Get the default RConnection instance and use it */ |
147 NOTE: This RConnection, if configured, would be created using the |
|
148 socket server on backend. The same server has to be used here */ |
|
149 RConnection& defConnection = Backend()->GetDefaultConnection(); |
147 RConnection& defConnection = Backend()->GetDefaultConnection(); |
150 if(defConnection.SubSessionHandle() != 0) |
148 if(defConnection.SubSessionHandle() != 0) |
151 { |
149 { |
152 err = hr.Open(ss, AF_INET, IPPROTO_UDP,defConnection); |
150 err = hr.Open(ss, AF_INET, IPPROTO_UDP,defConnection); |
153 } |
151 } |
154 else |
152 else |
155 { |
153 { |
156 err = hr.Open(ss, AF_INET, IPPROTO_UDP); |
154 err = ECONNABORTED; |
157 } |
155 } |
158 |
156 |
159 if (err == KErrNone) |
157 if (err == KErrNone) |
160 { |
158 { |
161 TBuf<128> hostname; |
159 TBuf<128> hostname; |
319 } |
318 } |
320 |
319 |
321 if (err == KErrNone) |
320 if (err == KErrNone) |
322 { |
321 { |
323 RHostResolver r; |
322 RHostResolver r; |
324 /* Get the default RConnection instance and use it if configured. |
323 /* Get the default RConnection instance and use it */ |
325 NOTE: This RConnection, if configured, would be created using the |
|
326 socket server on backend. The same server has to be used here */ |
|
327 RConnection& defConnection = Backend()->GetDefaultConnection(); |
324 RConnection& defConnection = Backend()->GetDefaultConnection(); |
328 if(defConnection.SubSessionHandle() != 0) |
325 if(defConnection.SubSessionHandle() != 0) |
329 { |
326 { |
330 err=r.Open(ss, format, IPPROTO_UDP, defConnection); |
327 err=r.Open(ss, format, IPPROTO_UDP, defConnection); |
331 } |
328 } |
332 else |
329 else |
333 { |
330 { |
334 err=r.Open(ss, format, IPPROTO_UDP); |
331 err = -ECONNABORTED; // needs to be negative for logic below to return NO_RECOVERY to caller |
335 } |
332 } |
336 |
333 |
337 if (err == KErrNone) |
334 if (err == KErrNone) |
338 { |
335 { |
339 struct sockaddr buf; |
336 struct sockaddr buf; |
413 return retval; |
415 return retval; |
414 } |
416 } |
415 } |
417 } |
416 |
418 |
417 RHostResolver r; |
419 RHostResolver r; |
418 /* Get the default RConnection instance and use it if configured. |
420 /* Get the default RConnection instance and use it */ |
419 NOTE: This RConnection, if configured, would be created using the |
|
420 socket server on backend. The same server has to be used here */ |
|
421 RConnection& defConnection = Backend()->GetDefaultConnection(); |
421 RConnection& defConnection = Backend()->GetDefaultConnection(); |
422 if (defConnection.SubSessionHandle() != 0) |
422 if (defConnection.SubSessionHandle() != 0) |
423 { |
423 { |
424 err = r.Open(ss, AF_INET, IPPROTO_UDP, defConnection); |
424 err = r.Open(ss, AF_INET, IPPROTO_UDP, defConnection); |
425 } |
425 } |
426 else |
426 else |
427 { |
427 { |
428 err = r.Open(ss, AF_INET, IPPROTO_UDP); |
428 err = -ECONNABORTED; // needs to be negative for logic below to return NO_RECOVERY to caller |
429 } |
429 } |
430 |
430 |
431 if (err == KErrNone) |
431 if (err == KErrNone) |
432 { |
432 { |
433 TNameRecord record; |
433 TNameRecord record; |
632 } |
642 } |
633 } |
643 } |
634 |
644 |
635 //Open the host resolver |
645 //Open the host resolver |
636 RHostResolver resolver; |
646 RHostResolver resolver; |
637 /* Get the default RConnection instance and use it if configured. |
647 /* Get the default RConnection instance and use it */ |
638 NOTE: This RConnection, if configured, would be created using the |
|
639 socket server on backend. The same server has to be used here */ |
|
640 RConnection& defConnection = Backend()->GetDefaultConnection(); |
648 RConnection& defConnection = Backend()->GetDefaultConnection(); |
641 if(defConnection.SubSessionHandle() != 0) |
649 if (defConnection.SubSessionHandle() != 0) |
|
650 { |
642 err = resolver.Open(sockServ, KAfInet, KProtocolInetUdp, defConnection); |
651 err = resolver.Open(sockServ, KAfInet, KProtocolInetUdp, defConnection); |
|
652 } |
643 else |
653 else |
644 err = resolver.Open(sockServ, KAfInet, KProtocolInetUdp); |
654 { |
|
655 err = ECONNABORTED; |
|
656 } |
645 |
657 |
646 if (err != KErrNone) |
658 if (err != KErrNone) |
647 { |
659 { |
648 MapError(err, *aErrno); |
660 MapError(err, *aErrno); |
649 return EAI_SYSTEM; |
661 return EAI_SYSTEM; |
661 } |
673 } |
662 |
674 |
663 //Create a list of addrinfo nodes from the result |
675 //Create a list of addrinfo nodes from the result |
664 *aRes = NULL; |
676 *aRes = NULL; |
665 struct addrinfo** curr = aRes; |
677 struct addrinfo** curr = aRes; |
666 do |
678 do |
667 { |
679 { |
668 nameRec = nameEntry(); |
680 nameRec = nameEntry(); |
669 TInetAddr inetAddr(nameRec.iAddr); |
681 TInetAddr inetAddr(nameRec.iAddr); |
670 //Create the node if the address is valid, and the family matches that of hints |
682 |
671 if(!inetAddr.IsUnspecified()) |
683 |
672 { |
684 //Create the node if the address is valid, and the family matches that of hints |
673 if (inetAddr.Family() == KAfInet) |
685 if (!inetAddr.IsUnspecified()) |
674 { |
686 { |
675 err = CreateAddrInfoNode(nameRec, aHints, curr); |
687 if (inetAddr.Family() == KAfInet) |
676 } |
688 { |
677 else if (inetAddr.Family() == KAfInet6) |
689 err = CreateAddrInfoNode(nameRec, aHints, curr); |
678 { |
690 if (err != 0) |
679 err = CreateAddrInfoNode(nameRec, aHints, curr); |
691 { |
680 if (err != 0) |
692 break; |
681 break; |
693 } |
682 |
694 |
683 curr = &((*curr)->ai_next); |
695 curr = &((*curr)->ai_next); |
684 if (inetAddr.IsV4Mapped()) |
696 |
685 { |
697 inetAddr.ConvertToV4Mapped(); |
686 inetAddr.ConvertToV4(); |
698 nameRec.iAddr = inetAddr; |
687 nameRec.iAddr = inetAddr; |
699 |
688 err = CreateAddrInfoNode(nameRec, aHints, curr); |
700 err = CreateAddrInfoNode(nameRec, aHints, curr); |
689 |
701 if (err != 0) |
690 if(err != 0) |
702 { |
691 break; |
703 break; |
692 |
704 } |
693 if (err == 0) |
705 |
694 { |
706 (*curr)->ai_flags |= AI_V4MAPPED; |
695 (*curr)->ai_flags |= AI_V4MAPPED; |
707 curr = &((*curr)->ai_next); |
696 curr = &((*curr)->ai_next); |
708 } |
697 } |
709 else if (inetAddr.Family() == KAfInet6) |
698 } |
710 { |
699 } |
711 err = CreateAddrInfoNode(nameRec, aHints, curr); |
700 } |
712 if (err != 0) |
701 err = resolver.Next(nameEntry); //Get the next record |
713 { |
702 if(err != KErrNone) |
714 break; |
703 {//No more records. Not an error, just stop iterating |
715 } |
704 err = KErrNone; |
716 |
705 break; |
717 curr = &((*curr)->ai_next); |
706 } |
718 if (inetAddr.IsV4Mapped()) |
707 } while(err == KErrNone); |
719 { |
|
720 inetAddr.ConvertToV4(); |
|
721 nameRec.iAddr = inetAddr; |
|
722 |
|
723 err = CreateAddrInfoNode(nameRec, aHints, curr); |
|
724 if (err != 0) |
|
725 { |
|
726 break; |
|
727 } |
|
728 |
|
729 (*curr)->ai_flags |= AI_V4CONVERTED; |
|
730 curr = &((*curr)->ai_next); |
|
731 } |
|
732 } |
|
733 } |
|
734 |
|
735 err = resolver.Next(nameEntry); //Get the next record |
|
736 if (err != KErrNone) |
|
737 {//No more records. Not an error, just stop iterating |
|
738 err = KErrNone; |
|
739 break; |
|
740 } |
|
741 } while(err == KErrNone); |
708 |
742 |
709 |
743 |
710 //If no nodes are created even when the operation is succes, it's an error |
744 //If no nodes are created even when the operation is succes, it's an error |
711 if(err == 0 && *aRes == NULL) |
745 if(err == 0 && *aRes == NULL) |
712 err = -1; |
746 err = -1; |