1 /*
2  * lib/krb5/os/full_ipadr.c
3  *
4  * Copyright 1995 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  *
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  Furthermore if you modify this software you must label
20  * your software as modified software and not distribute it in such a
21  * fashion that it might be confused with the original M.I.T. software.
22  * M.I.T. makes no representations about the suitability of
23  * this software for any purpose.  It is provided "as is" without express
24  * or implied warranty.
25  *
26  *
27  * Take an IP addr & port and generate a full IP address.
28  */
29 
30 #include "k5-int.h"
31 
32 #ifdef HAVE_NETINET_IN_H
33 
34 #include "os-proto.h"
35 #if !defined(_WINSOCKAPI_)
36 
37 #include <netinet/in.h>
38 #endif
39 
40 /*ARGSUSED*/
41 krb5_error_code
krb5_make_fulladdr(krb5_context context,krb5_address * kaddr,krb5_address * kport,krb5_address * raddr)42 krb5_make_fulladdr(krb5_context context, krb5_address *kaddr, krb5_address *kport, krb5_address *raddr)
43 {
44     register krb5_octet * marshal;
45     krb5_int32 tmp32;
46     krb5_int16 tmp16;
47 
48     if ((kport == NULL) || (kport == NULL))
49 	return EINVAL;
50 
51     raddr->length = kaddr->length + kport->length + (4 * sizeof(krb5_int32));
52     if (!(raddr->contents = (krb5_octet *)malloc(raddr->length)))
53 	return ENOMEM;
54 
55     raddr->addrtype = ADDRTYPE_ADDRPORT;
56     marshal = raddr->contents;
57 
58     tmp16 = kaddr->addrtype;
59     *marshal++ = 0x00;
60     *marshal++ = 0x00;
61     *marshal++ = (krb5_octet) (tmp16 & 0xff);
62     *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff);
63 
64     tmp32 = kaddr->length;
65     *marshal++ = (krb5_octet) (tmp32 & 0xff);
66     *marshal++ = (krb5_octet) ((tmp32 >> 8) & 0xff);
67     *marshal++ = (krb5_octet) ((tmp32 >> 16) & 0xff);
68     *marshal++ = (krb5_octet) ((tmp32 >> 24) & 0xff);
69 
70     (void) memcpy((char *)marshal, (char *)(kaddr->contents), kaddr->length);
71     marshal += kaddr->length;
72 
73     tmp16 = kport->addrtype;
74     *marshal++ = 0x00;
75     *marshal++ = 0x00;
76     *marshal++ = (krb5_octet) (tmp16 & 0xff);
77     *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff);
78 
79     tmp32 = kport->length;
80     *marshal++ = (krb5_octet) (tmp32 & 0xff);
81     *marshal++ = (krb5_octet) ((tmp32 >> 8) & 0xff);
82     *marshal++ = (krb5_octet) ((tmp32 >> 16) & 0xff);
83     *marshal++ = (krb5_octet) ((tmp32 >> 24) & 0xff);
84 
85     (void) memcpy((char *)marshal, (char *)(kport->contents), kport->length);
86     marshal += kport->length;
87     return 0;
88 }
89 #endif
90