Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/testnss.c
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-25 11:56:24 +0100
committerArthur de Jong <arthur@arthurdejong.org>2006-11-25 11:56:24 +0100
commit70f10e2b6c10e7e47ab3377854e61a4534af79fb (patch)
tree4bab7fb53ab220809034db70411a23711fa7417b /testnss.c
parent1d4906c0e367960d35bd688e85b31cb6a376f5bc (diff)
implement server end of service name lookup and fix client end to translate between host and network byte order and to also pass protocol in request
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@123 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'testnss.c')
-rw-r--r--testnss.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/testnss.c b/testnss.c
index 9078783..85845f7 100644
--- a/testnss.c
+++ b/testnss.c
@@ -207,6 +207,22 @@ static void printrpc(struct rpcent *rpc)
"}\n",i,(int)(rpc->r_number));
}
+static void printserv(struct servent *serv)
+{
+ int i;
+ printf("struct servent {\n"
+ " s_name=\"%s\",\n",
+ serv->s_name);
+ for (i=0;serv->s_aliases[i]!=NULL;i++)
+ printf(" s_aliases[%d]=\"%s\",\n",
+ i,serv->s_aliases[i]);
+ printf(" s_aliases[%d]=NULL,\n"
+ " s_port=%d,\n"
+ " s_proto=\"%s\"\n"
+ "}\n",i,(int)(ntohs(serv->s_port)),
+ serv->s_proto);
+}
+
/* the main program... */
int main(int argc,char *argv[])
{
@@ -219,6 +235,7 @@ int main(int argc,char *argv[])
struct __netgrent netgroupresult;
struct protoent protoresult;
struct rpcent rpcresult;
+ struct servent servresult;
char buffer[1024];
enum nss_status res;
int errnocp,h_errnocp;
@@ -541,5 +558,37 @@ int main(int argc,char *argv[])
res=_nss_ldap_endrpcent();
printf("status=%s\n",nssstatus(res));
+ /* test getservbyname() */
+ printf("\nTEST getservbyname()\n");
+ res=_nss_ldap_getservbyname_r("srvfoo","udp",&servresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printserv(&servresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getrpcbynumber() */
+ printf("\nTEST getservbyport()\n");
+ res=_nss_ldap_getservbyport_r(ntohs(9988),NULL,&servresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printserv(&servresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}servent() */
+ printf("\nTEST {set,get,end}servent()\n");
+ res=_nss_ldap_setservent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getservent_r(&servresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printserv(&servresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endservent();
+ printf("status=%s\n",nssstatus(res));
+
return 0;
}