1/* 2 * dllfunc.c - wrapper functions 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#include <process.h> 52 53#include "dlldef.h" 54 55WRAPPER_EXPORT int PASCAL FAR 56gethostname(char FAR * name, int namelen) { 57 int ret; 58 59 TRACE("ENTER gethostname\n"); 60 ret = _org_gethostname(name, namelen); 61 TRACE("LEAVE gethostname %d <%-.100s>\n", ret, name); 62 63 return (ret); 64} 65 66WRAPPER_EXPORT struct hostent FAR * PASCAL FAR 67gethostbyname(const char FAR * name) { 68 struct hostent FAR *ret; 69 char nbuff[256]; 70 char hbuff[256]; 71 BOOL stat; 72 idn_resconf_t encodeCtx; 73 74 TRACE("ENTER gethostbyname <%-.100s>\n", 75 (name != NULL ? name : "NULL")); 76 77 encodeCtx = idnGetContext(); 78 79 if (encodeCtx == NULL) { 80 TRACE("gethostbyname: not encode here\n"); 81 ret = _org_gethostbyname(name); 82 } else if (name == NULL) { 83 TRACE("gethostbyname: name is NULL\n"); 84 ret = _org_gethostbyname(name); 85 } else { 86 stat = idnConvReq(encodeCtx, name, nbuff, sizeof(nbuff)); 87 if (stat == FALSE) { 88 TRACE("idnConvReq failed\n"); 89 ret = NULL; 90 } else { 91 TRACE("Converted Name <%s>\n", 92 dumpName(nbuff, hbuff, sizeof(hbuff))); 93 ret = _org_gethostbyname(nbuff); 94 } 95 } 96 97 if (ret != NULL && encodeCtx != NULL) { 98 TRACE("Resulting Name <%s>\n", 99 dumpName(ret->h_name, hbuff, sizeof(hbuff))); 100 stat = idnConvRsp(encodeCtx, ret->h_name, nbuff, 101 sizeof(nbuff)); 102 if (stat == FALSE) { 103 TRACE("Decoding failed - return the name verbatim\n"); 104 } else { 105 TRACE("Converted Back <%s>\n", 106 dumpName(nbuff, hbuff, sizeof(hbuff))); 107 strcpy(ret->h_name, nbuff); 108 } 109 } 110 111 if (ret == NULL) { 112 TRACE("LEAVE gethostbyname NULL\n"); 113 } else { 114 TRACE("LEAVE gethostbyname <%s>\n", 115 dumpHost(ret, hbuff, sizeof(hbuff))); 116 } 117 return (ret); 118} 119 120WRAPPER_EXPORT struct hostent FAR * PASCAL FAR 121gethostbyaddr(const char FAR * addr, int len, int type) { 122 struct hostent FAR *ret; 123 char nbuff[256]; 124 char abuff[256]; 125 char hbuff[256]; 126 BOOL stat; 127 idn_resconf_t encodeCtx; 128 129 TRACE("ENTER gethostbyaddr <%s>\n", 130 dumpAddr(addr, len, abuff, sizeof(abuff))); 131 132 encodeCtx = idnGetContext(); 133 134 ret = _org_gethostbyaddr(addr, len, type); 135 136 if (ret != NULL && encodeCtx != NULL) { 137 TRACE("Resulting Name <%s>\n", 138 dumpName(ret->h_name, hbuff, sizeof(hbuff))); 139 stat = idnConvRsp(encodeCtx, ret->h_name, 140 nbuff, sizeof(nbuff)); 141 if (stat == FALSE) { 142 TRACE("Decoding failed - return the name verbatim\n"); 143 } else { 144 TRACE("Converted Back <%s>\n", 145 dumpName(nbuff, hbuff, sizeof(hbuff))); 146 strcpy(ret->h_name, nbuff); 147 } 148 } 149 150 if (ret == NULL) { 151 TRACE("LEAVE gethostbyaddr NULL\n") ; 152 } else { 153 TRACE("LEAVE gethostbyaddr <%s>\n", 154 dumpHost(ret, hbuff, sizeof(hbuff))); 155 } 156 return (ret); 157} 158 159WRAPPER_EXPORT HANDLE PASCAL FAR 160WSAAsyncGetHostByName(HWND hWnd, u_int wMsg, 161 const char FAR * name, char FAR * buf, int buflen) 162{ 163 HANDLE ret; 164 char nbuff[256]; 165 char hbuff[256]; 166 idn_resconf_t encodeCtx; 167 168 TRACE("ENTER WSAAsyncGetHostByName <%-.100s>\n", name); 169 170 encodeCtx = idnGetContext(); 171 172 if (encodeCtx == NULL || name == NULL) { 173 ret = _org_WSAAsyncGetHostByName(hWnd, wMsg, name, 174 buf, buflen); 175 } else { 176 idnHook(hWnd, wMsg, buf, encodeCtx); 177 idnConvReq(encodeCtx, name, nbuff, sizeof(nbuff)); 178 TRACE("Converted Name <%s>\n", 179 dumpName(nbuff, hbuff, sizeof(hbuff))); 180 ret = _org_WSAAsyncGetHostByName(hWnd, wMsg, nbuff, 181 buf, buflen); 182 } 183 184 TRACE("LEAVE WSAAsyncGetHostByName HANDLE %08x\n", ret); 185 186 return (ret); 187} 188 189WRAPPER_EXPORT HANDLE PASCAL FAR 190WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg, const char FAR * addr, 191 int len, int type, char FAR * buf, int buflen) 192{ 193 HANDLE ret; 194 char abuff[256]; 195 idn_resconf_t encodeCtx; 196 197 encodeCtx = idnGetContext(); 198 199 if (encodeCtx != NULL) { 200 idnHook(hWnd, wMsg, buf, encodeCtx); 201 } 202 203 TRACE("ENTER WSAAsyncGetHostByAddr <%s>\n", 204 dumpAddr(addr, len, abuff, sizeof(abuff))); 205 ret = _org_WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, 206 buf, buflen); 207 TRACE("LEAVE WSAAsyncGetHostByAddr HANDLE %08x\n", ret); 208 209 return (ret); 210} 211 212 213