+\r
+/**\r
+ Create Dns QName according the queried domain name. \r
+ QName is a domain name represented as a sequence of labels, \r
+ where each label consists of a length octet followed by that \r
+ number of octets. The QName terminates with the zero \r
+ length octet for the null label of the root. Caller should \r
+ take responsibility to free the buffer in returned pointer.\r
+\r
+ @param DomainName The pointer to the queried domain name string. \r
+\r
+ @retval NULL Failed to fill QName.\r
+ @return QName filled successfully.\r
+ \r
+**/ \r
+CHAR8 *\r
+EFIAPI\r
+NetLibCreateDnsQName (\r
+ IN CHAR16 *DomainName\r
+ )\r
+{\r
+ CHAR8 *QueryName;\r
+ UINTN QueryNameSize;\r
+ CHAR8 *Header;\r
+ CHAR8 *Tail;\r
+ UINTN Len;\r
+ UINTN Index;\r
+\r
+ QueryName = NULL;\r
+ QueryNameSize = 0;\r
+ Header = NULL;\r
+ Tail = NULL;\r
+\r
+ //\r
+ // One byte for first label length, one byte for terminated length zero. \r
+ //\r
+ QueryNameSize = StrLen (DomainName) + 2;\r
+ \r
+ if (QueryNameSize > DNS_MAX_NAME_SIZE) {\r
+ return NULL;\r
+ }\r
+\r
+ QueryName = AllocateZeroPool (QueryNameSize);\r
+ if (QueryName == NULL) {\r
+ return NULL;\r
+ }\r
+ \r
+ Header = QueryName;\r
+ Tail = Header + 1;\r
+ Len = 0;\r
+ for (Index = 0; DomainName[Index] != 0; Index++) {\r
+ *Tail = (CHAR8) DomainName[Index];\r
+ if (*Tail == '.') {\r
+ *Header = (CHAR8) Len;\r
+ Header = Tail;\r
+ Tail ++;\r
+ Len = 0;\r
+ } else {\r
+ Tail++;\r
+ Len++;\r
+ }\r
+ }\r
+ *Header = (CHAR8) Len;\r
+ *Tail = 0;\r
+\r
+ return QueryName;\r
+}
\ No newline at end of file