1 /* $NetBSD: dllfunc.c,v 1.3 2014/12/10 04:37:56 christos Exp $ */ 2 3 /* 4 * dllfunc.c - wrapper functions 5 */ 6 7 /* 8 * Copyright (c) 2000 Japan Network Information Center. All rights reserved. 9 * 10 * By using this file, you agree to the terms and conditions set forth bellow. 11 * 12 * LICENSE TERMS AND CONDITIONS 13 * 14 * The following License Terms and Conditions apply, unless a different 15 * license is obtained from Japan Network Information Center ("JPNIC"), 16 * a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda, 17 * Chiyoda-ku, Tokyo 101-0047, Japan. 18 * 19 * 1. Use, Modification and Redistribution (including distribution of any 20 * modified or derived work) in source and/or binary forms is permitted 21 * under this License Terms and Conditions. 22 * 23 * 2. Redistribution of source code must retain the copyright notices as they 24 * appear in each source code file, this License Terms and Conditions. 25 * 26 * 3. Redistribution in binary form must reproduce the Copyright Notice, 27 * this License Terms and Conditions, in the documentation and/or other 28 * materials provided with the distribution. For the purposes of binary 29 * distribution the "Copyright Notice" refers to the following language: 30 * "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved." 31 * 32 * 4. The name of JPNIC may not be used to endorse or promote products 33 * derived from this Software without specific prior written approval of 34 * JPNIC. 35 * 36 * 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC 37 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 38 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 39 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE 40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 41 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 42 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 43 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 45 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 46 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 47 */ 48 49 #include <windows.h> 50 #include <stdio.h> 51 #include <stdlib.h> 52 #include <string.h> 53 #include <process.h> 54 55 #include "dlldef.h" 56 57 WRAPPER_EXPORT int PASCAL FAR 58 gethostname(char FAR * name, int namelen) { 59 int ret; 60 61 TRACE("ENTER gethostname\n"); 62 ret = _org_gethostname(name, namelen); 63 TRACE("LEAVE gethostname %d <%-.100s>\n", ret, name); 64 65 return (ret); 66 } 67 68 WRAPPER_EXPORT struct hostent FAR * PASCAL FAR 69 gethostbyname(const char FAR * name) { 70 struct hostent FAR *ret; 71 char nbuff[256]; 72 char hbuff[256]; 73 BOOL stat; 74 idn_resconf_t encodeCtx; 75 76 TRACE("ENTER gethostbyname <%-.100s>\n", 77 (name != NULL ? name : "NULL")); 78 79 encodeCtx = idnGetContext(); 80 81 if (encodeCtx == NULL) { 82 TRACE("gethostbyname: not encode here\n"); 83 ret = _org_gethostbyname(name); 84 } else if (name == NULL) { 85 TRACE("gethostbyname: name is NULL\n"); 86 ret = _org_gethostbyname(name); 87 } else { 88 stat = idnConvReq(encodeCtx, name, nbuff, sizeof(nbuff)); 89 if (stat == FALSE) { 90 TRACE("idnConvReq failed\n"); 91 ret = NULL; 92 } else { 93 TRACE("Converted Name <%s>\n", 94 dumpName(nbuff, hbuff, sizeof(hbuff))); 95 ret = _org_gethostbyname(nbuff); 96 } 97 } 98 99 if (ret != NULL && encodeCtx != NULL) { 100 TRACE("Resulting Name <%s>\n", 101 dumpName(ret->h_name, hbuff, sizeof(hbuff))); 102 stat = idnConvRsp(encodeCtx, ret->h_name, nbuff, 103 sizeof(nbuff)); 104 if (stat == FALSE) { 105 TRACE("Decoding failed - return the name verbatim\n"); 106 } else { 107 TRACE("Converted Back <%s>\n", 108 dumpName(nbuff, hbuff, sizeof(hbuff))); 109 strcpy(ret->h_name, nbuff); 110 } 111 } 112 113 if (ret == NULL) { 114 TRACE("LEAVE gethostbyname NULL\n"); 115 } else { 116 TRACE("LEAVE gethostbyname <%s>\n", 117 dumpHost(ret, hbuff, sizeof(hbuff))); 118 } 119 return (ret); 120 } 121 122 WRAPPER_EXPORT struct hostent FAR * PASCAL FAR 123 gethostbyaddr(const char FAR * addr, int len, int type) { 124 struct hostent FAR *ret; 125 char nbuff[256]; 126 char abuff[256]; 127 char hbuff[256]; 128 BOOL stat; 129 idn_resconf_t encodeCtx; 130 131 TRACE("ENTER gethostbyaddr <%s>\n", 132 dumpAddr(addr, len, abuff, sizeof(abuff))); 133 134 encodeCtx = idnGetContext(); 135 136 ret = _org_gethostbyaddr(addr, len, type); 137 138 if (ret != NULL && encodeCtx != NULL) { 139 TRACE("Resulting Name <%s>\n", 140 dumpName(ret->h_name, hbuff, sizeof(hbuff))); 141 stat = idnConvRsp(encodeCtx, ret->h_name, 142 nbuff, sizeof(nbuff)); 143 if (stat == FALSE) { 144 TRACE("Decoding failed - return the name verbatim\n"); 145 } else { 146 TRACE("Converted Back <%s>\n", 147 dumpName(nbuff, hbuff, sizeof(hbuff))); 148 strcpy(ret->h_name, nbuff); 149 } 150 } 151 152 if (ret == NULL) { 153 TRACE("LEAVE gethostbyaddr NULL\n") ; 154 } else { 155 TRACE("LEAVE gethostbyaddr <%s>\n", 156 dumpHost(ret, hbuff, sizeof(hbuff))); 157 } 158 return (ret); 159 } 160 161 WRAPPER_EXPORT HANDLE PASCAL FAR 162 WSAAsyncGetHostByName(HWND hWnd, u_int wMsg, 163 const char FAR * name, char FAR * buf, int buflen) 164 { 165 HANDLE ret; 166 char nbuff[256]; 167 char hbuff[256]; 168 idn_resconf_t encodeCtx; 169 170 TRACE("ENTER WSAAsyncGetHostByName <%-.100s>\n", name); 171 172 encodeCtx = idnGetContext(); 173 174 if (encodeCtx == NULL || name == NULL) { 175 ret = _org_WSAAsyncGetHostByName(hWnd, wMsg, name, 176 buf, buflen); 177 } else { 178 idnHook(hWnd, wMsg, buf, encodeCtx); 179 idnConvReq(encodeCtx, name, nbuff, sizeof(nbuff)); 180 TRACE("Converted Name <%s>\n", 181 dumpName(nbuff, hbuff, sizeof(hbuff))); 182 ret = _org_WSAAsyncGetHostByName(hWnd, wMsg, nbuff, 183 buf, buflen); 184 } 185 186 TRACE("LEAVE WSAAsyncGetHostByName HANDLE %08x\n", ret); 187 188 return (ret); 189 } 190 191 WRAPPER_EXPORT HANDLE PASCAL FAR 192 WSAAsyncGetHostByAddr(HWND hWnd, u_int wMsg, const char FAR * addr, 193 int len, int type, char FAR * buf, int buflen) 194 { 195 HANDLE ret; 196 char abuff[256]; 197 idn_resconf_t encodeCtx; 198 199 encodeCtx = idnGetContext(); 200 201 if (encodeCtx != NULL) { 202 idnHook(hWnd, wMsg, buf, encodeCtx); 203 } 204 205 TRACE("ENTER WSAAsyncGetHostByAddr <%s>\n", 206 dumpAddr(addr, len, abuff, sizeof(abuff))); 207 ret = _org_WSAAsyncGetHostByAddr(hWnd, wMsg, addr, len, type, 208 buf, buflen); 209 TRACE("LEAVE WSAAsyncGetHostByAddr HANDLE %08x\n", ret); 210 211 return (ret); 212 } 213 214 215