2 * Copyright (c) 1995 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 /* Almost all programs use these routines (implicitly) so it's a good
35 * place to put the version string. */
41 RCSID("$Id: rw.c,v 1.12.2.1 2000/06/23 03:37:33 assar Exp $");
44 krb_get_int(void *f, u_int32_t *to, int size, int lsb)
47 unsigned char *from = (unsigned char *)f;
51 for(i = size-1; i >= 0; i--)
52 *to = (*to << 8) | from[i];
54 for(i = 0; i < size; i++)
55 *to = (*to << 8) | from[i];
61 krb_put_int(u_int32_t from, void *to, size_t rem, int size)
64 unsigned char *p = (unsigned char *)to;
69 for(i = size - 1; i >= 0; i--){
77 /* addresses are always sent in network byte order */
80 krb_get_address(void *from, u_int32_t *to)
82 unsigned char *p = (unsigned char*)from;
83 *to = htonl((p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]);
88 krb_put_address(u_int32_t addr, void *to, size_t rem)
90 return krb_put_int(ntohl(addr), to, rem, 4);
94 krb_put_string(const char *from, void *to, size_t rem)
96 size_t len = strlen(from) + 1;
100 memcpy(to, from, len);
105 krb_get_string(void *from, char *to, size_t to_size)
107 strlcpy (to, (char *)from, to_size);
108 return strlen((char *)from) + 1;
112 krb_get_nir(void *from,
113 char *name, size_t name_len,
114 char *instance, size_t instance_len,
115 char *realm, size_t realm_len)
117 char *p = (char *)from;
119 p += krb_get_string(p, name, name_len);
120 p += krb_get_string(p, instance, instance_len);
122 p += krb_get_string(p, realm, realm_len);
123 return p - (char *)from;
127 krb_put_nir(const char *name,
128 const char *instance,
133 char *p = (char *)to;
136 tmp = krb_put_string(name, p, rem);
142 tmp = krb_put_string(instance, p, rem);
149 tmp = krb_put_string(realm, p, rem);
155 return p - (char *)to;