1/* 2 * dump.c - dump data 3 */ 4 5/* 6 * Copyright (c) 2000 Japan Network Information Center. All rights reserved. 7 * 8 * By using this file, you agree to the terms and conditions set forth bellow. 9 * 10 * LICENSE TERMS AND CONDITIONS 11 * 12 * The following License Terms and Conditions apply, unless a different 13 * license is obtained from Japan Network Information Center ("JPNIC"), 14 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, 15 * Chiyoda-ku, Tokyo 101-0047, Japan. 16 * 17 * 1. Use, Modification and Redistribution (including distribution of any 18 * modified or derived work) in source and/or binary forms is permitted 19 * under this License Terms and Conditions. 20 * 21 * 2. Redistribution of source code must retain the copyright notices as they 22 * appear in each source code file, this License Terms and Conditions. 23 * 24 * 3. Redistribution in binary form must reproduce the Copyright Notice, 25 * this License Terms and Conditions, in the documentation and/or other 26 * materials provided with the distribution. For the purposes of binary 27 * distribution the "Copyright Notice" refers to the following language: 28 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." 29 * 30 * 4. The name of JPNIC may not be used to endorse or promote products 31 * derived from this Software without specific prior written approval of 32 * JPNIC. 33 * 34 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC 35 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 36 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 37 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE 38 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 39 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 40 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 41 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 42 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 43 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 44 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 45 */ 46 47#include <windows.h> 48#include <stdio.h> 49#include <stdlib.h> 50#include <string.h> 51 52#include "wrapcommon.h" 53 54char * 55dumpAddr(const char FAR *addr, int len, char *buff, size_t size) { 56 int i; 57 char *p; 58 59 buff[0] = '\0'; 60 for (i = 0, p = buff; i < len; i++) { 61 char digits[8]; 62 63 sprintf(digits, "%d", (addr[i] & 0xff)); 64 if (i + 1 < len) { 65 strcat(digits, "."); 66 } 67 if (strlen(digits) >= size) { 68 break; 69 } 70 strcpy(p, digits); 71 p += strlen(digits); 72 size -= strlen(digits); 73 } 74 return (buff); 75} 76 77char * 78dumpHost(const struct hostent FAR *hp, char *buff, size_t size) { 79 char *p = buff; 80 81 p[0] = '\0'; 82 if (strlen(hp->h_name) + 1 < size) { 83 sprintf(p, "%s ", hp->h_name); 84 p += strlen(p); 85 size -= strlen(p); 86 } 87 dumpAddr(hp->h_addr_list[0], hp->h_length, p, size); 88 return (buff); 89} 90 91char * 92dumpName(const char *name, char *buff, size_t size) { 93 const char *sp; 94 char *dp; 95 96 for (sp = name, dp = buff; *sp != '\0'; sp++) { 97 if (*sp >= 0x21 && *sp <= 0x7e) { 98 if (size < 2) { 99 break; 100 } 101 *dp++ = *sp; 102 size--; 103 } else { 104 if (size < 5) { 105 break; 106 } 107 dp[0] = '\\'; 108 dp[1] = 'x'; 109 sprintf(dp + 2, "%02x", *sp & 0xff); 110 dp += 4; 111 size -= 4; 112 } 113 } 114 *dp = '\0'; 115 116 return (buff); 117} 118 119