📄 rvinet.c
字号:
/*****************************************************************************
Filename : rvinet.c
Description: Internet Protocol utilities interface definition.
******************************************************************************
Copyright (c) 1999 RADVision Inc.
******************************************************************************
NOTICE:
This document contains information that is proprietary to RADVision Inc.
No part of this publication may be reproduced in any form whatsoever
without written prior approval by RADVision Inc.
RADVision Inc. reserves the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
******************************************************************************
$Revision:$
$Date:$
$Author: S. Eaton$
*****************************************************************************/
#include "rvinet.h"
#if defined(RV_SOCKETS_PSOS)
#include "psos.h"
#include "pna.h"
#include "pnacfg.h"
#include <string.h>
#include "rvtypes.h"
extern pNA_CT PnaCfg;
#endif
/* ip_buffer must be at least 16 bytes */
#if defined(RV_SOCKETS_NUCLEUS) /* Nucleus structures are different */
char * rvInetNtoa(UINT32 in32, char *ip_buffer)
#else
char * rvInetNtoa(struct in_addr in, char *ip_buffer)
#endif
{
int curr_num, curr_dig;
RvUint32 num;
char *p = &(ip_buffer[14]);
RvUint32 addr;
#if defined(RV_SOCKETS_NUCLEUS)
struct in_addr in;
in.s_addr = in32;
#endif
ip_buffer[15] = '\0';
addr = ntohl(in.s_addr);
for (curr_num = 0; curr_num <= 3; curr_num++)
{
num = addr & 0xFF;
addr >>= 8;
for (curr_dig = 0; curr_dig <= 2; curr_dig++)
{
*p = (char)(((char)(num % 10) + '0'));
num /= 10;
p--;
if (num == 0)
break;
}
if (curr_num < 3)
*p-- = '.';
}
return p+1;
}
#if defined(RV_SOCKETS_PSOS) || defined(RV_SOCKETS_NUCLEUS)
#define INADDR_NONE (~0)
RvUint32 inet_addr(const char *cp)
{
const char *p = cp;
RvUint32 addr[4], maxvals[4];
RvUint32 net_addr = 0, last_val;
int n = 0, i = 0;
memset(maxvals, 0xFF, sizeof maxvals);
for (;;)
{
if (*p == 0 || *p == '.' || n >= 4)
return INADDR_NONE;
addr[n] = 0;
last_val = 0;
if (n)
{
maxvals[n] = maxvals[n - 1] >> 8;
maxvals[n - 1] = 255;
}
do
{
if (!((*p >= '0') && (*p <= '9')))
return INADDR_NONE;
addr[n] *= 10;
addr[n] += (*p - '0');
if (addr[n] < last_val) /* overflow check */
return INADDR_NONE;
last_val = addr[n];
p++;
if (*p == 0) goto stop;
} while (*p != '.');
p++;
n++;
}
stop:
for (i = 0; i <= n; i++)
if (addr[n] > maxvals[n])
return INADDR_NONE;
net_addr = addr[n];
if (n >= 1) net_addr += (addr[0] << 24);
if (n >= 2) net_addr += (addr[1] << 16);
if (n >= 3) net_addr += (addr[2] << 8);
return htonl(net_addr);
}
#endif
#if defined(RV_SOCKETS_PSOS)
int gethostname(char *buf, size_t size) {
strncpy(buf, PnaCfg.nc_hostname, size);
return 0;
}
#endif
#if defined(RV_OS_OSE)
#include <ose.h>
#include <string.h>
/* since there is no host name in OSE, get it from the environent. */
int gethostname(char *buf, size_t size) {
char *result;
result = get_env(current_process(), "HOSTNAME");
if(result == NULL) {
result = get_env(get_bid(current_process()), "HOSTNAME"); /* try block environment */
if(result == NULL) {
*buf = '\0';
return -1;
}
}
strncpy(buf, result, size);
free_buf((union SIGNAL **)&result);
return 0;
}
#endif
#if defined(RV_INET_IPV6)
RvBool rvInetIsIpv6(const char* str)
{
char buffer[INET6_ADDRSTRLEN];
return (inet_pton(AF_INET6, str, buffer));
}
#endif
const char *rvGetLastErrorAsString(int errorno)
{
static char notImplementedErrorText[] = "No text for error";
#if defined(RV_DEBUG_ON)
#if defined(RV_SOCKETS_WSOCK)
static char unknownErrorText[] = "Unknown error type.";
switch(errorno)
{
case WSAEACCES :
return "Access denied.";
case WSAEADDRINUSE :
return "Address already in use.";
case WSAEADDRNOTAVAIL:
return "Cannot assign requested address.";
case WSAEAFNOSUPPORT:
return "Address family not supported by protocol family.";
case WSAEALREADY:
return "Operation already in progress.";
case WSAECONNABORTED:
return "Software caused connection abort.";
case WSAECONNREFUSED:
return "Connection refused.";
case WSAECONNRESET :
return "Connection reset by peer.";
case WSAEDESTADDRREQ:
return "Destination address required.";
case WSAEFAULT :
return "Bad address.";
case WSAEHOSTDOWN :
return "Host is down.";
case WSAEHOSTUNREACH:
return "No route to host.";
case WSAEINTR:
return "Interrupted function call.";
case WSAEINVAL:
return "Invalid argument.";
case WSAEMFILE:
return "Too many open files.";
case WSAEMSGSIZE:
return "Message too long.";
case WSAENETDOWN:
return "Network is down.";
case WSAENETRESET:
return "Network dropped connection on reset.";
case WSAENETUNREACH:
return "Network is unreachable.";
case WSAENOBUFS:
return "No buffer space available.";
case WSAENOPROTOOPT :
return "Bad protocol option. An unknown, invalid or unsupported option or level was specified.";
case WSAENOTCONN:
return "Socket is not connected.";
case WSAENOTSOCK:
return "Socket operation on nonsocket.";
case WSAEPFNOSUPPORT:
return "Protocol family not supported.";
case WSAEPROCLIM:
return "Too many processes.";
case WSAEPROTONOSUPPORT:
return "Protocol not supported.";
case WSAEPROTOTYPE:
return "Protocol wrong type for socket.";
case WSAESHUTDOWN:
return "Cannot send after socket shutdown.";
case WSAESOCKTNOSUPPORT :
return "Socket type not supported.";
case WSAETIMEDOUT:
return "Connection timed out.";
case WSAEWOULDBLOCK:
return "Resource temporarily unavailable.";
case WSAHOST_NOT_FOUND:
return "Host not found";
/*case WSAINVALIDPROCTABLE:
return "Invalid procedure table from service provider. ";
case WSAINVALIDPROVIDER :
return "Invalid service provider version number."; */
case WSANOTINITIALISED:
return "Successful WSAStartup not yet performed.";
case WSANO_DATA:
return "Valid name, no data record of requested type.";
case WSANO_RECOVERY:
return "This is a nonrecoverable error.";
/*case WSAPROVIDERFAILEDINIT:
return "Unable to initialize a service provider."; */
case WSASYSNOTREADY:
return "Network subsystem is unavailable.";
case WSATRY_AGAIN:
return "Nonauthoritative host not found.";
case WSAVERNOTSUPPORTED:
return "Winsock.dll version out of range.";
case WSAEDISCON:
return "Graceful shutdown in progress.";
#ifdef RV_WINSOCK_2
case WSA_INVALID_HANDLE:
return "Specified event object handle is invalid.";
case WSA_INVALID_PARAMETER:
return "One or more parameters are invalid";
case WSA_IO_INCOMPLETE:
return "Overlapped I/O event object not in signaled state.";
case WSA_IO_PENDING:
return "Overlapped operations will complete later.";
case WSA_NOT_ENOUGH_MEMORY :
return "Insufficient memory available.";
case WSASYSCALLFAILURE:
return "System call failure.";
case WSA_OPERATION_ABORTED:
return "Overlapped operation aborted.";
case WSATYPE_NOT_FOUND:
return "Class type not found.";
#endif
default:
return unknownErrorText;
}
#elif defined(RV_OS_REDHAT) || defined(RV_OS_SOLARIS) || defined(RV_OS_TRU64) || defined(RV_OS_HPUX)
static char unknownErrorText[] = "Unknown error type.";
char *errorStringPtr;
int oldErrno = errno;
errno = 0;
errorStringPtr = strerror(errorno);
if(errorStringPtr == NULL)
errorStringPtr = unknownErrorText;
if(errno == EINVAL) /* for Unix 98 */
errorStringPtr = unknownErrorText;
errno = oldErrno;
return errorStringPtr;
#else
return notImplementedErrorText;
#endif
#else
return notImplementedErrorText;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -