17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * lib/krb5/os/port2ip.c
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * Copyright 1991 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 ADDRPORT address and split into IP addr & port.
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
30159d09a2SMark Phalan #include "k5-int.h"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef HAVE_NETINET_IN_H
337c478bd9Sstevel@tonic-gate #include "os-proto.h"
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*ARGSUSED*/
367c478bd9Sstevel@tonic-gate krb5_error_code
krb5_unpack_full_ipaddr(krb5_context context,const krb5_address * inaddr,krb5_int32 * adr,krb5_int16 * port)37505d05c7Sgtb krb5_unpack_full_ipaddr(krb5_context context, const krb5_address *inaddr, krb5_int32 *adr, krb5_int16 *port)
387c478bd9Sstevel@tonic-gate {
397c478bd9Sstevel@tonic-gate     unsigned long smushaddr;
407c478bd9Sstevel@tonic-gate     unsigned short smushport;
417c478bd9Sstevel@tonic-gate     register krb5_octet *marshal;
427c478bd9Sstevel@tonic-gate     krb5_addrtype temptype;
437c478bd9Sstevel@tonic-gate     krb5_ui_4 templength;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate     if (inaddr->addrtype != ADDRTYPE_ADDRPORT)
467c478bd9Sstevel@tonic-gate 	return KRB5_PROG_ATYPE_NOSUPP;
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate     if (inaddr->length != sizeof(smushaddr)+ sizeof(smushport) +
497c478bd9Sstevel@tonic-gate 	2*sizeof(temptype) + 2*sizeof(templength))
507c478bd9Sstevel@tonic-gate 	return KRB5_PROG_ATYPE_NOSUPP;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate     marshal = inaddr->contents;
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate     (void) memcpy((char *)&temptype, (char *)marshal, sizeof(temptype));
557c478bd9Sstevel@tonic-gate     marshal += sizeof(temptype);
567c478bd9Sstevel@tonic-gate     if (temptype != htons(ADDRTYPE_INET))
577c478bd9Sstevel@tonic-gate 	return KRB5_PROG_ATYPE_NOSUPP;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate     (void) memcpy((char *)&templength, (char *)marshal, sizeof(templength));
607c478bd9Sstevel@tonic-gate     marshal += sizeof(templength);
617c478bd9Sstevel@tonic-gate     if (templength != htonl(sizeof(smushaddr)))
627c478bd9Sstevel@tonic-gate 	return KRB5_PROG_ATYPE_NOSUPP;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate     (void) memcpy((char *)&smushaddr, (char *)marshal, sizeof(smushaddr));
657c478bd9Sstevel@tonic-gate     /* leave in net order */
667c478bd9Sstevel@tonic-gate     marshal += sizeof(smushaddr);
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate     (void) memcpy((char *)&temptype, (char *)marshal, sizeof(temptype));
697c478bd9Sstevel@tonic-gate     marshal += sizeof(temptype);
707c478bd9Sstevel@tonic-gate     if (temptype != htons(ADDRTYPE_IPPORT))
717c478bd9Sstevel@tonic-gate 	return KRB5_PROG_ATYPE_NOSUPP;
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate     (void) memcpy((char *)&templength, (char *)marshal, sizeof(templength));
747c478bd9Sstevel@tonic-gate     marshal += sizeof(templength);
757c478bd9Sstevel@tonic-gate     if (templength != htonl(sizeof(smushport)))
767c478bd9Sstevel@tonic-gate 	return KRB5_PROG_ATYPE_NOSUPP;
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate     (void) memcpy((char *)&smushport, (char *)marshal, sizeof(smushport));
797c478bd9Sstevel@tonic-gate     /* leave in net order */
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate     *adr = (krb5_int32) smushaddr;
827c478bd9Sstevel@tonic-gate     *port = (krb5_int16) smushport;
837c478bd9Sstevel@tonic-gate     return 0;
847c478bd9Sstevel@tonic-gate }
857c478bd9Sstevel@tonic-gate #endif
86