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