17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * lib/krb5/os/full_ipadr.c
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * Copyright 1995 by the Massachusetts Institute of Technology.
57c478bd9Sstevel@tonic-gate * All Rights Reserved.
67c478bd9Sstevel@tonic-gate *
77c478bd9Sstevel@tonic-gate * Export of this software from the United States of America may
87c478bd9Sstevel@tonic-gate * require a specific license from the United States Government.
97c478bd9Sstevel@tonic-gate * It is the responsibility of any person or organization contemplating
107c478bd9Sstevel@tonic-gate * export to obtain such a license before exporting.
11*55fea89dSDan Cross *
127c478bd9Sstevel@tonic-gate * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
137c478bd9Sstevel@tonic-gate * distribute this software and its documentation for any purpose and
147c478bd9Sstevel@tonic-gate * without fee is hereby granted, provided that the above copyright
157c478bd9Sstevel@tonic-gate * notice appear in all copies and that both that copyright notice and
167c478bd9Sstevel@tonic-gate * this permission notice appear in supporting documentation, and that
177c478bd9Sstevel@tonic-gate * the name of M.I.T. not be used in advertising or publicity pertaining
187c478bd9Sstevel@tonic-gate * to distribution of the software without specific, written prior
197c478bd9Sstevel@tonic-gate * permission. Furthermore if you modify this software you must label
207c478bd9Sstevel@tonic-gate * your software as modified software and not distribute it in such a
217c478bd9Sstevel@tonic-gate * fashion that it might be confused with the original M.I.T. software.
227c478bd9Sstevel@tonic-gate * M.I.T. makes no representations about the suitability of
237c478bd9Sstevel@tonic-gate * this software for any purpose. It is provided "as is" without express
247c478bd9Sstevel@tonic-gate * or implied warranty.
25*55fea89dSDan Cross *
267c478bd9Sstevel@tonic-gate *
277c478bd9Sstevel@tonic-gate * Take an IP addr & port and generate a full IP address.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
30159d09a2SMark Phalan #include "k5-int.h"
317c478bd9Sstevel@tonic-gate
327c478bd9Sstevel@tonic-gate #ifdef HAVE_NETINET_IN_H
33*55fea89dSDan Cross
347c478bd9Sstevel@tonic-gate #include "os-proto.h"
35505d05c7Sgtb #if !defined(_WINSOCKAPI_)
367c478bd9Sstevel@tonic-gate
377c478bd9Sstevel@tonic-gate #include <netinet/in.h>
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate
407c478bd9Sstevel@tonic-gate /*ARGSUSED*/
417c478bd9Sstevel@tonic-gate krb5_error_code
krb5_make_fulladdr(krb5_context context,krb5_address * kaddr,krb5_address * kport,krb5_address * raddr)42505d05c7Sgtb krb5_make_fulladdr(krb5_context context, krb5_address *kaddr, krb5_address *kport, krb5_address *raddr)
437c478bd9Sstevel@tonic-gate {
44505d05c7Sgtb register krb5_octet * marshal;
457c478bd9Sstevel@tonic-gate krb5_int32 tmp32;
467c478bd9Sstevel@tonic-gate krb5_int16 tmp16;
477c478bd9Sstevel@tonic-gate
48*55fea89dSDan Cross if ((kport == NULL) || (kport == NULL))
497c478bd9Sstevel@tonic-gate return EINVAL;
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate raddr->length = kaddr->length + kport->length + (4 * sizeof(krb5_int32));
52505d05c7Sgtb if (!(raddr->contents = (krb5_octet *)malloc(raddr->length)))
537c478bd9Sstevel@tonic-gate return ENOMEM;
547c478bd9Sstevel@tonic-gate
557c478bd9Sstevel@tonic-gate raddr->addrtype = ADDRTYPE_ADDRPORT;
567c478bd9Sstevel@tonic-gate marshal = raddr->contents;
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate tmp16 = kaddr->addrtype;
597c478bd9Sstevel@tonic-gate *marshal++ = 0x00;
607c478bd9Sstevel@tonic-gate *marshal++ = 0x00;
617c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) (tmp16 & 0xff);
627c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate tmp32 = kaddr->length;
657c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) (tmp32 & 0xff);
667c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp32 >> 8) & 0xff);
677c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp32 >> 16) & 0xff);
687c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp32 >> 24) & 0xff);
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate (void) memcpy((char *)marshal, (char *)(kaddr->contents), kaddr->length);
717c478bd9Sstevel@tonic-gate marshal += kaddr->length;
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate tmp16 = kport->addrtype;
747c478bd9Sstevel@tonic-gate *marshal++ = 0x00;
757c478bd9Sstevel@tonic-gate *marshal++ = 0x00;
767c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) (tmp16 & 0xff);
777c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp16 >> 8) & 0xff);
787c478bd9Sstevel@tonic-gate
797c478bd9Sstevel@tonic-gate tmp32 = kport->length;
807c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) (tmp32 & 0xff);
817c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp32 >> 8) & 0xff);
827c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp32 >> 16) & 0xff);
837c478bd9Sstevel@tonic-gate *marshal++ = (krb5_octet) ((tmp32 >> 24) & 0xff);
847c478bd9Sstevel@tonic-gate
857c478bd9Sstevel@tonic-gate (void) memcpy((char *)marshal, (char *)(kport->contents), kport->length);
867c478bd9Sstevel@tonic-gate marshal += kport->length;
877c478bd9Sstevel@tonic-gate return 0;
887c478bd9Sstevel@tonic-gate }
897c478bd9Sstevel@tonic-gate #endif
90