Migrate system/extra getaddrinfo test, and fix a bug in getservbyname(3).

This change is to migrate the getaddrinfo tests defined in the old file
system/extras/tests/bionic/libc/common/test_getaddrinfo.c
to the new place bionic/tests/netdb_test.cpp.

The test here is more thorough, and catches a bug in getservbyname(3)
that was breaking getaddrinfo(3)'s ability to look up services by name
without a hint that would cause it to ask for a specific protocol.

Change-Id: Ief5ebd0869496d1bc6a97861dfefa04bdf24bab1
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
diff --git a/libc/dns/net/getservbyname.c b/libc/dns/net/getservbyname.c
index c95c9b0..c32416c 100644
--- a/libc/dns/net/getservbyname.c
+++ b/libc/dns/net/getservbyname.c
@@ -25,29 +25,19 @@
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
-#include <sys/cdefs.h>
-#include <sys/types.h>
+
 #include <netdb.h>
+
 #include "servent.h"
 
-struct servent *
-getservbyname(const char *name, const char *proto)
-{
-    res_static       rs = __res_get_static();
-
-    if (rs == NULL || proto == NULL || name == NULL) {
-        errno = EINVAL;
-        return NULL;
+struct servent* getservbyname(const char* name, const char* proto) {
+  res_static rs = __res_get_static();
+  rs->servent_ptr = NULL;
+  struct servent* s;
+  while ((s = getservent_r(rs)) != NULL) {
+    if (strcmp(s->s_name, name) == 0 && (proto == NULL || strcmp(s->s_proto, proto) == 0)) {
+      return s;
     }
-
-    rs->servent_ptr = NULL;
-    while (1) {
-        struct servent*  s = getservent_r(rs);
-        if (s == NULL)
-            break;
-        if ( !strcmp( s->s_name, name ) && !strcmp( s->s_proto, proto ) )
-            return s;
-    }
-
-    return NULL;
+  }
+  return NULL;
 }