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 * 4. Neither the name of the University nor the names of its contributors 1411819Sjulian * may be used to endorse or promote products derived from this software 1511819Sjulian * without specific prior written permission. 1611819Sjulian * 1711819Sjulian * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1811819Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1911819Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2011819Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2111819Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2211819Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2311819Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2411819Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2511819Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2611819Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2711819Sjulian * SUCH DAMAGE. 2811819Sjulian */ 2911819Sjulian 3084209Sdillon#include <sys/cdefs.h> 3184209Sdillon__FBSDID("$FreeBSD$"); 3284209Sdillon 3311819Sjulian#if defined(LIBC_SCCS) && !defined(lint) 3411819Sjulianstatic char sccsid[] = "@(#)ipx_ntoa.c"; 3511819Sjulian#endif /* LIBC_SCCS and not lint */ 3611819Sjulian 3711819Sjulian#include <sys/param.h> 3890868Smike#include <arpa/inet.h> 3911819Sjulian#include <netipx/ipx.h> 4011819Sjulian#include <stdio.h> 4111819Sjulian 42129667Sstefanfstatic char *spectHex(char *); 43129667Sstefanf 4411819Sjulianchar * 4511819Sjulianipx_ntoa(addr) 4611819Sjulian struct ipx_addr addr; 4711819Sjulian{ 4811819Sjulian static char obuf[40]; 4911819Sjulian union { union ipx_net net_e; u_long long_e; } net; 5011819Sjulian u_short port = htons(addr.x_port); 5192913Sobrien char *cp; 5211819Sjulian char *cp2; 5392913Sobrien u_char *up = addr.x_host.c_host; 5411819Sjulian u_char *uplim = up + 6; 5511819Sjulian 5611819Sjulian net.net_e = addr.x_net; 5737304Sbde sprintf(obuf, "%lx", (u_long)ntohl(net.long_e)); 5811819Sjulian cp = spectHex(obuf); 5911819Sjulian cp2 = cp + 1; 6011819Sjulian while (*up==0 && up < uplim) up++; 6111819Sjulian if (up == uplim) { 6211819Sjulian if (port) { 6311819Sjulian sprintf(cp, ".0"); 6411819Sjulian cp += 2; 6511819Sjulian } 6611819Sjulian } else { 6711819Sjulian sprintf(cp, ".%x", *up++); 6811819Sjulian while (up < uplim) { 6911819Sjulian while (*cp) cp++; 7011819Sjulian sprintf(cp, "%02x", *up++); 7111819Sjulian } 7211819Sjulian cp = spectHex(cp2); 7311819Sjulian } 7411819Sjulian if (port) { 7511819Sjulian sprintf(cp, ".%x", port); 7611819Sjulian spectHex(cp + 1); 7711819Sjulian } 7811819Sjulian return (obuf); 7911819Sjulian} 8011819Sjulian 8111819Sjulianstatic char * 8211819SjulianspectHex(p0) 8311819Sjulian char *p0; 8411819Sjulian{ 8511819Sjulian int ok = 0; 8611819Sjulian int nonzero = 0; 8792913Sobrien char *p = p0; 8811819Sjulian for (; *p; p++) switch (*p) { 8911819Sjulian 9011819Sjulian case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 9111819Sjulian case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 9211819Sjulian ok = 1; 9311819Sjulian case '1': case '2': case '3': case '4': case '5': 9411819Sjulian case '6': case '7': case '8': case '9': 9511819Sjulian nonzero = 1; 9611819Sjulian } 9711819Sjulian if (nonzero && !ok) { *p++ = 'H'; *p = 0; } 9811819Sjulian return (p); 9911819Sjulian} 100