1 /* Copyright (C) 1997-2014 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Mark Kettenis <kettenis@phys.uva.nl>, 1997.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
22 #include <netinet/in.h>
28 #include "nss_hesiod.h"
30 /* Declare a parser for Hesiod protocol entries. Although the format
31 of the entries is identical to those in /etc/protocols, here is no
32 predefined parser for us to use. */
34 #define ENTNAME protoent
36 struct protoent_data
{};
38 #define TRAILING_LIST_MEMBER p_aliases
39 #define TRAILING_LIST_SEPARATOR_P isspace
40 #include <nss/nss_files/files-parse.c>
43 STRING_FIELD (result
->p_name
, isspace
, 1);
44 INT_FIELD (result
->p_proto
, isspace
, 1, 10,);
48 _nss_hesiod_setprotoent (int stayopen
)
50 return NSS_STATUS_SUCCESS
;
54 _nss_hesiod_endprotoent (void)
56 return NSS_STATUS_SUCCESS
;
59 static enum nss_status
60 lookup (const char *name
, const char *type
, struct protoent
*proto
,
61 char *buffer
, size_t buflen
, int *errnop
)
63 struct parser_data
*data
= (void *) buffer
;
71 context
= _nss_hesiod_init ();
73 return NSS_STATUS_UNAVAIL
;
75 list
= hesiod_resolve (context
, name
, type
);
81 return err
== ENOENT
? NSS_STATUS_NOTFOUND
: NSS_STATUS_UNAVAIL
;
84 linebuflen
= buffer
+ buflen
- data
->linebuffer
;
90 size_t len
= strlen (*item
) + 1;
94 hesiod_free_list (context
, list
);
97 return NSS_STATUS_TRYAGAIN
;
100 memcpy (data
->linebuffer
, *item
, len
);
102 parse_res
= parse_line (buffer
, proto
, data
, buflen
, errnop
);
105 hesiod_free_list (context
, list
);
106 hesiod_end (context
);
107 return NSS_STATUS_TRYAGAIN
;
115 while (*item
!= NULL
&& !found
);
117 hesiod_free_list (context
, list
);
118 hesiod_end (context
);
122 __set_errno (olderr
);
123 return NSS_STATUS_NOTFOUND
;
126 return NSS_STATUS_SUCCESS
;
130 _nss_hesiod_getprotobyname_r (const char *name
, struct protoent
*proto
,
131 char *buffer
, size_t buflen
, int *errnop
)
133 return lookup (name
, "protocol", proto
, buffer
, buflen
, errnop
);
137 _nss_hesiod_getprotobynumber_r (const int protocol
, struct protoent
*proto
,
138 char *buffer
, size_t buflen
, int *errnop
)
142 snprintf (protostr
, sizeof protostr
, "%d", protocol
);
144 return lookup (protostr
, "protonum", proto
, buffer
, buflen
, errnop
);