/* WARNING: This file was generated by dkct. Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: dk4sock01.ctr */ /* Copyright (C) 2015-2017, Dirk Krause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above opyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file dk4sock01.c The dk4sock01 module. */ #line 10 "dk4sock01.ctr" #include "dk4sock.h" #if DK4_HAVE_ERRNO_H #ifndef ERRNO_H_INCLUDED #include #define ERRNO_H_INCLUDED 1 #endif #endif #line 23 "dk4sock01.ctr" void dk4socket_error_reset(void) { #if DK4_ON_WINDOWS WSASetLastError(0); #else errno = 0; h_errno = 0; #endif } int dk4socket_error_get(void) { #if DK4_ON_WINDOWS return (WSAGetLastError()); #else return (errno); #endif } void dk4socket_error_report(dk4_er_t *erp, int ec) { #if DK4_ON_WINDOWS dk4error_set_idetails(erp, ec, WSAGetLastError()); #else switch (ec) { case DK4_E_SOCKET_GETHOSTBYNAME : { dk4error_set_idetails(erp, ec, h_errno); } break; default : { dk4error_set_idetails(erp, ec, errno); } break; } #endif } void dk4socket_debug_address(const char *text, struct sockaddr *addr, size_t sz) { #if TRACE_DEBUG FILE *fipo; struct sockaddr_in *soin; unsigned long ul; unsigned short us; fipo = dktrace_file(); if (NULL != fipo) { if (NULL != text) { fputs(text, fipo); fputc('\n', fipo); } switch (addr->sa_family) { case AF_INET : { fputs("Address family: AF_INET\n", fipo); soin = (struct sockaddr_in *)addr; ul = soin->sin_addr.s_addr; us = soin->sin_port; ul = ntohl(ul); us = ntohs(us); fprintf( fipo, "%lu.%lu.%lu.%lu:%u\n", ((ul >> 24) & 0x000000FFUL), ((ul >> 16) & 0x000000FFUL), ((ul >> 8) & 0x000000FFUL), (ul & 0x000000FFUL), (unsigned)us ); } break; case AF_INET6 : { fputs("Address family: AF_INET6\n", fipo); } break; case AF_UNIX : { fputs("Address family: AF_UNIX\n", fipo); } break; default : { fputs("Address family: !UNKNOWN!\n", fipo); } break; } } #endif } #if (DK4_HAVE_SETSOCKOPT) && defined(SOL_SOCKET) && defined(SO_ERROR) int dk4socket_non_null_getsockopt(int optval, socklen_t slo) { unsigned char *ptr; socklen_t i; socklen_t max; int back = 0; #line 127 "dk4sock01.ctr" max = sizeof(int); if (slo < max) { max = slo; } ptr = (unsigned char *)(&optval); for (i = 0; ((0 == back) && (i < max)); i++) { if (0x00 != *(ptr++)) { back = 1; } } #line 136 "dk4sock01.ctr" return back; } #endif