|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1986 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #if defined(LIBC_SCCS) && !defined(lint) ! 21: static char sccsid[] = "@(#)ns_ntoa.c 6.5 (Berkeley) 6/1/90"; ! 22: #endif /* LIBC_SCCS and not lint */ ! 23: ! 24: #include <sys/types.h> ! 25: #include <netns/ns.h> ! 26: ! 27: char * ! 28: ns_ntoa(addr) ! 29: struct ns_addr addr; ! 30: { ! 31: static char obuf[40]; ! 32: char *spectHex(); ! 33: union { union ns_net net_e; u_long long_e; } net; ! 34: u_short port = htons(addr.x_port); ! 35: register char *cp; ! 36: char *cp2; ! 37: register u_char *up = addr.x_host.c_host; ! 38: u_char *uplim = up + 6; ! 39: ! 40: net.net_e = addr.x_net; ! 41: sprintf(obuf, "%lx", ntohl(net.long_e)); ! 42: cp = spectHex(obuf); ! 43: cp2 = cp + 1; ! 44: while (*up==0 && up < uplim) up++; ! 45: if (up == uplim) { ! 46: if (port) { ! 47: sprintf(cp, ".0"); ! 48: cp += 2; ! 49: } ! 50: } else { ! 51: sprintf(cp, ".%x", *up++); ! 52: while (up < uplim) { ! 53: while (*cp) cp++; ! 54: sprintf(cp, "%02x", *up++); ! 55: } ! 56: cp = spectHex(cp2); ! 57: } ! 58: if (port) { ! 59: sprintf(cp, ".%x", port); ! 60: spectHex(cp + 1); ! 61: } ! 62: return (obuf); ! 63: } ! 64: ! 65: static char * ! 66: spectHex(p0) ! 67: char *p0; ! 68: { ! 69: int ok = 0; ! 70: int nonzero = 0; ! 71: register char *p = p0; ! 72: for (; *p; p++) switch (*p) { ! 73: ! 74: case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': ! 75: *p += ('A' - 'a'); ! 76: /* fall into . . . */ ! 77: case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': ! 78: ok = 1; ! 79: case '1': case '2': case '3': case '4': case '5': ! 80: case '6': case '7': case '8': case '9': ! 81: nonzero = 1; ! 82: } ! 83: if (nonzero && !ok) { *p++ = 'H'; *p = 0; } ! 84: return (p); ! 85: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.