2
test_ethers.c - simple tests of developed nss code
4
Copyright (C) 2006 West Consulting
5
Copyright (C) 2006 Arthur de Jong
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Lesser General Public
9
License as published by the Free Software Foundation; either
10
version 2.1 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Lesser General Public License for more details.
17
You should have received a copy of the GNU Lesser General Public
18
License along with this library; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28
#include <sys/types.h>
29
#include <sys/socket.h>
30
#include <arpa/inet.h>
32
#include "nss/prototypes.h"
34
static char *nssstatus(enum nss_status retv)
38
case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
39
case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
40
case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
41
case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
42
case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
43
default: return "NSS_STATUS_**ILLEGAL**";
47
static void printether(struct etherent *ether)
49
printf("struct etherent {\n"
53
ether->e_name,ether_ntoa(&(ether->e_addr)));
56
/* the main program... */
57
int main(int argc,char *argv[])
59
struct etherent etherresult;
64
/* test ether_hostton() */
65
printf("\nTEST ether_hostton()\n");
66
res=_nss_ldap_gethostton_r("spiritus",ðerresult,buffer,1024,&errnocp);
67
printf("status=%s\n",nssstatus(res));
68
if (res==NSS_STATUS_SUCCESS)
69
printether(ðerresult);
71
printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
73
/* test ether_ntohost() */
74
printf("\nTEST ether_ntohost()\n");
75
res=_nss_ldap_getntohost_r(ether_aton("00:E0:4C:39:D3:6A"),
76
ðerresult,buffer,1024,&errnocp);
77
printf("status=%s\n",nssstatus(res));
78
if (res==NSS_STATUS_SUCCESS)
79
printether(ðerresult);
81
printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
83
/* test {set,get,end}etherent() */
84
printf("\nTEST {set,get,end}etherent()\n");
85
res=_nss_ldap_setetherent(1);
86
printf("status=%s\n",nssstatus(res));
87
while ((res=_nss_ldap_getetherent_r(ðerresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
89
printf("status=%s\n",nssstatus(res));
90
printether(ðerresult);
92
printf("status=%s\n",nssstatus(res));
93
printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
94
res=_nss_ldap_endetherent();
95
printf("status=%s\n",nssstatus(res));