1*85f5e301Schristos /* $NetBSD: __rpc_getxid.c,v 1.4 2024/01/23 17:24:38 christos Exp $ */
235beb403Sitojun /* $OpenBSD: ip_id.c,v 1.6 2002/03/15 18:19:52 millert Exp $ */
335beb403Sitojun
435beb403Sitojun /*
5cfbab92fSitojun * Copyright (C) 2003 WIDE Project.
635beb403Sitojun * All rights reserved.
735beb403Sitojun *
835beb403Sitojun * Redistribution and use in source and binary forms, with or without
935beb403Sitojun * modification, are permitted provided that the following conditions
1035beb403Sitojun * are met:
1135beb403Sitojun * 1. Redistributions of source code must retain the above copyright
1235beb403Sitojun * notice, this list of conditions and the following disclaimer.
1335beb403Sitojun * 2. Redistributions in binary form must reproduce the above copyright
1435beb403Sitojun * notice, this list of conditions and the following disclaimer in the
1535beb403Sitojun * documentation and/or other materials provided with the distribution.
16cfbab92fSitojun * 3. Neither the name of the project nor the names of its contributors
17cfbab92fSitojun * may be used to endorse or promote products derived from this software
18cfbab92fSitojun * without specific prior written permission.
1935beb403Sitojun *
20cfbab92fSitojun * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21cfbab92fSitojun * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22cfbab92fSitojun * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23cfbab92fSitojun * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24cfbab92fSitojun * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25cfbab92fSitojun * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26cfbab92fSitojun * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27cfbab92fSitojun * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28cfbab92fSitojun * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29cfbab92fSitojun * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30cfbab92fSitojun * SUCH DAMAGE.
3135beb403Sitojun */
3235beb403Sitojun
3335beb403Sitojun #include <sys/cdefs.h>
3435beb403Sitojun #if defined(LIBC_SCCS) && !defined(lint)
35*85f5e301Schristos __RCSID("$NetBSD: __rpc_getxid.c,v 1.4 2024/01/23 17:24:38 christos Exp $");
3635beb403Sitojun #endif
3735beb403Sitojun
3835beb403Sitojun #include <sys/types.h>
39cfbab92fSitojun
401ecc9b58Sitojun #include "namespace.h"
41*85f5e301Schristos #include "reentrant.h"
421ecc9b58Sitojun
4335beb403Sitojun #include <stdlib.h>
44cfbab92fSitojun #include <randomid.h>
4535beb403Sitojun #include <rpc/rpc.h>
4635beb403Sitojun #include "rpc_internal.h"
4735beb403Sitojun
4835beb403Sitojun u_int32_t
__rpc_getxid(void)4935beb403Sitojun __rpc_getxid(void)
5035beb403Sitojun {
51cfbab92fSitojun static randomid_t ctx = NULL;
5235beb403Sitojun
53cfbab92fSitojun if (!ctx) {
54cfbab92fSitojun ctx = randomid_new(32, RANDOMID_TIMEO_DEFAULT);
55cfbab92fSitojun if (!ctx)
56cfbab92fSitojun abort();
5735beb403Sitojun }
5835beb403Sitojun
59cfbab92fSitojun return randomid(ctx);
6035beb403Sitojun }
61