ipx_ntoa.c revision 11819
111819Sjulian/* 211819Sjulian * Copyright (c) 1986, 1993 311819Sjulian * The Regents of the University of California. All rights reserved. 411819Sjulian * 511819Sjulian * Redistribution and use in source and binary forms, with or without 611819Sjulian * modification, are permitted provided that the following conditions 711819Sjulian * are met: 811819Sjulian * 1. Redistributions of source code must retain the above copyright 911819Sjulian * notice, this list of conditions and the following disclaimer. 1011819Sjulian * 2. Redistributions in binary form must reproduce the above copyright 1111819Sjulian * notice, this list of conditions and the following disclaimer in the 1211819Sjulian * documentation and/or other materials provided with the distribution. 1311819Sjulian * 3. All advertising materials mentioning features or use of this software 1411819Sjulian * must display the following acknowledgement: 1511819Sjulian * This product includes software developed by the University of 1611819Sjulian * California, Berkeley and its contributors. 1711819Sjulian * 4. Neither the name of the University nor the names of its contributors 1811819Sjulian * may be used to endorse or promote products derived from this software 1911819Sjulian * without specific prior written permission. 2011819Sjulian * 2111819Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2211819Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2311819Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2411819Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2511819Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2611819Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2711819Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2811819Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2911819Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3011819Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3111819Sjulian * SUCH DAMAGE. 3211819Sjulian */ 3311819Sjulian 3411819Sjulian#if defined(LIBC_SCCS) && !defined(lint) 3511819Sjulianstatic char sccsid[] = "@(#)ipx_ntoa.c"; 3611819Sjulian#endif /* LIBC_SCCS and not lint */ 3711819Sjulian 3811819Sjulian#include <sys/param.h> 3911819Sjulian#include <netipx/ipx.h> 4011819Sjulian#include <stdio.h> 4111819Sjulian 4211819Sjulianchar * 4311819Sjulianipx_ntoa(addr) 4411819Sjulian struct ipx_addr addr; 4511819Sjulian{ 4611819Sjulian static char obuf[40]; 4711819Sjulian union { union ipx_net net_e; u_long long_e; } net; 4811819Sjulian u_short port = htons(addr.x_port); 4911819Sjulian register char *cp; 5011819Sjulian char *cp2; 5111819Sjulian register u_char *up = addr.x_host.c_host; 5211819Sjulian u_char *uplim = up + 6; 5311819Sjulian static char *spectHex(); 5411819Sjulian 5511819Sjulian net.net_e = addr.x_net; 5611819Sjulian sprintf(obuf, "%lx", ntohl(net.long_e)); 5711819Sjulian cp = spectHex(obuf); 5811819Sjulian cp2 = cp + 1; 5911819Sjulian while (*up==0 && up < uplim) up++; 6011819Sjulian if (up == uplim) { 6111819Sjulian if (port) { 6211819Sjulian sprintf(cp, ".0"); 6311819Sjulian cp += 2; 6411819Sjulian } 6511819Sjulian } else { 6611819Sjulian sprintf(cp, ".%x", *up++); 6711819Sjulian while (up < uplim) { 6811819Sjulian while (*cp) cp++; 6911819Sjulian sprintf(cp, "%02x", *up++); 7011819Sjulian } 7111819Sjulian cp = spectHex(cp2); 7211819Sjulian } 7311819Sjulian if (port) { 7411819Sjulian sprintf(cp, ".%x", port); 7511819Sjulian spectHex(cp + 1); 7611819Sjulian } 7711819Sjulian return (obuf); 7811819Sjulian} 7911819Sjulian 8011819Sjulianstatic char * 8111819SjulianspectHex(p0) 8211819Sjulian char *p0; 8311819Sjulian{ 8411819Sjulian int ok = 0; 8511819Sjulian int nonzero = 0; 8611819Sjulian register char *p = p0; 8711819Sjulian for (; *p; p++) switch (*p) { 8811819Sjulian 8911819Sjulian case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 9011819Sjulian case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 9111819Sjulian ok = 1; 9211819Sjulian case '1': case '2': case '3': case '4': case '5': 9311819Sjulian case '6': case '7': case '8': case '9': 9411819Sjulian nonzero = 1; 9511819Sjulian } 9611819Sjulian if (nonzero && !ok) { *p++ = 'H'; *p = 0; } 9711819Sjulian return (p); 9811819Sjulian} 99