genericopenlibs/openenvcore/backend/src/syscall/handlenms.cpp
changeset 63 a117ad66e027
parent 52 bf6a71c50e42
child 56 acd3cd4aaceb
equal deleted inserted replaced
59:09fa7c3c5079 63:a117ad66e027
   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;
   171 				{
   169 				{
   172 				err = ENAMETOOLONG;
   170 				err = ENAMETOOLONG;
   173 				}
   171 				}
   174 				
   172 				
   175 			}
   173 			}
   176 		}
   174 
   177 		hr.Close();
   175 		hr.Close();
       
   176 		}
   178 	return MapError(err, *aErrno);
   177 	return MapError(err, *aErrno);
   179 	}
   178 	}
   180 
   179 
   181 EXPORT_C int _getprotobyname_r(int* aErrno, const char* name, TProtocolDesc* pProtoInf)
   180 EXPORT_C int _getprotobyname_r(int* aErrno, const char* name, TProtocolDesc* pProtoInf)
   182 	{
   181 	{
   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;
   373                             break;
   370                             break;
   374                             }
   371                             }
   375                         }
   372                         }
   376                     err = r.Next(entry);
   373                     err = r.Next(entry);
   377                     }
   374                     }
       
   375                 
       
   376                 if (err == -5121) // KErrDndAddrNotFound, equivalent to a KErrNotFound?
       
   377                     {
       
   378                     err = HOST_NOT_FOUND;
       
   379                     }
   378                 }
   380                 }
   379 		             if (err == KErrNone)
   381 		             if (err == KErrNone)
   380 		                {
   382 		                {
   381 		                record = entry();
   383 		                record = entry();
   382 		                retval = mapNameRecord(rp, record, length, format);
   384 		                retval = mapNameRecord(rp, record, length, format);
   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;
   455                     if (addr.Family() == KAfInet) 
   455                     if (addr.Family() == KAfInet) 
   456                         {
   456                         {
   457                         break;
   457                         break;
   458                         }
   458                         }
   459                     
   459                     
   460                     if (addr.Family() == KAfInet6 && (addr.IsV4Compat() || addr.IsV4Mapped()))
   460                     if (addr.Family() == KAfInet6 && addr.IsV4Mapped())
   461                         {
   461                         {
   462                         addr.ConvertToV4(); 
   462                         addr.ConvertToV4(); 
   463                         entry().iAddr = addr;
   463                         entry().iAddr = addr;
   464                         break;
   464                         break;
   465                         }
   465                         }
   466                     }
   466                     }
   467                 err = r.Next(entry);
   467                 err = r.Next(entry);
       
   468                 }
       
   469             
       
   470             if (err == -5120) // KErrDndNameNotFound, equivalent to a KErrNotFound
       
   471                 {
       
   472                 err = HOST_NOT_FOUND;
   468                 }
   473                 }
   469             }
   474             }
   470         
   475         
   471         if (err == KErrNone)
   476         if (err == KErrNone)
   472             {
   477             {
   517 		return -1;
   522 		return -1;
   518 		}
   523 		}
   519 	
   524 	
   520 	return 0;
   525 	return 0;
   521 	}
   526 	}
       
   527 
       
   528 EXPORT_C int _unsetdefaultif_r(int* /*aErrno*/)
       
   529     {
       
   530     return Backend()->unsetdefaultif(EFalse);
       
   531     }
   522 
   532 
   523 /*
   533 /*
   524  * Helper function to create an addrinfo node and fill it.
   534  * Helper function to create an addrinfo node and fill it.
   525  * @param	aRec		 	The name details to be used to fill the addrinfo node
   535  * @param	aRec		 	The name details to be used to fill the addrinfo node
   526  * @param	aHints			The hints to be used
   536  * @param	aHints			The hints to be used
   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;
   717 		*aRes = NULL;
   751 		*aRes = NULL;
   718 		}
   752 		}
   719 	if(err != 0 && err != EAI_MEMORY)
   753 	if(err != 0 && err != EAI_MEMORY)
   720         err = EAI_FAIL;
   754         err = EAI_FAIL;
   721 	resolver.Close();
   755 	resolver.Close();
       
   756 
   722 	return err;
   757 	return err;
   723 	}
   758 	}
   724 
   759 
   725 /*
   760 /*
   726  * Frees the addrinfo structure created in backend
   761  * Frees the addrinfo structure created in backend