Add Socket Libraries.
Add Posix functions for porting compatibility. Fix compliance issues with ISO/IEC 9899:199409 New Functions: setenv(), fparseln(), GetFileNameFromPath(), rename(), realpath(), setprogname(), getprogname(), strlcat(), strlcpy(), strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(), mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(), writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(), bcopy(), git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
115
StdLib/BsdSocketLib/BsdSocketLib.inf
Normal file
115
StdLib/BsdSocketLib/BsdSocketLib.inf
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
#/** @file
|
||||||
|
# Component description file for the socket library.
|
||||||
|
#
|
||||||
|
# This module implements the socket library.
|
||||||
|
# Copyright (c) 2011, Intel Corporation
|
||||||
|
#
|
||||||
|
# All rights reserved. This program and the accompanying materials
|
||||||
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
# which accompanies this distribution. The full text of the license may be found at
|
||||||
|
# http://opensource.org/licenses/bsd-license.php
|
||||||
|
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
#
|
||||||
|
#**/
|
||||||
|
|
||||||
|
[Defines]
|
||||||
|
INF_VERSION = 0x00010005
|
||||||
|
BASE_NAME = BsdSocketLib
|
||||||
|
FILE_GUID = E7A79769-DD6E-48f7-B90B-D4C510AC1741
|
||||||
|
MODULE_TYPE = BASE
|
||||||
|
VERSION_STRING = 1.0
|
||||||
|
LIBRARY_CLASS = BsdSocketLib
|
||||||
|
|
||||||
|
#
|
||||||
|
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||||
|
#
|
||||||
|
|
||||||
|
[Sources.common]
|
||||||
|
accept.c
|
||||||
|
base64.c
|
||||||
|
bind.c
|
||||||
|
close.c
|
||||||
|
connect.c
|
||||||
|
gethostbydns.c
|
||||||
|
gethostbyht.c
|
||||||
|
gethostbynis.c
|
||||||
|
gethostname.c
|
||||||
|
gethostnamadr.c
|
||||||
|
gethostbynis.c
|
||||||
|
getnetbydns.c
|
||||||
|
getnetbynis.c
|
||||||
|
getnetbyht.c
|
||||||
|
getnetnamadr.c
|
||||||
|
getpeername.c
|
||||||
|
getprotoent.c
|
||||||
|
getprotoname.c
|
||||||
|
getproto.c
|
||||||
|
getservbyname.c
|
||||||
|
getservbyport.c
|
||||||
|
getservent.c
|
||||||
|
getsockname.c
|
||||||
|
getsockopt.c
|
||||||
|
herror.c
|
||||||
|
# inet_addr.c
|
||||||
|
# inet_lnaof.c
|
||||||
|
# inet_makeaddr.c
|
||||||
|
inet_net_ntop.c
|
||||||
|
inet_net_pton.c
|
||||||
|
inet_neta.c
|
||||||
|
# inet_netof.c
|
||||||
|
# inet_network.c
|
||||||
|
# inet_ntoa.c
|
||||||
|
# inet_ntop.c
|
||||||
|
inet_pton.c
|
||||||
|
listen.c
|
||||||
|
map_v4v6.c
|
||||||
|
ns_addr.c
|
||||||
|
ns_name.c
|
||||||
|
ns_netint.c
|
||||||
|
ns_ntoa.c
|
||||||
|
ns_parse.c
|
||||||
|
ns_print.c
|
||||||
|
ns_ttl.c
|
||||||
|
nsap_addr.c
|
||||||
|
poll.c
|
||||||
|
read.c
|
||||||
|
recv.c
|
||||||
|
recvfrom.c
|
||||||
|
res_comp.c
|
||||||
|
res_config.h
|
||||||
|
res_data.c
|
||||||
|
res_debug.c
|
||||||
|
res_init.c
|
||||||
|
res_mkquery.c
|
||||||
|
res_mkupdate.c
|
||||||
|
res_query.c
|
||||||
|
res_send.c
|
||||||
|
res_update.c
|
||||||
|
send.c
|
||||||
|
sendto.c
|
||||||
|
sethostname.c
|
||||||
|
setsockopt.c
|
||||||
|
shutdown.c
|
||||||
|
socket.c
|
||||||
|
SocketInternals.h
|
||||||
|
write.c
|
||||||
|
|
||||||
|
[Packages]
|
||||||
|
StdLib/StdLib.dec
|
||||||
|
StdLibPrivateInternalFiles/DoNotUse.dec
|
||||||
|
MdePkg/MdePkg.dec
|
||||||
|
MdeModulePkg/MdeModulePkg.dec
|
||||||
|
# SocketPkg/SocketPkg.dec
|
||||||
|
|
||||||
|
[LibraryClasses]
|
||||||
|
BaseLib
|
||||||
|
BaseMemoryLib
|
||||||
|
DebugLib
|
||||||
|
DevUtility
|
||||||
|
UefiBootServicesTableLib
|
||||||
|
UefiLib
|
||||||
|
|
||||||
|
[Protocols]
|
||||||
|
gEfiSocketServiceBindingProtocolGuid
|
||||||
|
gEfiSocketProtocolGuid
|
190
StdLib/BsdSocketLib/SocketInternals.h
Normal file
190
StdLib/BsdSocketLib/SocketInternals.h
Normal file
@ -0,0 +1,190 @@
|
|||||||
|
/** @file
|
||||||
|
Definitions for the socket library.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef _SOCKET_INTERNALS_H_
|
||||||
|
#define _SOCKET_INTERNALS_H_
|
||||||
|
|
||||||
|
#include <Uefi.h>
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// The following private files are required to support file descriptors
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <kfile.h>
|
||||||
|
#include <MainData.h>
|
||||||
|
|
||||||
|
#include <efi/SysEfi.h>
|
||||||
|
|
||||||
|
//
|
||||||
|
// End of private files
|
||||||
|
//
|
||||||
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
|
#include <Library/UefiLib.h>
|
||||||
|
|
||||||
|
#include <Protocol/EfiSocket.h>
|
||||||
|
#include <Protocol/ServiceBinding.h>
|
||||||
|
|
||||||
|
#include <sys/errno.h>
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#include <sys/EfiSysCall.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Support Routines
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Translate from the socket file descriptor to the socket protocol.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] ppDescriptor Address to receive the descriptor structure
|
||||||
|
address for the file
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@returns A pointer to the socket protocol structure or NULL if
|
||||||
|
an invalid file descriptor was passed in.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_SOCKET_PROTOCOL *
|
||||||
|
BslFdToSocketProtocol (
|
||||||
|
int s,
|
||||||
|
struct __filedes ** ppDescriptor,
|
||||||
|
int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Close the socket
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
|
||||||
|
@returns This routine returns 0 upon success and -1 upon failure.
|
||||||
|
In the case of failure, errno contains more information.
|
||||||
|
|
||||||
|
**/
|
||||||
|
INT32
|
||||||
|
BslSocketClose (
|
||||||
|
struct __filedes * pDescriptor
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Worker routine to close the socket.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Socket protocol structure address
|
||||||
|
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Successfully closed the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
BslSocketCloseWork (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Poll the socket for activity
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
|
||||||
|
@param [in] Events Mask of events to detect
|
||||||
|
|
||||||
|
@returns Detected events for the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
short
|
||||||
|
BslSocketPoll (
|
||||||
|
IN struct __filedes * pDescriptor,
|
||||||
|
IN short Events
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Build a file descriptor for a socket.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Socket protocol structure address
|
||||||
|
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@returns The file descriptor for the socket or -1 if an error occurs.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
BslSocketProtocolToFd (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Read support routine for sockets
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
@param [in] pOffset File offset
|
||||||
|
@param [in] LengthInBytes Number of bytes to read
|
||||||
|
@param [in] pBuffer Address of the buffer to receive the data
|
||||||
|
|
||||||
|
@returns The number of bytes read or -1 if an error occurs.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
BslSocketRead (
|
||||||
|
struct __filedes *pDescriptor,
|
||||||
|
off_t * pOffset,
|
||||||
|
size_t LengthInBytes,
|
||||||
|
void * pBuffer
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write support routine for sockets
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
@param [in] pOffset File offset
|
||||||
|
@param [in] LengthInBytes Number of bytes to write
|
||||||
|
@param [in] pBuffer Address of the data
|
||||||
|
|
||||||
|
@returns The number of bytes written or -1 if an error occurs.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
BslSocketWrite (
|
||||||
|
struct __filedes *pDescriptor,
|
||||||
|
off_t * pOffset,
|
||||||
|
size_t LengthInBytes,
|
||||||
|
const void * pBuffer
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Validate the socket's file descriptor
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor for the file
|
||||||
|
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@returns A pointer to the socket protocol structure or NULL if
|
||||||
|
an invalid file descriptor was passed in.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_SOCKET_PROTOCOL *
|
||||||
|
BslValidateSocketFd (
|
||||||
|
struct __filedes * pDescriptor,
|
||||||
|
int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif // _SOCKET_INTERNALS_H_
|
42
StdLib/BsdSocketLib/Socklib_internals.h
Normal file
42
StdLib/BsdSocketLib/Socklib_internals.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/** @file
|
||||||
|
Definitions for the socket library functions that are used internally.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef _SOCKLIB_INTERNALS_H_
|
||||||
|
#define _SOCKLIB_INTERNALS_H_
|
||||||
|
|
||||||
|
void _sethosthtent(int);
|
||||||
|
void _endhosthtent(void);
|
||||||
|
void _sethostdnsent(int);
|
||||||
|
void _endhostdnsent(void);
|
||||||
|
void _setnethtent(int);
|
||||||
|
void _endnethtent(void);
|
||||||
|
void _setnetdnsent(int);
|
||||||
|
void _endnetdnsent(void);
|
||||||
|
|
||||||
|
struct hostent * _gethostbyhtname(const char *, int);
|
||||||
|
struct hostent * _gethostbydnsname(const char *, int);
|
||||||
|
struct hostent * _gethostbynisname(const char *, int);
|
||||||
|
struct hostent * _gethostbyhtaddr(const char *, int, int);
|
||||||
|
struct hostent * _gethostbydnsaddr(const char *, int, int);
|
||||||
|
struct hostent * _gethostbynisaddr(const char *, int, int);
|
||||||
|
struct netent * _getnetbyhtname(const char *);
|
||||||
|
struct netent * _getnetbydnsname(const char *);
|
||||||
|
struct netent * _getnetbynisname(const char *);
|
||||||
|
struct netent * _getnetbyhtaddr(unsigned long, int);
|
||||||
|
struct netent * _getnetbydnsaddr(unsigned long, int);
|
||||||
|
struct netent * _getnetbynisaddr(unsigned long, int);
|
||||||
|
void _map_v4v6_address(const char *src, char *dst);
|
||||||
|
void _map_v4v6_hostent(struct hostent *hp, char **bp, int *len);
|
||||||
|
#endif
|
||||||
|
|
157
StdLib/BsdSocketLib/accept.c
Normal file
157
StdLib/BsdSocketLib/accept.c
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the accept API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Worker routine for ::Accept and ::AcceptNB
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] bBlocking TRUE if this is a blocking call
|
||||||
|
@param [in] address Address of a buffer to receive the remote network address.
|
||||||
|
|
||||||
|
@param [in, out] address_len Address of a buffer containing the Length in bytes
|
||||||
|
of the remote network address buffer. Upon return,
|
||||||
|
contains the length of the remote network address.
|
||||||
|
|
||||||
|
@returns ::accept returns zero if successful and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
AcceptWork (
|
||||||
|
int s,
|
||||||
|
BOOLEAN bBlocking,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
INT32 NewSocketFd;
|
||||||
|
struct __filedes * pDescriptor;
|
||||||
|
EFI_SOCKET_PROTOCOL * pNewSocket;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
NewSocketFd = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s,
|
||||||
|
&pDescriptor,
|
||||||
|
&errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// TODO: Update bBlocking by anding with check for NON_BLOCKING
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Attempt to accept a new network connection
|
||||||
|
//
|
||||||
|
do {
|
||||||
|
Status = pSocketProtocol->pfnAccept ( pSocketProtocol,
|
||||||
|
address,
|
||||||
|
address_len,
|
||||||
|
&pNewSocket,
|
||||||
|
&errno );
|
||||||
|
} while ( bBlocking && ( EFI_NOT_READY == Status ));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Convert the protocol to a socket
|
||||||
|
//
|
||||||
|
NewSocketFd = BslSocketProtocolToFd ( pNewSocket, &errno );
|
||||||
|
if ( -1 == NewSocketFd ) {
|
||||||
|
//
|
||||||
|
// Close the socket
|
||||||
|
//
|
||||||
|
BslSocketCloseWork ( pNewSocket, NULL );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the new socket file descriptor
|
||||||
|
//
|
||||||
|
return NewSocketFd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Accept a network connection.
|
||||||
|
|
||||||
|
The ::accept routine waits for a network connection to the socket.
|
||||||
|
It is able to return the remote network address to the caller if
|
||||||
|
requested. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/accept.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] address Address of a buffer to receive the remote network address.
|
||||||
|
|
||||||
|
@param [in, out] address_len Address of a buffer containing the Length in bytes
|
||||||
|
of the remote network address buffer. Upon return,
|
||||||
|
contains the length of the remote network address.
|
||||||
|
|
||||||
|
@returns ::accept returns zero if successful and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
accept (
|
||||||
|
int s,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Wait for the accept call to complete
|
||||||
|
//
|
||||||
|
return AcceptWork ( s, TRUE, address, address_len );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Non blocking version of accept.
|
||||||
|
|
||||||
|
See ::accept
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] address Address of a buffer to receive the remote network address.
|
||||||
|
|
||||||
|
@param [in, out] address_len Address of a buffer containing the Length in bytes
|
||||||
|
of the remote network address buffer. Upon return,
|
||||||
|
contains the length of the remote network address.
|
||||||
|
|
||||||
|
@returns This routine returns zero if successful and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
AcceptNB (
|
||||||
|
int s,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Attempt to accept a network connection
|
||||||
|
//
|
||||||
|
return AcceptWork ( s, FALSE, address, address_len );
|
||||||
|
}
|
357
StdLib/BsdSocketLib/base64.c
Normal file
357
StdLib/BsdSocketLib/base64.c
Normal file
@ -0,0 +1,357 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996, 1998 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1995 by International Business Machines, Inc.
|
||||||
|
*
|
||||||
|
* International Business Machines, Inc. (hereinafter called IBM) grants
|
||||||
|
* permission under its copyrights to use, copy, modify, and distribute this
|
||||||
|
* Software with or without fee, provided that the above copyright notice and
|
||||||
|
* all paragraphs of this notice appear in all copies, and that the name of IBM
|
||||||
|
* not be used in connection with the marketing of any product incorporating
|
||||||
|
* the Software or modifications thereof, without specific, written prior
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* To the extent it has a right to do so, IBM grants an immunity from suit
|
||||||
|
* under its patents, if any, for the use, sale or manufacture of products to
|
||||||
|
* the extent that such products are used for performing Domain Name System
|
||||||
|
* dynamic updates in TCP/IP networks by means of the Software. No immunity is
|
||||||
|
* granted for any product per se or for any other function of any product.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
|
||||||
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
|
||||||
|
* DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
|
||||||
|
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(LINT) && !defined(CODECENTER)
|
||||||
|
static char rcsid[] = "$Id: base64.c,v 1.1.1.1 2003/11/19 01:51:25 kyu3 Exp $";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define Assert(Cond) if (!(Cond)) abort()
|
||||||
|
|
||||||
|
static const char Base64[] =
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
static const char Pad64 = '=';
|
||||||
|
|
||||||
|
/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
|
||||||
|
The following encoding technique is taken from RFC 1521 by Borenstein
|
||||||
|
and Freed. It is reproduced here in a slightly edited form for
|
||||||
|
convenience.
|
||||||
|
|
||||||
|
A 65-character subset of US-ASCII is used, enabling 6 bits to be
|
||||||
|
represented per printable character. (The extra 65th character, "=",
|
||||||
|
is used to signify a special processing function.)
|
||||||
|
|
||||||
|
The encoding process represents 24-bit groups of input bits as output
|
||||||
|
strings of 4 encoded characters. Proceeding from left to right, a
|
||||||
|
24-bit input group is formed by concatenating 3 8-bit input groups.
|
||||||
|
These 24 bits are then treated as 4 concatenated 6-bit groups, each
|
||||||
|
of which is translated into a single digit in the base64 alphabet.
|
||||||
|
|
||||||
|
Each 6-bit group is used as an index into an array of 64 printable
|
||||||
|
characters. The character referenced by the index is placed in the
|
||||||
|
output string.
|
||||||
|
|
||||||
|
Table 1: The Base64 Alphabet
|
||||||
|
|
||||||
|
Value Encoding Value Encoding Value Encoding Value Encoding
|
||||||
|
0 A 17 R 34 i 51 z
|
||||||
|
1 B 18 S 35 j 52 0
|
||||||
|
2 C 19 T 36 k 53 1
|
||||||
|
3 D 20 U 37 l 54 2
|
||||||
|
4 E 21 V 38 m 55 3
|
||||||
|
5 F 22 W 39 n 56 4
|
||||||
|
6 G 23 X 40 o 57 5
|
||||||
|
7 H 24 Y 41 p 58 6
|
||||||
|
8 I 25 Z 42 q 59 7
|
||||||
|
9 J 26 a 43 r 60 8
|
||||||
|
10 K 27 b 44 s 61 9
|
||||||
|
11 L 28 c 45 t 62 +
|
||||||
|
12 M 29 d 46 u 63 /
|
||||||
|
13 N 30 e 47 v
|
||||||
|
14 O 31 f 48 w (pad) =
|
||||||
|
15 P 32 g 49 x
|
||||||
|
16 Q 33 h 50 y
|
||||||
|
|
||||||
|
Special processing is performed if fewer than 24 bits are available
|
||||||
|
at the end of the data being encoded. A full encoding quantum is
|
||||||
|
always completed at the end of a quantity. When fewer than 24 input
|
||||||
|
bits are available in an input group, zero bits are added (on the
|
||||||
|
right) to form an integral number of 6-bit groups. Padding at the
|
||||||
|
end of the data is performed using the '=' character.
|
||||||
|
|
||||||
|
Since all base64 input is an integral number of octets, only the
|
||||||
|
-------------------------------------------------
|
||||||
|
following cases can arise:
|
||||||
|
|
||||||
|
(1) the final quantum of encoding input is an integral
|
||||||
|
multiple of 24 bits; here, the final unit of encoded
|
||||||
|
output will be an integral multiple of 4 characters
|
||||||
|
with no "=" padding,
|
||||||
|
(2) the final quantum of encoding input is exactly 8 bits;
|
||||||
|
here, the final unit of encoded output will be two
|
||||||
|
characters followed by two "=" padding characters, or
|
||||||
|
(3) the final quantum of encoding input is exactly 16 bits;
|
||||||
|
here, the final unit of encoded output will be three
|
||||||
|
characters followed by one "=" padding character.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
|
||||||
|
size_t datalength = 0;
|
||||||
|
u_char input[3];
|
||||||
|
u_char output[4];
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
while (2 < srclength) {
|
||||||
|
input[0] = *src++;
|
||||||
|
input[1] = *src++;
|
||||||
|
input[2] = *src++;
|
||||||
|
srclength -= 3;
|
||||||
|
|
||||||
|
output[0] = input[0] >> 2;
|
||||||
|
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
|
||||||
|
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
|
||||||
|
output[3] = input[2] & 0x3f;
|
||||||
|
Assert(output[0] < 64);
|
||||||
|
Assert(output[1] < 64);
|
||||||
|
Assert(output[2] < 64);
|
||||||
|
Assert(output[3] < 64);
|
||||||
|
|
||||||
|
if (datalength + 4 > targsize)
|
||||||
|
return (-1);
|
||||||
|
target[datalength++] = Base64[output[0]];
|
||||||
|
target[datalength++] = Base64[output[1]];
|
||||||
|
target[datalength++] = Base64[output[2]];
|
||||||
|
target[datalength++] = Base64[output[3]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now we worry about padding. */
|
||||||
|
if (0 != srclength) {
|
||||||
|
/* Get what's left. */
|
||||||
|
input[0] = input[1] = input[2] = '\0';
|
||||||
|
for (i = 0; i < srclength; i++)
|
||||||
|
input[i] = *src++;
|
||||||
|
|
||||||
|
output[0] = input[0] >> 2;
|
||||||
|
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
|
||||||
|
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
|
||||||
|
Assert(output[0] < 64);
|
||||||
|
Assert(output[1] < 64);
|
||||||
|
Assert(output[2] < 64);
|
||||||
|
|
||||||
|
if (datalength + 4 > targsize)
|
||||||
|
return (-1);
|
||||||
|
target[datalength++] = Base64[output[0]];
|
||||||
|
target[datalength++] = Base64[output[1]];
|
||||||
|
if (srclength == 1)
|
||||||
|
target[datalength++] = Pad64;
|
||||||
|
else
|
||||||
|
target[datalength++] = Base64[output[2]];
|
||||||
|
target[datalength++] = Pad64;
|
||||||
|
}
|
||||||
|
if (datalength >= targsize)
|
||||||
|
return (-1);
|
||||||
|
target[datalength] = '\0'; /* Returned value doesn't count \0. */
|
||||||
|
return ((int)datalength);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* skips all whitespace anywhere.
|
||||||
|
converts characters, four at a time, starting at (or after)
|
||||||
|
src from base - 64 numbers into three 8 bit bytes in the target area.
|
||||||
|
it returns the number of data bytes stored at the target, or -1 on error.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
b64_pton(
|
||||||
|
char const *src,
|
||||||
|
u_char *target,
|
||||||
|
size_t targsize
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int tarindex, state, ch;
|
||||||
|
char *pos;
|
||||||
|
|
||||||
|
state = 0;
|
||||||
|
tarindex = 0;
|
||||||
|
|
||||||
|
while ((ch = *src++) != '\0') {
|
||||||
|
if (isspace(ch)) /* Skip whitespace anywhere. */
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ch == Pad64)
|
||||||
|
break;
|
||||||
|
|
||||||
|
pos = strchr(Base64, ch);
|
||||||
|
if (pos == 0) /* A non-base64 character. */
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case 0:
|
||||||
|
if (target) {
|
||||||
|
if ((size_t)tarindex >= targsize)
|
||||||
|
return (-1);
|
||||||
|
target[tarindex] = (u_char)((pos - Base64) << 2);
|
||||||
|
}
|
||||||
|
state = 1;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
if (target) {
|
||||||
|
if ((size_t)tarindex + 1 >= targsize)
|
||||||
|
return (-1);
|
||||||
|
target[tarindex] |= (u_char)((pos - Base64) >> 4);
|
||||||
|
target[tarindex+1] = (u_char)(((pos - Base64) & 0x0f)
|
||||||
|
<< 4) ;
|
||||||
|
}
|
||||||
|
tarindex++;
|
||||||
|
state = 2;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (target) {
|
||||||
|
if ((size_t)tarindex + 1 >= targsize)
|
||||||
|
return (-1);
|
||||||
|
target[tarindex] |= (u_char)((pos - Base64) >> 2);
|
||||||
|
target[tarindex+1] = (u_char)(((pos - Base64) & 0x03)
|
||||||
|
<< 6);
|
||||||
|
}
|
||||||
|
tarindex++;
|
||||||
|
state = 3;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (target) {
|
||||||
|
if ((size_t)tarindex >= targsize)
|
||||||
|
return (-1);
|
||||||
|
target[tarindex] |= (u_char)(pos - Base64);
|
||||||
|
}
|
||||||
|
tarindex++;
|
||||||
|
state = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We are done decoding Base-64 chars. Let's see if we ended
|
||||||
|
* on a byte boundary, and/or with erroneous trailing characters.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (ch == Pad64) { /* We got a pad char. */
|
||||||
|
ch = *src++; /* Skip it, get next. */
|
||||||
|
switch (state) {
|
||||||
|
case 0: /* Invalid = in first position */
|
||||||
|
case 1: /* Invalid = in second position */
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
case 2: /* Valid, means one byte of info */
|
||||||
|
/* Skip any number of spaces. */
|
||||||
|
for ((void)NULL; ch != '\0'; ch = *src++)
|
||||||
|
if (!isspace(ch))
|
||||||
|
break;
|
||||||
|
/* Make sure there is another trailing = sign. */
|
||||||
|
if (ch != Pad64)
|
||||||
|
return (-1);
|
||||||
|
ch = *src++; /* Skip the = */
|
||||||
|
/* Fall through to "single trailing =" case. */
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
|
case 3: /* Valid, means two bytes of info */
|
||||||
|
/*
|
||||||
|
* We know this char is an =. Is there anything but
|
||||||
|
* whitespace after it?
|
||||||
|
*/
|
||||||
|
for ((void)NULL; ch != '\0'; ch = *src++)
|
||||||
|
if (!isspace(ch))
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Now make sure for cases 2 and 3 that the "extra"
|
||||||
|
* bits that slopped past the last full byte were
|
||||||
|
* zeros. If we don't check them, they become a
|
||||||
|
* subliminal channel.
|
||||||
|
*/
|
||||||
|
if (target && target[tarindex] != 0)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* We ended by seeing the end of the string. Make sure we
|
||||||
|
* have no partial bytes lying around.
|
||||||
|
*/
|
||||||
|
if (state != 0)
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (tarindex);
|
||||||
|
}
|
72
StdLib/BsdSocketLib/bind.c
Normal file
72
StdLib/BsdSocketLib/bind.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the bind API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Bind a name to a socket.
|
||||||
|
|
||||||
|
The ::bind routine connects a name to a socket on the local machine. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
|
||||||
|
documentation for the bind routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] name Address of a sockaddr structure that contains the
|
||||||
|
connection point on the local machine. An IPv4 address
|
||||||
|
of INADDR_ANY specifies that the connection is made to
|
||||||
|
all of the network stacks on the platform. Specifying a
|
||||||
|
specific IPv4 address restricts the connection to the
|
||||||
|
network stack supporting that address. Specifying zero
|
||||||
|
for the port causes the network layer to assign a port
|
||||||
|
number from the dynamic range. Specifying a specific
|
||||||
|
port number causes the network layer to use that port.
|
||||||
|
|
||||||
|
@param [in] namelen Specifies the length in bytes of the sockaddr structure.
|
||||||
|
|
||||||
|
@returns The bind routine returns zero (0) if successful and -1 upon failure.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
bind (
|
||||||
|
IN int s,
|
||||||
|
IN const struct sockaddr * name,
|
||||||
|
IN socklen_t namelen
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int BindStatus;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Bind the socket
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnBind ( pSocketProtocol,
|
||||||
|
name,
|
||||||
|
namelen,
|
||||||
|
&errno );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation stauts
|
||||||
|
//
|
||||||
|
BindStatus = ( 0 == errno ) ? 0 : -1;
|
||||||
|
return BindStatus;
|
||||||
|
}
|
116
StdLib/BsdSocketLib/close.c
Normal file
116
StdLib/BsdSocketLib/close.c
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the close API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Worker routine to close the socket.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Socket protocol structure address
|
||||||
|
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Successfully closed the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
BslSocketCloseWork (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Start closing the socket
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnCloseStart ( pSocketProtocol,
|
||||||
|
FALSE,
|
||||||
|
pErrno );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Wait for the socket to close or an error
|
||||||
|
//
|
||||||
|
while ( EFI_NOT_READY == Status ) {
|
||||||
|
Status = pSocketProtocol->pfnClosePoll ( pSocketProtocol,
|
||||||
|
pErrno );
|
||||||
|
}
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Locate the socket protocol
|
||||||
|
//
|
||||||
|
Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,
|
||||||
|
NULL,
|
||||||
|
(VOID **) &pServiceBinding );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Release the handle
|
||||||
|
//
|
||||||
|
Status = pServiceBinding->DestroyChild ( pServiceBinding,
|
||||||
|
pSocketProtocol->SocketHandle );
|
||||||
|
}
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
*pErrno = EIO;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR,
|
||||||
|
"ERROR - Failed to close the socket: %r\r\n",
|
||||||
|
Status ));
|
||||||
|
*pErrno = EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the close status
|
||||||
|
//
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Close the socket
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
|
||||||
|
@returns This routine returns 0 upon success and -1 upon failure.
|
||||||
|
In the case of failure, errno contains more information.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
BslSocketClose (
|
||||||
|
struct __filedes * pDescriptor
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int CloseStatus;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the socket protocol
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslValidateSocketFd ( pDescriptor, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Close the socket
|
||||||
|
//
|
||||||
|
BslSocketCloseWork ( pSocketProtocol, &errno );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the close status
|
||||||
|
//
|
||||||
|
CloseStatus = ( errno == 0 ) ? 0 : -1;
|
||||||
|
return CloseStatus;
|
||||||
|
}
|
94
StdLib/BsdSocketLib/connect.c
Normal file
94
StdLib/BsdSocketLib/connect.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the connect API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to a remote system via the network.
|
||||||
|
|
||||||
|
The ::connect routine attempts to establish a connection to a
|
||||||
|
socket on the local or remote system using the specified address.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
There are three states associated with a connection:
|
||||||
|
<ul>
|
||||||
|
<li>Not connected</li>
|
||||||
|
<li>Connection in progress</li>
|
||||||
|
<li>Connected</li>
|
||||||
|
</ul>
|
||||||
|
In the "Not connected" state, calls to ::connect start the connection
|
||||||
|
processing and update the state to "Connection in progress". During
|
||||||
|
the "Connection in progress" state, connect polls for connection completion
|
||||||
|
and moves the state to "Connected" after the connection is established.
|
||||||
|
Note that these states are only visible when the file descriptor is marked
|
||||||
|
with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
|
||||||
|
completes and may be used by poll or select as an indicator to call
|
||||||
|
connect again.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] address Network address of the remote system
|
||||||
|
|
||||||
|
@param [in] address_len Length of the remote network address
|
||||||
|
|
||||||
|
@returns ::connect returns zero if successful and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
connect (
|
||||||
|
int s,
|
||||||
|
const struct sockaddr * address,
|
||||||
|
socklen_t address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
BOOLEAN bBlocking;
|
||||||
|
int ConnectStatus;
|
||||||
|
struct __filedes * pDescriptor;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s,
|
||||||
|
&pDescriptor,
|
||||||
|
&errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// TODO: Check for NON_BLOCKING
|
||||||
|
//
|
||||||
|
bBlocking = TRUE;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Attempt to connect to a remote system
|
||||||
|
//
|
||||||
|
do {
|
||||||
|
errno = 0;
|
||||||
|
Status = pSocketProtocol->pfnConnect ( pSocketProtocol,
|
||||||
|
address,
|
||||||
|
address_len,
|
||||||
|
&errno );
|
||||||
|
} while ( bBlocking && ( EFI_NOT_READY == Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the new socket file descriptor
|
||||||
|
//
|
||||||
|
ConnectStatus = (0 == errno) ? 0 : -1;
|
||||||
|
return ConnectStatus;
|
||||||
|
}
|
18
StdLib/BsdSocketLib/errno.c
Normal file
18
StdLib/BsdSocketLib/errno.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/** @file
|
||||||
|
errno variable
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <sys/errno.h>
|
||||||
|
|
||||||
|
|
||||||
|
int errno;
|
814
StdLib/BsdSocketLib/gethostbydns.c
Normal file
814
StdLib/BsdSocketLib/gethostbydns.c
Normal file
@ -0,0 +1,814 @@
|
|||||||
|
/*
|
||||||
|
* ++Copyright++ 1985, 1988, 1993
|
||||||
|
* -
|
||||||
|
* Copyright (c) 1985, 1988, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
* -
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
* -
|
||||||
|
* --Copyright--
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.23 1998/04/07 04:59:46 vixie Exp $";
|
||||||
|
static char rcsid[] = "$Id: gethostbydns.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
#include <syslog.h>
|
||||||
|
#else
|
||||||
|
#include <stdlib.h>
|
||||||
|
u_int32_t _getlong(const u_char *src);
|
||||||
|
u_int16_t _getshort(const u_char *src);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
#include "Socklib_internals.h"
|
||||||
|
|
||||||
|
#define SPRINTF(x) ((size_t)sprintf x)
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
#define MAXADDRS 35
|
||||||
|
|
||||||
|
static const char AskedForGot[] =
|
||||||
|
"gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
|
||||||
|
|
||||||
|
static char *h_addr_ptrs[MAXADDRS + 1];
|
||||||
|
|
||||||
|
static struct hostent host;
|
||||||
|
static char *host_aliases[MAXALIASES];
|
||||||
|
static char hostbuf[8*1024];
|
||||||
|
static u_char host_addr[16]; /* IPv4 or IPv6 */
|
||||||
|
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
static void addrsort(char **, int);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if PACKETSZ > 1024
|
||||||
|
#define MAXPACKET PACKETSZ
|
||||||
|
#else
|
||||||
|
#define MAXPACKET 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
HEADER hdr;
|
||||||
|
u_char buf[MAXPACKET];
|
||||||
|
} querybuf;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
int32_t al;
|
||||||
|
char ac;
|
||||||
|
} align;
|
||||||
|
|
||||||
|
extern int h_errno;
|
||||||
|
int _dns_ttl_;
|
||||||
|
|
||||||
|
#ifdef DEBUG_RES
|
||||||
|
static void
|
||||||
|
dprintf(char *msg, int num)
|
||||||
|
{
|
||||||
|
if (_res.options & RES_DEBUG) {
|
||||||
|
int save = errno;
|
||||||
|
|
||||||
|
printf(msg, num);
|
||||||
|
errno = save;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# define dprintf(msg, num) /*nada*/
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOUNDED_INCR(x) \
|
||||||
|
do { \
|
||||||
|
cp += x; \
|
||||||
|
if (cp > eom) { \
|
||||||
|
h_errno = NO_RECOVERY; \
|
||||||
|
return (NULL); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define BOUNDS_CHECK(ptr, count) \
|
||||||
|
do { \
|
||||||
|
if ((ptr) + (count) > eom) { \
|
||||||
|
h_errno = NO_RECOVERY; \
|
||||||
|
return (NULL); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static struct hostent *
|
||||||
|
gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype)
|
||||||
|
{
|
||||||
|
register const HEADER *hp;
|
||||||
|
register const u_char *cp;
|
||||||
|
register int n;
|
||||||
|
const u_char *eom, *erdata;
|
||||||
|
char *bp, **ap, **hap;
|
||||||
|
int type, class, buflen, ancount, qdcount;
|
||||||
|
int haveanswer, had_error;
|
||||||
|
int toobig = 0;
|
||||||
|
char tbuf[MAXDNAME];
|
||||||
|
const char *tname;
|
||||||
|
int (*name_ok)(const char *);
|
||||||
|
|
||||||
|
tname = qname;
|
||||||
|
host.h_name = NULL;
|
||||||
|
eom = answer->buf + anslen;
|
||||||
|
switch (qtype) {
|
||||||
|
case T_A:
|
||||||
|
case T_AAAA:
|
||||||
|
name_ok = res_hnok;
|
||||||
|
break;
|
||||||
|
case T_PTR:
|
||||||
|
name_ok = res_dnok;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL); /* XXX should be abort(); */
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* find first satisfactory answer
|
||||||
|
*/
|
||||||
|
hp = &answer->hdr;
|
||||||
|
ancount = ntohs(hp->ancount);
|
||||||
|
qdcount = ntohs(hp->qdcount);
|
||||||
|
bp = hostbuf;
|
||||||
|
buflen = sizeof hostbuf;
|
||||||
|
cp = answer->buf;
|
||||||
|
BOUNDED_INCR(HFIXEDSZ);
|
||||||
|
if (qdcount != 1) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
n = dn_expand(answer->buf, eom, cp, bp, buflen);
|
||||||
|
if ((n < 0) || !(*name_ok)(bp)) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
BOUNDED_INCR(n + QFIXEDSZ);
|
||||||
|
if (qtype == T_A || qtype == T_AAAA) {
|
||||||
|
/* res_send() has already verified that the query name is the
|
||||||
|
* same as the one we sent; this just gets the expanded name
|
||||||
|
* (i.e., with the succeeding search-domain tacked on).
|
||||||
|
*/
|
||||||
|
n = (int)strlen(bp) + 1; /* for the \0 */
|
||||||
|
if (n >= MAXHOSTNAMELEN) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
host.h_name = bp;
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
/* The qname can be abbreviated, but h_name is now absolute. */
|
||||||
|
qname = host.h_name;
|
||||||
|
}
|
||||||
|
ap = host_aliases;
|
||||||
|
*ap = NULL;
|
||||||
|
host.h_aliases = host_aliases;
|
||||||
|
hap = h_addr_ptrs;
|
||||||
|
*hap = NULL;
|
||||||
|
host.h_addr_list = h_addr_ptrs;
|
||||||
|
haveanswer = 0;
|
||||||
|
had_error = 0;
|
||||||
|
_dns_ttl_ = -1;
|
||||||
|
while (ancount-- > 0 && cp < eom && !had_error) {
|
||||||
|
n = dn_expand(answer->buf, eom, cp, bp, buflen);
|
||||||
|
if ((n < 0) || !(*name_ok)(bp)) {
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cp += n; /* name */
|
||||||
|
BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
|
||||||
|
type = _getshort(cp);
|
||||||
|
cp += INT16SZ; /* type */
|
||||||
|
class = _getshort(cp);
|
||||||
|
cp += INT16SZ; /* class */
|
||||||
|
if (qtype == T_A && type == T_A)
|
||||||
|
_dns_ttl_ = _getlong(cp);
|
||||||
|
cp += INT32SZ; /* TTL */
|
||||||
|
n = _getshort(cp);
|
||||||
|
cp += INT16SZ; /* len */
|
||||||
|
BOUNDS_CHECK(cp, n);
|
||||||
|
erdata = cp + n;
|
||||||
|
if (class != C_IN) {
|
||||||
|
/* XXX - debug? syslog? */
|
||||||
|
cp += n;
|
||||||
|
continue; /* XXX - had_error++ ? */
|
||||||
|
}
|
||||||
|
if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
|
||||||
|
if (ap >= &host_aliases[MAXALIASES-1])
|
||||||
|
continue;
|
||||||
|
n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
|
||||||
|
if ((n < 0) || !(*name_ok)(tbuf)) {
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cp += n;
|
||||||
|
if (cp != erdata) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
/* Store alias. */
|
||||||
|
*ap++ = bp;
|
||||||
|
n = (int)strlen(bp) + 1; /* for the \0 */
|
||||||
|
if (n >= MAXHOSTNAMELEN) {
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
/* Get canonical name. */
|
||||||
|
n = (int)strlen(tbuf) + 1; /* for the \0 */
|
||||||
|
if (n > buflen || n >= MAXHOSTNAMELEN) {
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
strcpy(bp, tbuf);
|
||||||
|
host.h_name = bp;
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (qtype == T_PTR && type == T_CNAME) {
|
||||||
|
n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
|
||||||
|
if (n < 0 || !res_dnok(tbuf)) {
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
cp += n;
|
||||||
|
if (cp != erdata) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
/* Get canonical name. */
|
||||||
|
n = (int)strlen(tbuf) + 1; /* for the \0 */
|
||||||
|
if (n > buflen || n >= MAXHOSTNAMELEN) {
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
strcpy(bp, tbuf);
|
||||||
|
tname = bp;
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (type != qtype) {
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
syslog(LOG_NOTICE|LOG_AUTH,
|
||||||
|
"gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
|
||||||
|
qname, p_class(C_IN), p_type(qtype),
|
||||||
|
p_type(type));
|
||||||
|
#endif
|
||||||
|
cp += n;
|
||||||
|
continue; /* XXX - had_error++ ? */
|
||||||
|
}
|
||||||
|
switch (type) {
|
||||||
|
case T_PTR:
|
||||||
|
if (strcasecmp(tname, bp) != 0) {
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
syslog(LOG_NOTICE|LOG_AUTH,
|
||||||
|
AskedForGot, qname, bp);
|
||||||
|
#endif
|
||||||
|
cp += n;
|
||||||
|
continue; /* XXX - had_error++ ? */
|
||||||
|
}
|
||||||
|
n = dn_expand(answer->buf, eom, cp, bp, buflen);
|
||||||
|
if ((n < 0) || !res_hnok(bp)) {
|
||||||
|
had_error++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#if MULTI_PTRS_ARE_ALIASES
|
||||||
|
cp += n;
|
||||||
|
if (cp != erdata) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (!haveanswer)
|
||||||
|
host.h_name = bp;
|
||||||
|
else if (ap < &host_aliases[MAXALIASES-1])
|
||||||
|
*ap++ = bp;
|
||||||
|
else
|
||||||
|
n = -1;
|
||||||
|
if (n != -1) {
|
||||||
|
n = (int)strlen(bp) + 1; /* for the \0 */
|
||||||
|
if (n >= MAXHOSTNAMELEN) {
|
||||||
|
had_error++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#else
|
||||||
|
host.h_name = bp;
|
||||||
|
if (_res.options & RES_USE_INET6) {
|
||||||
|
n = strlen(bp) + 1; /* for the \0 */
|
||||||
|
if (n >= MAXHOSTNAMELEN) {
|
||||||
|
had_error++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
_map_v4v6_hostent(&host, &bp, &buflen);
|
||||||
|
}
|
||||||
|
h_errno = NETDB_SUCCESS;
|
||||||
|
return (&host);
|
||||||
|
#endif
|
||||||
|
case T_A:
|
||||||
|
case T_AAAA:
|
||||||
|
if (strcasecmp(host.h_name, bp) != 0) {
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
syslog(LOG_NOTICE|LOG_AUTH,
|
||||||
|
AskedForGot, host.h_name, bp);
|
||||||
|
#endif
|
||||||
|
cp += n;
|
||||||
|
continue; /* XXX - had_error++ ? */
|
||||||
|
}
|
||||||
|
if (n != host.h_length) {
|
||||||
|
cp += n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!haveanswer) {
|
||||||
|
register int nn;
|
||||||
|
|
||||||
|
host.h_name = bp;
|
||||||
|
nn = (int)strlen(bp) + 1; /* for the \0 */
|
||||||
|
bp += nn;
|
||||||
|
buflen -= nn;
|
||||||
|
}
|
||||||
|
|
||||||
|
bp += sizeof(align) - ((size_t)bp % sizeof(align));
|
||||||
|
|
||||||
|
if (bp + n >= &hostbuf[sizeof hostbuf]) {
|
||||||
|
dprintf("size (%d) too big\n", n);
|
||||||
|
had_error++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (hap >= &h_addr_ptrs[MAXADDRS-1]) {
|
||||||
|
if (!toobig++)
|
||||||
|
dprintf("Too many addresses (%d)\n",
|
||||||
|
MAXADDRS);
|
||||||
|
cp += n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*hap++ = bp;
|
||||||
|
bcopy(cp, bp, n);
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
cp += n;
|
||||||
|
if (cp != erdata) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
dprintf("Impossible condition (type=%d)\n", type);
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
/* BIND has abort() here, too risky on bad data */
|
||||||
|
}
|
||||||
|
if (!had_error)
|
||||||
|
haveanswer++;
|
||||||
|
}
|
||||||
|
if (haveanswer) {
|
||||||
|
*ap = NULL;
|
||||||
|
*hap = NULL;
|
||||||
|
# if defined(RESOLVSORT)
|
||||||
|
/*
|
||||||
|
* Note: we sort even if host can take only one address
|
||||||
|
* in its return structures - should give it the "best"
|
||||||
|
* address in that case, not some random one
|
||||||
|
*/
|
||||||
|
if (_res.nsort && haveanswer > 1 && qtype == T_A)
|
||||||
|
addrsort(h_addr_ptrs, haveanswer);
|
||||||
|
# endif /*RESOLVSORT*/
|
||||||
|
if (!host.h_name) {
|
||||||
|
n = (int)strlen(qname) + 1; /* for the \0 */
|
||||||
|
if (n > buflen || n >= MAXHOSTNAMELEN)
|
||||||
|
goto no_recovery;
|
||||||
|
strcpy(bp, qname);
|
||||||
|
host.h_name = bp;
|
||||||
|
bp += n;
|
||||||
|
buflen -= n;
|
||||||
|
}
|
||||||
|
if (_res.options & RES_USE_INET6)
|
||||||
|
_map_v4v6_hostent(&host, &bp, &buflen);
|
||||||
|
h_errno = NETDB_SUCCESS;
|
||||||
|
return (&host);
|
||||||
|
}
|
||||||
|
no_recovery:
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
__dns_getanswer(const char *answer, int anslen, const char *qname, int qtype)
|
||||||
|
{
|
||||||
|
switch(qtype) {
|
||||||
|
case T_AAAA:
|
||||||
|
host.h_addrtype = AF_INET6;
|
||||||
|
host.h_length = IN6ADDRSZ;
|
||||||
|
break;
|
||||||
|
case T_A:
|
||||||
|
default:
|
||||||
|
host.h_addrtype = AF_INET;
|
||||||
|
host.h_length = INADDRSZ;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(gethostanswer((const querybuf *)answer, anslen, qname, qtype));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
_gethostbydnsname(const char *name, int af)
|
||||||
|
{
|
||||||
|
querybuf buf;
|
||||||
|
register const char *cp;
|
||||||
|
char *bp;
|
||||||
|
int n, size, type, len;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
size = INADDRSZ;
|
||||||
|
type = T_A;
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
size = IN6ADDRSZ;
|
||||||
|
type = T_AAAA;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
host.h_addrtype = af;
|
||||||
|
host.h_length = size;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* if there aren't any dots, it could be a user-level alias.
|
||||||
|
* this is also done in res_query() since we are not the only
|
||||||
|
* function that looks up host names.
|
||||||
|
*/
|
||||||
|
if (!strchr(name, '.') && ( NULL != (cp = __hostalias(name))))
|
||||||
|
name = cp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* disallow names consisting only of digits/dots, unless
|
||||||
|
* they end in a dot.
|
||||||
|
*/
|
||||||
|
if (isdigit(name[0]))
|
||||||
|
for (cp = name;; ++cp) {
|
||||||
|
if (!*cp) {
|
||||||
|
if (*--cp == '.')
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* All-numeric, no dot at the end.
|
||||||
|
* Fake up a hostent as if we'd actually
|
||||||
|
* done a lookup.
|
||||||
|
*/
|
||||||
|
if (inet_pton(af, name, host_addr) <= 0) {
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
strncpy(hostbuf, name, MAXDNAME);
|
||||||
|
hostbuf[MAXDNAME] = '\0';
|
||||||
|
bp = hostbuf + MAXDNAME;
|
||||||
|
len = sizeof hostbuf - MAXDNAME;
|
||||||
|
host.h_name = hostbuf;
|
||||||
|
host.h_aliases = host_aliases;
|
||||||
|
host_aliases[0] = NULL;
|
||||||
|
h_addr_ptrs[0] = (char *)host_addr;
|
||||||
|
h_addr_ptrs[1] = NULL;
|
||||||
|
host.h_addr_list = h_addr_ptrs;
|
||||||
|
if (_res.options & RES_USE_INET6)
|
||||||
|
_map_v4v6_hostent(&host, &bp, &len);
|
||||||
|
h_errno = NETDB_SUCCESS;
|
||||||
|
return (&host);
|
||||||
|
}
|
||||||
|
if (!isdigit(*cp) && *cp != '.')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((isxdigit(name[0]) && strchr(name, ':') != NULL) ||
|
||||||
|
name[0] == ':')
|
||||||
|
for (cp = name;; ++cp) {
|
||||||
|
if (!*cp) {
|
||||||
|
if (*--cp == '.')
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* All-IPv6-legal, no dot at the end.
|
||||||
|
* Fake up a hostent as if we'd actually
|
||||||
|
* done a lookup.
|
||||||
|
*/
|
||||||
|
if (inet_pton(af, name, host_addr) <= 0) {
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
strncpy(hostbuf, name, MAXDNAME);
|
||||||
|
hostbuf[MAXDNAME] = '\0';
|
||||||
|
bp = hostbuf + MAXDNAME;
|
||||||
|
len = sizeof hostbuf - MAXDNAME;
|
||||||
|
host.h_name = hostbuf;
|
||||||
|
host.h_aliases = host_aliases;
|
||||||
|
host_aliases[0] = NULL;
|
||||||
|
h_addr_ptrs[0] = (char *)host_addr;
|
||||||
|
h_addr_ptrs[1] = NULL;
|
||||||
|
host.h_addr_list = h_addr_ptrs;
|
||||||
|
h_errno = NETDB_SUCCESS;
|
||||||
|
return (&host);
|
||||||
|
}
|
||||||
|
if (!isxdigit(*cp) && *cp != ':' && *cp != '.')
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {
|
||||||
|
dprintf("res_search failed (%d)\n", n);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return (gethostanswer(&buf, n, name, type));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
_gethostbydnsaddr(const char *addr, int len, int af)
|
||||||
|
{
|
||||||
|
const u_char *uaddr = (const u_char *)addr;
|
||||||
|
static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };
|
||||||
|
static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
|
||||||
|
int n, size;
|
||||||
|
querybuf buf;
|
||||||
|
register struct hostent *hp;
|
||||||
|
char qbuf[MAXDNAME+1], *qp;
|
||||||
|
#ifdef SUNSECURITY
|
||||||
|
register struct hostent *rhp;
|
||||||
|
char **haddr;
|
||||||
|
u_long old_options;
|
||||||
|
char hname2[MAXDNAME+1];
|
||||||
|
#endif /*SUNSECURITY*/
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (af == AF_INET6 && len == IN6ADDRSZ &&
|
||||||
|
(!bcmp(uaddr, mapped, sizeof mapped) ||
|
||||||
|
!bcmp(uaddr, tunnelled, sizeof tunnelled))) {
|
||||||
|
/* Unmap. */
|
||||||
|
addr += sizeof mapped;
|
||||||
|
uaddr += sizeof mapped;
|
||||||
|
af = AF_INET;
|
||||||
|
len = INADDRSZ;
|
||||||
|
}
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
size = INADDRSZ;
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
size = IN6ADDRSZ;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (size != len) {
|
||||||
|
errno = EINVAL;
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
(void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
|
||||||
|
(uaddr[3] & 0xff),
|
||||||
|
(uaddr[2] & 0xff),
|
||||||
|
(uaddr[1] & 0xff),
|
||||||
|
(uaddr[0] & 0xff));
|
||||||
|
break;
|
||||||
|
case AF_INET6:
|
||||||
|
qp = qbuf;
|
||||||
|
for (n = IN6ADDRSZ - 1; n >= 0; n--) {
|
||||||
|
qp += SPRINTF((qp, "%x.%x.",
|
||||||
|
uaddr[n] & 0xf,
|
||||||
|
(uaddr[n] >> 4) & 0xf));
|
||||||
|
}
|
||||||
|
strcpy(qp, "ip6.int");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);
|
||||||
|
if (n < 0) {
|
||||||
|
dprintf("res_query failed (%d)\n", n);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if ( NULL == (hp = gethostanswer(&buf, n, qbuf, T_PTR)))
|
||||||
|
return (NULL); /* h_errno was set by gethostanswer() */
|
||||||
|
#ifdef SUNSECURITY
|
||||||
|
if (af == AF_INET) {
|
||||||
|
/*
|
||||||
|
* turn off search as the name should be absolute,
|
||||||
|
* 'localhost' should be matched by defnames
|
||||||
|
*/
|
||||||
|
strncpy(hname2, hp->h_name, MAXDNAME);
|
||||||
|
hname2[MAXDNAME] = '\0';
|
||||||
|
old_options = _res.options;
|
||||||
|
_res.options &= ~RES_DNSRCH;
|
||||||
|
_res.options |= RES_DEFNAMES;
|
||||||
|
if (!(rhp = gethostbyname(hname2))) {
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
syslog(LOG_NOTICE|LOG_AUTH,
|
||||||
|
"gethostbyaddr: No A record for %s (verifying [%s])",
|
||||||
|
hname2, inet_ntoa(*((struct in_addr *)addr)));
|
||||||
|
#endif
|
||||||
|
_res.options = old_options;
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
_res.options = old_options;
|
||||||
|
for (haddr = rhp->h_addr_list; *haddr; haddr++)
|
||||||
|
if (!memcmp(*haddr, addr, INADDRSZ))
|
||||||
|
break;
|
||||||
|
if (!*haddr) {
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
syslog(LOG_NOTICE|LOG_AUTH,
|
||||||
|
"gethostbyaddr: A record of %s != PTR record [%s]",
|
||||||
|
hname2, inet_ntoa(*((struct in_addr *)addr)));
|
||||||
|
#endif
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /*SUNSECURITY*/
|
||||||
|
hp->h_addrtype = af;
|
||||||
|
hp->h_length = len;
|
||||||
|
bcopy(addr, host_addr, len);
|
||||||
|
h_addr_ptrs[0] = (char *)host_addr;
|
||||||
|
h_addr_ptrs[1] = NULL;
|
||||||
|
if (af == AF_INET && (_res.options & RES_USE_INET6)) {
|
||||||
|
_map_v4v6_address((char*)host_addr, (char*)host_addr);
|
||||||
|
hp->h_addrtype = AF_INET6;
|
||||||
|
hp->h_length = IN6ADDRSZ;
|
||||||
|
}
|
||||||
|
h_errno = NETDB_SUCCESS;
|
||||||
|
return (hp);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
static void
|
||||||
|
addrsort(char **ap, int num)
|
||||||
|
{
|
||||||
|
short i, j;
|
||||||
|
char **p;
|
||||||
|
short aval[MAXADDRS];
|
||||||
|
short needsort = 0;
|
||||||
|
|
||||||
|
p = ap;
|
||||||
|
for (i = 0; i < num; i++, p++) {
|
||||||
|
for (j = 0 ; (unsigned)j < _res.nsort; j++)
|
||||||
|
if (_res.sort_list[j].addr.s_addr ==
|
||||||
|
(((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
|
||||||
|
break;
|
||||||
|
aval[i] = j;
|
||||||
|
if (needsort == 0 && i > 0 && j < aval[i-1])
|
||||||
|
needsort = i;
|
||||||
|
}
|
||||||
|
if (!needsort)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (needsort < num) {
|
||||||
|
for (j = needsort - 1; j >= 0; j--) {
|
||||||
|
if (aval[j] > aval[j+1]) {
|
||||||
|
char *hp;
|
||||||
|
|
||||||
|
i = aval[j];
|
||||||
|
aval[j] = aval[j+1];
|
||||||
|
aval[j+1] = i;
|
||||||
|
|
||||||
|
hp = ap[j];
|
||||||
|
ap[j] = ap[j+1];
|
||||||
|
ap[j+1] = hp;
|
||||||
|
|
||||||
|
} else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
needsort++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
void
|
||||||
|
_sethostdnsent(int stayopen)
|
||||||
|
{
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
|
||||||
|
return;
|
||||||
|
if (stayopen)
|
||||||
|
_res.options |= RES_STAYOPEN | RES_USEVC;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_endhostdnsent()
|
||||||
|
{
|
||||||
|
_res.options &= ~(RES_STAYOPEN | RES_USEVC);
|
||||||
|
res_close();
|
||||||
|
}
|
207
StdLib/BsdSocketLib/gethostbyht.c
Normal file
207
StdLib/BsdSocketLib/gethostbyht.c
Normal file
@ -0,0 +1,207 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1985, 1988, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
* -
|
||||||
|
* --Copyright--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char rcsid[] = "$Id: gethostbyht.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arpa/nameser.h> /* XXX */
|
||||||
|
#include <resolv.h> /* XXX */
|
||||||
|
#include "Socklib_internals.h"
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
static struct hostent host;
|
||||||
|
static char *host_aliases[MAXALIASES];
|
||||||
|
static char hostbuf[BUFSIZ+1];
|
||||||
|
static FILE *hostf = NULL;
|
||||||
|
static u_char host_addr[16]; /* IPv4 or IPv6 */
|
||||||
|
static char *h_addr_ptrs[2];
|
||||||
|
static int stayopen = 0;
|
||||||
|
|
||||||
|
void
|
||||||
|
_sethosthtent(int f)
|
||||||
|
{
|
||||||
|
if (!hostf)
|
||||||
|
hostf = fopen(_PATH_HOSTS, "r" );
|
||||||
|
else
|
||||||
|
rewind(hostf);
|
||||||
|
stayopen = f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_endhosthtent()
|
||||||
|
{
|
||||||
|
if (hostf && !stayopen) {
|
||||||
|
(void) fclose(hostf);
|
||||||
|
hostf = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
gethostent()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
register char *cp, **q;
|
||||||
|
int af, len;
|
||||||
|
|
||||||
|
if (!hostf && ( NULL == (hostf = fopen(_PATH_HOSTS, "r" )))) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
again:
|
||||||
|
if ( NULL == (p = fgets(hostbuf, sizeof hostbuf, hostf))) {
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (*p == '#')
|
||||||
|
goto again;
|
||||||
|
if ( NULL == (cp = strpbrk(p, "#\n")))
|
||||||
|
goto again;
|
||||||
|
*cp = '\0';
|
||||||
|
if ( NULL == (cp = strpbrk(p, " \t")))
|
||||||
|
goto again;
|
||||||
|
*cp++ = '\0';
|
||||||
|
if (inet_pton(AF_INET6, p, host_addr) > 0) {
|
||||||
|
af = AF_INET6;
|
||||||
|
len = IN6ADDRSZ;
|
||||||
|
} else if (inet_pton(AF_INET, p, host_addr) > 0) {
|
||||||
|
if (_res.options & RES_USE_INET6) {
|
||||||
|
_map_v4v6_address((char*)host_addr, (char*)host_addr);
|
||||||
|
af = AF_INET6;
|
||||||
|
len = IN6ADDRSZ;
|
||||||
|
} else {
|
||||||
|
af = AF_INET;
|
||||||
|
len = INADDRSZ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
goto again;
|
||||||
|
}
|
||||||
|
h_addr_ptrs[0] = (char *)host_addr;
|
||||||
|
h_addr_ptrs[1] = NULL;
|
||||||
|
host.h_addr_list = h_addr_ptrs;
|
||||||
|
host.h_length = len;
|
||||||
|
host.h_addrtype = af;
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
host.h_name = cp;
|
||||||
|
q = host.h_aliases = host_aliases;
|
||||||
|
if ((cp = strpbrk(cp, " \t\r")) != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &host_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
if ((cp = strpbrk(cp, " \t\r")) != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
h_errno = NETDB_SUCCESS;
|
||||||
|
return (&host);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
_gethostbyhtname(const char *name, int af)
|
||||||
|
{
|
||||||
|
register struct hostent *p;
|
||||||
|
register char **cp;
|
||||||
|
|
||||||
|
sethostent(0);
|
||||||
|
while ((p = gethostent()) != NULL) {
|
||||||
|
if (p->h_addrtype != af)
|
||||||
|
continue;
|
||||||
|
if (strcasecmp(p->h_name, name) == 0)
|
||||||
|
break;
|
||||||
|
for (cp = p->h_aliases; *cp != 0; cp++)
|
||||||
|
if (strcasecmp(*cp, name) == 0)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
found:
|
||||||
|
endhostent();
|
||||||
|
return (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
_gethostbyhtaddr(const char *addr, int len, int af)
|
||||||
|
{
|
||||||
|
register struct hostent *p;
|
||||||
|
|
||||||
|
sethostent(0);
|
||||||
|
while ((p = gethostent()) != NULL)
|
||||||
|
if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
|
||||||
|
break;
|
||||||
|
endhostent();
|
||||||
|
return (p);
|
||||||
|
}
|
134
StdLib/BsdSocketLib/gethostbynis.c
Normal file
134
StdLib/BsdSocketLib/gethostbynis.c
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1994, Garrett Wollman
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)$Id: gethostbynis.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
static char rcsid[] = "$Id: gethostbynis.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#ifdef YP
|
||||||
|
#include <rpc/rpc.h>
|
||||||
|
#include <rpcsvc/yp_prot.h>
|
||||||
|
#include <rpcsvc/ypclnt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
#define MAXADDRS 35
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
static char *host_aliases[MAXALIASES];
|
||||||
|
static char hostaddr[MAXADDRS];
|
||||||
|
static char *host_addrs[2];
|
||||||
|
#endif /* YP */
|
||||||
|
|
||||||
|
static struct hostent *
|
||||||
|
_gethostbynis(const char *name, char *map, int af)
|
||||||
|
{
|
||||||
|
#ifdef YP
|
||||||
|
register char *cp, **q;
|
||||||
|
char *result;
|
||||||
|
int resultlen;
|
||||||
|
static struct hostent h;
|
||||||
|
static char *domain = (char *)NULL;
|
||||||
|
static char ypbuf[YPMAXRECORD + 2];
|
||||||
|
|
||||||
|
switch(af) {
|
||||||
|
case AF_INET:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case AF_INET6:
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domain == (char *)NULL)
|
||||||
|
if (yp_get_default_domain (&domain))
|
||||||
|
return ((struct hostent *)NULL);
|
||||||
|
|
||||||
|
if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
|
||||||
|
return ((struct hostent *)NULL);
|
||||||
|
|
||||||
|
/* avoid potential memory leak */
|
||||||
|
bcopy((char *)result, (char *)&ypbuf, resultlen);
|
||||||
|
ypbuf[resultlen] = '\0';
|
||||||
|
free(result);
|
||||||
|
result = (char *)&ypbuf;
|
||||||
|
|
||||||
|
if ((cp = index(result, '\n')))
|
||||||
|
*cp = '\0';
|
||||||
|
|
||||||
|
cp = strpbrk(result, " \t");
|
||||||
|
*cp++ = '\0';
|
||||||
|
h.h_addr_list = host_addrs;
|
||||||
|
h.h_addr = hostaddr;
|
||||||
|
*((u_long *)h.h_addr) = inet_addr(result);
|
||||||
|
h.h_length = sizeof(u_long);
|
||||||
|
h.h_addrtype = AF_INET;
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
h.h_name = cp;
|
||||||
|
q = h.h_aliases = host_aliases;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &host_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&h);
|
||||||
|
#else
|
||||||
|
return (NULL);
|
||||||
|
#endif /* YP */
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
_gethostbynisname(const char *name, int af)
|
||||||
|
{
|
||||||
|
return _gethostbynis(name, "hosts.byname", af);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
_gethostbynisaddr(const char *addr, int len, int af)
|
||||||
|
{
|
||||||
|
return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
|
||||||
|
}
|
225
StdLib/BsdSocketLib/gethostnamadr.c
Normal file
225
StdLib/BsdSocketLib/gethostnamadr.c
Normal file
@ -0,0 +1,225 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1994, Garrett Wollman
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)$Id: gethostnamadr.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
static char rcsid[] = "$Id: gethostnamadr.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arpa/nameser.h> /* XXX hack for _res */
|
||||||
|
#include <resolv.h> /* XXX hack for _res */
|
||||||
|
|
||||||
|
#include "Socklib_internals.h"
|
||||||
|
|
||||||
|
|
||||||
|
enum service_type {
|
||||||
|
SERVICE_NONE = 0,
|
||||||
|
SERVICE_BIND,
|
||||||
|
SERVICE_HOSTS,
|
||||||
|
SERVICE_NIS };
|
||||||
|
#define SERVICE_MAX SERVICE_NIS
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
const char *name;
|
||||||
|
enum service_type type;
|
||||||
|
} service_names[] = {
|
||||||
|
{ "hosts", SERVICE_HOSTS },
|
||||||
|
{ _PATH_HOSTS, SERVICE_HOSTS },
|
||||||
|
{ "hosttable", SERVICE_HOSTS },
|
||||||
|
{ "htable", SERVICE_HOSTS },
|
||||||
|
{ "bind", SERVICE_BIND },
|
||||||
|
{ "dns", SERVICE_BIND },
|
||||||
|
{ "domain", SERVICE_BIND },
|
||||||
|
{ "yp", SERVICE_NIS },
|
||||||
|
{ "yellowpages", SERVICE_NIS },
|
||||||
|
{ "nis", SERVICE_NIS },
|
||||||
|
{ 0, SERVICE_NONE }
|
||||||
|
};
|
||||||
|
|
||||||
|
static enum service_type service_order[SERVICE_MAX + 1];
|
||||||
|
static int service_done = 0;
|
||||||
|
|
||||||
|
static enum service_type
|
||||||
|
get_service_name(const char *name) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
|
||||||
|
if(!strcasecmp(name, service_names[i].name)) {
|
||||||
|
return service_names[i].type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SERVICE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_services()
|
||||||
|
{
|
||||||
|
char *cp, *p, buf[BUFSIZ];
|
||||||
|
register int cc = 0;
|
||||||
|
FILE *fd;
|
||||||
|
|
||||||
|
if ((fd = (FILE *)fopen(_PATH_HOSTCONF, "r")) == NULL) {
|
||||||
|
/* make some assumptions */
|
||||||
|
service_order[0] = SERVICE_HOSTS;
|
||||||
|
service_order[1] = SERVICE_BIND;
|
||||||
|
service_order[2] = SERVICE_NONE;
|
||||||
|
} else {
|
||||||
|
while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
|
||||||
|
if(buf[0] == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
p = buf;
|
||||||
|
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
|
||||||
|
;
|
||||||
|
if (cp == NULL)
|
||||||
|
continue;
|
||||||
|
do {
|
||||||
|
if (isalpha(cp[0])) {
|
||||||
|
service_order[cc] = get_service_name(cp);
|
||||||
|
if(service_order[cc] != SERVICE_NONE)
|
||||||
|
cc++;
|
||||||
|
}
|
||||||
|
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
|
||||||
|
;
|
||||||
|
} while(cp != NULL && cc < SERVICE_MAX);
|
||||||
|
}
|
||||||
|
service_order[cc] = SERVICE_NONE;
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
service_done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
gethostbyname(const char *name)
|
||||||
|
{
|
||||||
|
struct hostent *hp;
|
||||||
|
|
||||||
|
if (_res.options & RES_USE_INET6) { /* XXX */
|
||||||
|
hp = gethostbyname2(name, AF_INET6); /* XXX */
|
||||||
|
if (hp) /* XXX */
|
||||||
|
return (hp); /* XXX */
|
||||||
|
} /* XXX */
|
||||||
|
return (gethostbyname2(name, AF_INET));
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
gethostbyname2(const char *name, int type)
|
||||||
|
{
|
||||||
|
struct hostent *hp = 0;
|
||||||
|
int nserv = 0;
|
||||||
|
|
||||||
|
if (!service_done)
|
||||||
|
init_services();
|
||||||
|
|
||||||
|
while (!hp) {
|
||||||
|
switch (service_order[nserv]) {
|
||||||
|
case SERVICE_NONE:
|
||||||
|
return NULL;
|
||||||
|
case SERVICE_HOSTS:
|
||||||
|
hp = _gethostbyhtname(name, type);
|
||||||
|
break;
|
||||||
|
case SERVICE_BIND:
|
||||||
|
hp = _gethostbydnsname(name, type);
|
||||||
|
break;
|
||||||
|
case SERVICE_NIS:
|
||||||
|
hp = _gethostbynisname(name, type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nserv++;
|
||||||
|
}
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct hostent *
|
||||||
|
gethostbyaddr(const char *addr, socklen_t len, int type)
|
||||||
|
{
|
||||||
|
struct hostent *hp = 0;
|
||||||
|
int nserv = 0;
|
||||||
|
|
||||||
|
if (!service_done)
|
||||||
|
init_services();
|
||||||
|
|
||||||
|
while (!hp) {
|
||||||
|
switch (service_order[nserv]) {
|
||||||
|
case SERVICE_NONE:
|
||||||
|
return 0;
|
||||||
|
case SERVICE_HOSTS:
|
||||||
|
hp = _gethostbyhtaddr(addr, len, type);
|
||||||
|
break;
|
||||||
|
case SERVICE_BIND:
|
||||||
|
hp = _gethostbydnsaddr(addr, len, type);
|
||||||
|
break;
|
||||||
|
case SERVICE_NIS:
|
||||||
|
hp = _gethostbynisaddr(addr, len, type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nserv++;
|
||||||
|
}
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _THREAD_SAFE
|
||||||
|
struct hostent_data;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Temporary function (not thread safe)
|
||||||
|
*/
|
||||||
|
int gethostbyaddr_r(const char *addr, int len, int type,
|
||||||
|
struct hostent *result, struct hostent_data *buffer)
|
||||||
|
{
|
||||||
|
struct hostent *hp;
|
||||||
|
int ret;
|
||||||
|
if ((hp = gethostbyaddr(addr, len, type)) == NULL) {
|
||||||
|
ret = -1;
|
||||||
|
} else {
|
||||||
|
memcpy(result, hp, sizeof(struct hostent));
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
sethostent(int stayopen)
|
||||||
|
{
|
||||||
|
_sethosthtent(stayopen);
|
||||||
|
_sethostdnsent(stayopen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endhostent()
|
||||||
|
{
|
||||||
|
_endhosthtent();
|
||||||
|
_endhostdnsent();
|
||||||
|
}
|
92
StdLib/BsdSocketLib/gethostname.c
Normal file
92
StdLib/BsdSocketLib/gethostname.c
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software must
|
||||||
|
* display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and its
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be used to
|
||||||
|
* endorse or promote products derived from this software without specific
|
||||||
|
* prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Module Name:
|
||||||
|
|
||||||
|
gethostname.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
Map FreeBSD gethostname call to EFI Interface
|
||||||
|
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
int
|
||||||
|
gethostname(
|
||||||
|
char *name,
|
||||||
|
size_t namelen
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Get the hostname for this system.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
name - Pointer to storage for hostname.
|
||||||
|
namelen - Length of name
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
0 on success, -1 if not set
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
char *pHost;
|
||||||
|
|
||||||
|
pHost = getenv ("HOSTNAME");
|
||||||
|
|
||||||
|
if ( pHost == NULL ) {
|
||||||
|
*name = 0;
|
||||||
|
} else {
|
||||||
|
strncpy (name, pHost, namelen);
|
||||||
|
name[namelen-1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
318
StdLib/BsdSocketLib/getnetbydns.c
Normal file
318
StdLib/BsdSocketLib/getnetbydns.c
Normal file
@ -0,0 +1,318 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1985, 1988, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
* -
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
* -
|
||||||
|
* --Copyright--
|
||||||
|
*/
|
||||||
|
/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
|
||||||
|
* Dep. Matematica Universidade de Coimbra, Portugal, Europe
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char rcsid[] = "$Id: getnetbydns.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
#include <syslog.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
#include "Socklib_internals.h"
|
||||||
|
|
||||||
|
extern int h_errno;
|
||||||
|
|
||||||
|
#define BYADDR 0
|
||||||
|
#define BYNAME 1
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
#if PACKETSZ > 1024
|
||||||
|
#define MAXPACKET PACKETSZ
|
||||||
|
#else
|
||||||
|
#define MAXPACKET 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
HEADER hdr;
|
||||||
|
u_char buf[MAXPACKET];
|
||||||
|
} querybuf;
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
long al;
|
||||||
|
char ac;
|
||||||
|
} align;
|
||||||
|
|
||||||
|
static struct netent *
|
||||||
|
getnetanswer(querybuf *answer, int anslen, int net_i)
|
||||||
|
{
|
||||||
|
|
||||||
|
register HEADER *hp;
|
||||||
|
register u_char *cp;
|
||||||
|
register int n;
|
||||||
|
u_char *eom;
|
||||||
|
int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
|
||||||
|
char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN];
|
||||||
|
char *in, *st, *pauxt, *bp, **ap;
|
||||||
|
char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
|
||||||
|
static struct netent net_entry;
|
||||||
|
static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* find first satisfactory answer
|
||||||
|
*
|
||||||
|
* answer --> +------------+ ( MESSAGE )
|
||||||
|
* | Header |
|
||||||
|
* +------------+
|
||||||
|
* | Question | the question for the name server
|
||||||
|
* +------------+
|
||||||
|
* | Answer | RRs answering the question
|
||||||
|
* +------------+
|
||||||
|
* | Authority | RRs pointing toward an authority
|
||||||
|
* | Additional | RRs holding additional information
|
||||||
|
* +------------+
|
||||||
|
*/
|
||||||
|
eom = answer->buf + anslen;
|
||||||
|
hp = &answer->hdr;
|
||||||
|
ancount = ntohs(hp->ancount); /* #/records in the answer section */
|
||||||
|
qdcount = ntohs(hp->qdcount); /* #/entries in the question section */
|
||||||
|
bp = netbuf;
|
||||||
|
buflen = sizeof(netbuf);
|
||||||
|
cp = answer->buf + HFIXEDSZ;
|
||||||
|
if (!qdcount) {
|
||||||
|
if (hp->aa)
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
else
|
||||||
|
h_errno = TRY_AGAIN;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
while (qdcount-- > 0)
|
||||||
|
cp += __dn_skipname(cp, eom) + QFIXEDSZ;
|
||||||
|
ap = net_aliases;
|
||||||
|
*ap = NULL;
|
||||||
|
net_entry.n_aliases = net_aliases;
|
||||||
|
haveanswer = 0;
|
||||||
|
while (--ancount >= 0 && cp < eom) {
|
||||||
|
n = dn_expand(answer->buf, eom, cp, bp, buflen);
|
||||||
|
if ((n < 0) || !res_dnok(bp))
|
||||||
|
break;
|
||||||
|
cp += n;
|
||||||
|
ans[0] = '\0';
|
||||||
|
(void)strncpy(&ans[0], bp, sizeof(ans) - 1);
|
||||||
|
ans[sizeof(ans) - 1] = '\0';
|
||||||
|
GETSHORT(type, cp);
|
||||||
|
GETSHORT(class, cp);
|
||||||
|
cp += INT32SZ; /* TTL */
|
||||||
|
GETSHORT(n, cp);
|
||||||
|
if (class == C_IN && type == T_PTR) {
|
||||||
|
n = dn_expand(answer->buf, eom, cp, bp, buflen);
|
||||||
|
if ((n < 0) || !res_hnok(bp)) {
|
||||||
|
cp += n;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
cp += n;
|
||||||
|
*ap++ = bp;
|
||||||
|
bp += strlen(bp) + 1;
|
||||||
|
net_entry.n_addrtype =
|
||||||
|
(class == C_IN) ? AF_INET : AF_UNSPEC;
|
||||||
|
haveanswer++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (haveanswer) {
|
||||||
|
*ap = NULL;
|
||||||
|
switch (net_i) {
|
||||||
|
case BYADDR:
|
||||||
|
net_entry.n_name = *net_entry.n_aliases;
|
||||||
|
net_entry.n_net = 0L;
|
||||||
|
break;
|
||||||
|
case BYNAME:
|
||||||
|
in = *net_entry.n_aliases;
|
||||||
|
net_entry.n_name = &ans[0];
|
||||||
|
aux2[0] = '\0';
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
for (st = in, nchar = 0;
|
||||||
|
*st != '.';
|
||||||
|
st++, nchar++)
|
||||||
|
;
|
||||||
|
if (nchar != 1 || *in != '0' || flag) {
|
||||||
|
flag = 1;
|
||||||
|
(void)strncpy(paux1,
|
||||||
|
(i==0) ? in : in-1,
|
||||||
|
(i==0) ?nchar : nchar+1);
|
||||||
|
paux1[(i==0) ? nchar : nchar+1] = '\0';
|
||||||
|
pauxt = paux2;
|
||||||
|
paux2 = strcat(paux1, paux2);
|
||||||
|
paux1 = pauxt;
|
||||||
|
}
|
||||||
|
in = ++st;
|
||||||
|
}
|
||||||
|
net_entry.n_net = inet_network(paux2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
net_entry.n_aliases++;
|
||||||
|
return (&net_entry);
|
||||||
|
}
|
||||||
|
h_errno = TRY_AGAIN;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
_getnetbydnsaddr(register unsigned long net, register int net_type)
|
||||||
|
{
|
||||||
|
unsigned int netbr[4];
|
||||||
|
int nn, anslen;
|
||||||
|
querybuf buf;
|
||||||
|
char qbuf[MAXDNAME];
|
||||||
|
unsigned long net2;
|
||||||
|
struct netent *net_entry;
|
||||||
|
|
||||||
|
if (net_type != AF_INET)
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
for (nn = 4, net2 = net; net2; net2 >>= 8)
|
||||||
|
netbr[--nn] = net2 & 0xff;
|
||||||
|
switch (nn) {
|
||||||
|
case 3: /* Class A */
|
||||||
|
sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
|
||||||
|
break;
|
||||||
|
case 2: /* Class B */
|
||||||
|
sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
|
||||||
|
break;
|
||||||
|
case 1: /* Class C */
|
||||||
|
sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
|
||||||
|
netbr[1]);
|
||||||
|
break;
|
||||||
|
case 0: /* Class D - E */
|
||||||
|
sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
|
||||||
|
netbr[1], netbr[0]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
|
||||||
|
if (anslen < 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf("res_query failed\n");
|
||||||
|
#endif
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
net_entry = getnetanswer(&buf, anslen, BYADDR);
|
||||||
|
if (net_entry) {
|
||||||
|
unsigned u_net = net; /* maybe net should be unsigned ? */
|
||||||
|
|
||||||
|
/* Strip trailing zeros */
|
||||||
|
while ((u_net & 0xff) == 0 && u_net != 0)
|
||||||
|
u_net >>= 8;
|
||||||
|
net_entry->n_net = u_net;
|
||||||
|
return (net_entry);
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
_getnetbydnsname(register const char *net)
|
||||||
|
{
|
||||||
|
int anslen;
|
||||||
|
querybuf buf;
|
||||||
|
char qbuf[MAXDNAME];
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
strncpy(qbuf, net, sizeof(qbuf) - 1);
|
||||||
|
qbuf[sizeof(qbuf) - 1] = '\0';
|
||||||
|
anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
|
||||||
|
if (anslen < 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf("res_query failed\n");
|
||||||
|
#endif
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
return getnetanswer(&buf, anslen, BYNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_setnetdnsent(int stayopen)
|
||||||
|
{
|
||||||
|
if (stayopen)
|
||||||
|
_res.options |= RES_STAYOPEN | RES_USEVC;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_endnetdnsent()
|
||||||
|
{
|
||||||
|
_res.options &= ~(RES_STAYOPEN | RES_USEVC);
|
||||||
|
res_close();
|
||||||
|
}
|
169
StdLib/BsdSocketLib/getnetbyht.c
Normal file
169
StdLib/BsdSocketLib/getnetbyht.c
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
|
||||||
|
* Dep. Matematica Universidade de Coimbra, Portugal, Europe
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* from getnetent.c 1.1 (Coimbra) 93/06/02
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char orig_rcsid[] = "From: Id: getnetent.c,v 8.4 1997/06/01 20:34:37 vixie Exp";
|
||||||
|
static chat rcsid[] = "$Id: getnetbyht.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
static FILE *netf;
|
||||||
|
static char line[BUFSIZ+1];
|
||||||
|
static struct netent net;
|
||||||
|
static char *net_aliases[MAXALIASES];
|
||||||
|
static int _net_stayopen;
|
||||||
|
|
||||||
|
void
|
||||||
|
_setnethtent(int f)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (netf == NULL)
|
||||||
|
netf = fopen(_PATH_NETWORKS, "r" );
|
||||||
|
else
|
||||||
|
rewind(netf);
|
||||||
|
_net_stayopen |= f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_endnethtent()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (netf) {
|
||||||
|
fclose(netf);
|
||||||
|
netf = NULL;
|
||||||
|
}
|
||||||
|
_net_stayopen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
getnetent()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
register char *cp, **q;
|
||||||
|
|
||||||
|
if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
again:
|
||||||
|
p = fgets(line, sizeof line, netf);
|
||||||
|
if (p == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (*p == '#')
|
||||||
|
goto again;
|
||||||
|
cp = strpbrk(p, "#\n");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp = '\0';
|
||||||
|
net.n_name = p;
|
||||||
|
cp = strpbrk(p, " \t");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
p = strpbrk(cp, " \t");
|
||||||
|
if (p != NULL)
|
||||||
|
*p++ = '\0';
|
||||||
|
net.n_net = inet_network(cp);
|
||||||
|
net.n_addrtype = AF_INET;
|
||||||
|
q = net.n_aliases = net_aliases;
|
||||||
|
if (p != NULL)
|
||||||
|
cp = p;
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &net_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&net);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
_getnetbyhtname(register const char *name)
|
||||||
|
{
|
||||||
|
register struct netent *p;
|
||||||
|
register char **cp;
|
||||||
|
|
||||||
|
setnetent(_net_stayopen);
|
||||||
|
while ( NULL != (p = getnetent()) ) {
|
||||||
|
if (strcasecmp(p->n_name, name) == 0)
|
||||||
|
break;
|
||||||
|
for (cp = p->n_aliases; *cp != 0; cp++)
|
||||||
|
if (strcasecmp(*cp, name) == 0)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
found:
|
||||||
|
if (!_net_stayopen)
|
||||||
|
endnetent();
|
||||||
|
return (p);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
_getnetbyhtaddr(register unsigned long net, register int type)
|
||||||
|
{
|
||||||
|
register struct netent *p;
|
||||||
|
|
||||||
|
setnetent(_net_stayopen);
|
||||||
|
while ( NULL != (p = getnetent()) )
|
||||||
|
if (p->n_addrtype == type && p->n_net == net)
|
||||||
|
break;
|
||||||
|
if (!_net_stayopen)
|
||||||
|
endnetent();
|
||||||
|
return (p);
|
||||||
|
}
|
171
StdLib/BsdSocketLib/getnetbynis.c
Normal file
171
StdLib/BsdSocketLib/getnetbynis.c
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1994, Garrett Wollman
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)$Id: getnetbynis.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
|
||||||
|
static char rcsid[] = "$Id: getnetbynis.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#ifdef YP
|
||||||
|
#include <rpc/rpc.h>
|
||||||
|
#include <rpcsvc/yp_prot.h>
|
||||||
|
#include <rpcsvc/ypclnt.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
#define MAXADDRS 35
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
static char *host_aliases[MAXALIASES];
|
||||||
|
#endif /* YP */
|
||||||
|
|
||||||
|
static struct netent *
|
||||||
|
_getnetbynis(const char *name, char *map, int af)
|
||||||
|
{
|
||||||
|
#ifdef YP
|
||||||
|
register char *cp, **q;
|
||||||
|
static char *result;
|
||||||
|
int resultlen;
|
||||||
|
static struct netent h;
|
||||||
|
static char *domain = (char *)NULL;
|
||||||
|
static char ypbuf[YPMAXRECORD + 2];
|
||||||
|
|
||||||
|
switch(af) {
|
||||||
|
case AF_INET:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
case AF_INET6:
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (domain == (char *)NULL)
|
||||||
|
if (yp_get_default_domain (&domain))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
|
||||||
|
return (NULL);
|
||||||
|
|
||||||
|
bcopy((char *)result, (char *)&ypbuf, resultlen);
|
||||||
|
ypbuf[resultlen] = '\0';
|
||||||
|
free(result);
|
||||||
|
result = (char *)&ypbuf;
|
||||||
|
|
||||||
|
if ((cp = index(result, '\n')))
|
||||||
|
*cp = '\0';
|
||||||
|
|
||||||
|
cp = strpbrk(result, " \t");
|
||||||
|
*cp++ = '\0';
|
||||||
|
h.n_name = result;
|
||||||
|
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
h.n_net = inet_network(cp);
|
||||||
|
h.n_addrtype = AF_INET;
|
||||||
|
|
||||||
|
q = h.n_aliases = host_aliases;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &host_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&h);
|
||||||
|
#else
|
||||||
|
return (NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
_getnetbynisname(const char *name)
|
||||||
|
{
|
||||||
|
return _getnetbynis(name, "networks.byname", AF_INET);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
_getnetbynisaddr(unsigned long addr, int af)
|
||||||
|
{
|
||||||
|
char *str, *cp;
|
||||||
|
unsigned long net2;
|
||||||
|
int nn;
|
||||||
|
unsigned int netbr[4];
|
||||||
|
char buf[MAXDNAME];
|
||||||
|
|
||||||
|
if (af != AF_INET) {
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (nn = 4, net2 = addr; net2; net2 >>= 8) {
|
||||||
|
netbr[--nn] = net2 & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (nn) {
|
||||||
|
case 3: /* Class A */
|
||||||
|
sprintf(buf, "%u", netbr[3]);
|
||||||
|
break;
|
||||||
|
case 2: /* Class B */
|
||||||
|
sprintf(buf, "%u.%u", netbr[2], netbr[3]);
|
||||||
|
break;
|
||||||
|
case 1: /* Class C */
|
||||||
|
sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
|
||||||
|
break;
|
||||||
|
case 0: /* Class D - E */
|
||||||
|
sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
|
||||||
|
netbr[2], netbr[3]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
str = (char *)&buf;
|
||||||
|
cp = str + (strlen(str) - 2);
|
||||||
|
|
||||||
|
while(!strcmp(cp, ".0")) {
|
||||||
|
*cp = '\0';
|
||||||
|
cp = str + (strlen(str) - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _getnetbynis(str, "networks.byaddr", af);
|
||||||
|
}
|
186
StdLib/BsdSocketLib/getnetnamadr.c
Normal file
186
StdLib/BsdSocketLib/getnetnamadr.c
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1994, Garrett Wollman
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char rcsid[] = "$Id: getnetnamadr.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "Socklib_internals.h"
|
||||||
|
|
||||||
|
enum service_type {
|
||||||
|
SERVICE_NONE = 0,
|
||||||
|
SERVICE_BIND,
|
||||||
|
SERVICE_TABLE,
|
||||||
|
SERVICE_NIS };
|
||||||
|
#define SERVICE_MAX SERVICE_NIS
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
const char *name;
|
||||||
|
enum service_type type;
|
||||||
|
} service_names[] = {
|
||||||
|
{ "hosts", SERVICE_TABLE },
|
||||||
|
{ _PATH_HOSTS, SERVICE_TABLE },
|
||||||
|
{ "hosttable", SERVICE_TABLE },
|
||||||
|
{ "htable", SERVICE_TABLE },
|
||||||
|
{ "bind", SERVICE_BIND },
|
||||||
|
{ "dns", SERVICE_BIND },
|
||||||
|
{ "domain", SERVICE_BIND },
|
||||||
|
{ "yp", SERVICE_NIS },
|
||||||
|
{ "yellowpages", SERVICE_NIS },
|
||||||
|
{ "nis", SERVICE_NIS },
|
||||||
|
{ 0, SERVICE_NONE }
|
||||||
|
};
|
||||||
|
|
||||||
|
static enum service_type service_order[SERVICE_MAX + 1];
|
||||||
|
static int service_done = 0;
|
||||||
|
|
||||||
|
static enum service_type
|
||||||
|
get_service_name(const char *name) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
|
||||||
|
if(!strcasecmp(name, service_names[i].name)) {
|
||||||
|
return service_names[i].type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return SERVICE_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init_services()
|
||||||
|
{
|
||||||
|
char *cp, *p, buf[BUFSIZ];
|
||||||
|
register int cc = 0;
|
||||||
|
FILE *fd;
|
||||||
|
|
||||||
|
if ((fd = (FILE *)fopen(_PATH_NETCONF, "r")) == NULL) {
|
||||||
|
/* make some assumptions */
|
||||||
|
service_order[0] = SERVICE_TABLE;
|
||||||
|
service_order[1] = SERVICE_NONE;
|
||||||
|
} else {
|
||||||
|
while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
|
||||||
|
if(buf[0] == '#')
|
||||||
|
continue;
|
||||||
|
|
||||||
|
p = buf;
|
||||||
|
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
|
||||||
|
;
|
||||||
|
if (cp == NULL)
|
||||||
|
continue;
|
||||||
|
do {
|
||||||
|
if (isalpha(cp[0])) {
|
||||||
|
service_order[cc] = get_service_name(cp);
|
||||||
|
if(service_order[cc] != SERVICE_NONE)
|
||||||
|
cc++;
|
||||||
|
}
|
||||||
|
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
|
||||||
|
;
|
||||||
|
} while(cp != NULL && cc < SERVICE_MAX);
|
||||||
|
}
|
||||||
|
service_order[cc] = SERVICE_NONE;
|
||||||
|
fclose(fd);
|
||||||
|
}
|
||||||
|
service_done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
getnetbyname(const char *name)
|
||||||
|
{
|
||||||
|
struct netent *hp = 0;
|
||||||
|
int nserv = 0;
|
||||||
|
|
||||||
|
if (!service_done)
|
||||||
|
init_services();
|
||||||
|
|
||||||
|
while (!hp) {
|
||||||
|
switch (service_order[nserv]) {
|
||||||
|
case SERVICE_NONE:
|
||||||
|
return NULL;
|
||||||
|
case SERVICE_TABLE:
|
||||||
|
hp = _getnetbyhtname(name);
|
||||||
|
break;
|
||||||
|
case SERVICE_BIND:
|
||||||
|
hp = _getnetbydnsname(name);
|
||||||
|
break;
|
||||||
|
case SERVICE_NIS:
|
||||||
|
hp = _getnetbynisname(name);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nserv++;
|
||||||
|
}
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct netent *
|
||||||
|
getnetbyaddr(uint32_t addr, int af)
|
||||||
|
{
|
||||||
|
struct netent *hp = 0;
|
||||||
|
int nserv = 0;
|
||||||
|
|
||||||
|
if (!service_done)
|
||||||
|
init_services();
|
||||||
|
|
||||||
|
while (!hp) {
|
||||||
|
switch (service_order[nserv]) {
|
||||||
|
case SERVICE_NONE:
|
||||||
|
return 0;
|
||||||
|
case SERVICE_TABLE:
|
||||||
|
hp = _getnetbyhtaddr(addr, af);
|
||||||
|
break;
|
||||||
|
case SERVICE_BIND:
|
||||||
|
hp = _getnetbydnsaddr(addr, af);
|
||||||
|
break;
|
||||||
|
case SERVICE_NIS:
|
||||||
|
hp = _getnetbynisaddr(addr, af);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
nserv++;
|
||||||
|
}
|
||||||
|
return hp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
setnetent(int stayopen)
|
||||||
|
{
|
||||||
|
_setnethtent(stayopen);
|
||||||
|
_setnetdnsent(stayopen);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endnetent()
|
||||||
|
{
|
||||||
|
_endnethtent();
|
||||||
|
_endnetdnsent();
|
||||||
|
}
|
73
StdLib/BsdSocketLib/getpeername.c
Normal file
73
StdLib/BsdSocketLib/getpeername.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the getpeername API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the remote address
|
||||||
|
|
||||||
|
The ::getpeername routine retrieves the remote system address from the socket.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getpeername.html#">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [out] address Network address to receive the remote system address
|
||||||
|
|
||||||
|
@param [in] address_len Length of the remote network address structure
|
||||||
|
|
||||||
|
@returns ::getpeername returns zero (0) if successful or -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
getpeername (
|
||||||
|
int s,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int RetVal;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
RetVal = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Get the remote address
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnGetPeer ( pSocketProtocol,
|
||||||
|
address,
|
||||||
|
address_len,
|
||||||
|
&errno );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
RetVal = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation status
|
||||||
|
//
|
||||||
|
return RetVal;
|
||||||
|
}
|
54
StdLib/BsdSocketLib/getproto.c
Normal file
54
StdLib/BsdSocketLib/getproto.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getproto.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
extern int _proto_stayopen;
|
||||||
|
|
||||||
|
struct protoent *
|
||||||
|
getprotobynumber(register int proto)
|
||||||
|
{
|
||||||
|
register struct protoent *p;
|
||||||
|
|
||||||
|
setprotoent(_proto_stayopen);
|
||||||
|
while ( NULL != (p = getprotoent()) )
|
||||||
|
if (p->p_proto == proto)
|
||||||
|
break;
|
||||||
|
if (!_proto_stayopen)
|
||||||
|
endprotoent();
|
||||||
|
return (p);
|
||||||
|
}
|
118
StdLib/BsdSocketLib/getprotoent.c
Normal file
118
StdLib/BsdSocketLib/getprotoent.c
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
static FILE *protof = NULL;
|
||||||
|
static char line[BUFSIZ+1];
|
||||||
|
static struct protoent proto;
|
||||||
|
static char *proto_aliases[MAXALIASES];
|
||||||
|
int _proto_stayopen;
|
||||||
|
|
||||||
|
void
|
||||||
|
setprotoent(int f)
|
||||||
|
{
|
||||||
|
if (protof == NULL)
|
||||||
|
protof = fopen(_PATH_PROTOCOLS, "r" );
|
||||||
|
else
|
||||||
|
rewind(protof);
|
||||||
|
_proto_stayopen |= f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endprotoent()
|
||||||
|
{
|
||||||
|
if (protof) {
|
||||||
|
fclose(protof);
|
||||||
|
protof = NULL;
|
||||||
|
}
|
||||||
|
_proto_stayopen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct protoent *
|
||||||
|
getprotoent()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
register char *cp, **q;
|
||||||
|
|
||||||
|
if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
again:
|
||||||
|
if ((p = fgets(line, BUFSIZ, protof)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
if (*p == '#')
|
||||||
|
goto again;
|
||||||
|
cp = strpbrk(p, "#\n");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp = '\0';
|
||||||
|
proto.p_name = p;
|
||||||
|
cp = strpbrk(p, " \t");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
p = strpbrk(cp, " \t");
|
||||||
|
if (p != NULL)
|
||||||
|
*p++ = '\0';
|
||||||
|
proto.p_proto = atoi(cp);
|
||||||
|
q = proto.p_aliases = proto_aliases;
|
||||||
|
if (p != NULL) {
|
||||||
|
cp = p;
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &proto_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&proto);
|
||||||
|
}
|
61
StdLib/BsdSocketLib/getprotoname.c
Normal file
61
StdLib/BsdSocketLib/getprotoname.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getprotoname.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern int _proto_stayopen;
|
||||||
|
|
||||||
|
struct protoent *
|
||||||
|
getprotobyname(register const char *name)
|
||||||
|
{
|
||||||
|
register struct protoent *p;
|
||||||
|
register char **cp;
|
||||||
|
|
||||||
|
setprotoent(_proto_stayopen);
|
||||||
|
while ( NULL != (p = getprotoent()) ) {
|
||||||
|
if (strcmp(p->p_name, name) == 0)
|
||||||
|
break;
|
||||||
|
for (cp = p->p_aliases; *cp != 0; cp++)
|
||||||
|
if (strcmp(*cp, name) == 0)
|
||||||
|
goto found;
|
||||||
|
}
|
||||||
|
found:
|
||||||
|
if (!_proto_stayopen)
|
||||||
|
endprotoent();
|
||||||
|
return (p);
|
||||||
|
}
|
77
StdLib/BsdSocketLib/getservbyname.c
Normal file
77
StdLib/BsdSocketLib/getservbyname.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getservbyname.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern int _serv_stayopen;
|
||||||
|
|
||||||
|
struct servent *
|
||||||
|
getservbyname(IN const char *name, IN const char *proto)
|
||||||
|
{
|
||||||
|
register struct servent *p;
|
||||||
|
register char **cp;
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
extern char *___getservbyname_yp;
|
||||||
|
extern char *___getservbyproto_yp;
|
||||||
|
|
||||||
|
___getservbyname_yp = (char *)name;
|
||||||
|
___getservbyproto_yp = (char *)proto;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setservent(_serv_stayopen);
|
||||||
|
while ( NULL != (p = getservent()) ) {
|
||||||
|
if (strcmp(name, p->s_name) == 0)
|
||||||
|
goto gotname;
|
||||||
|
for (cp = p->s_aliases; *cp; cp++)
|
||||||
|
if (strcmp(name, *cp) == 0)
|
||||||
|
goto gotname;
|
||||||
|
continue;
|
||||||
|
gotname:
|
||||||
|
if (proto == 0 || strcmp(p->s_proto, proto) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!_serv_stayopen)
|
||||||
|
endservent();
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
___getservbyname_yp = NULL;
|
||||||
|
___getservbyproto_yp = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (p);
|
||||||
|
}
|
72
StdLib/BsdSocketLib/getservbyport.c
Normal file
72
StdLib/BsdSocketLib/getservbyport.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getservbyport.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
extern int _serv_stayopen;
|
||||||
|
|
||||||
|
struct servent *
|
||||||
|
getservbyport(int port, const char *proto)
|
||||||
|
{
|
||||||
|
register struct servent *p;
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
extern int ___getservbyport_yp;
|
||||||
|
extern char *___getservbyproto_yp;
|
||||||
|
|
||||||
|
___getservbyport_yp = port;
|
||||||
|
___getservbyproto_yp = (char *)proto;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
setservent(_serv_stayopen);
|
||||||
|
while ( NULL != (p = getservent()) ) {
|
||||||
|
if (p->s_port != port)
|
||||||
|
continue;
|
||||||
|
if (proto == 0 || strcmp(p->s_proto, proto) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!_serv_stayopen)
|
||||||
|
endservent();
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
___getservbyport_yp = 0;
|
||||||
|
___getservbyproto_yp = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return (p);
|
||||||
|
}
|
277
StdLib/BsdSocketLib/getservent.c
Normal file
277
StdLib/BsdSocketLib/getservent.c
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#ifdef YP
|
||||||
|
#include <rpc/rpc.h>
|
||||||
|
#include <rpcsvc/yp_prot.h>
|
||||||
|
#include <rpcsvc/ypclnt.h>
|
||||||
|
static int serv_stepping_yp = 0;
|
||||||
|
extern int _yp_check __P(( char ** ));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define MAXALIASES 35
|
||||||
|
|
||||||
|
static FILE *servf = NULL;
|
||||||
|
static char line[BUFSIZ+1];
|
||||||
|
static struct servent serv;
|
||||||
|
static char *serv_aliases[MAXALIASES];
|
||||||
|
int _serv_stayopen;
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
char *___getservbyname_yp = NULL;
|
||||||
|
char *___getservbyproto_yp = NULL;
|
||||||
|
int ___getservbyport_yp = 0;
|
||||||
|
static char *yp_domain = NULL;
|
||||||
|
|
||||||
|
static int
|
||||||
|
_getservbyport_yp(line)
|
||||||
|
char *line;
|
||||||
|
{
|
||||||
|
char *result;
|
||||||
|
int resultlen;
|
||||||
|
char buf[YPMAXRECORD + 2];
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp),
|
||||||
|
___getservbyproto_yp);
|
||||||
|
|
||||||
|
___getservbyport_yp = 0;
|
||||||
|
___getservbyproto_yp = NULL;
|
||||||
|
|
||||||
|
if(!yp_domain) {
|
||||||
|
if(yp_get_default_domain(&yp_domain))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We have to be a little flexible here. Ideally you're supposed
|
||||||
|
* to have both a services.byname and a services.byport map, but
|
||||||
|
* some systems have only services.byname. FreeBSD cheats a little
|
||||||
|
* by putting the services.byport information in the same map as
|
||||||
|
* services.byname so that either case will work. We allow for both
|
||||||
|
* possibilities here: if there is no services.byport map, we try
|
||||||
|
* services.byname instead.
|
||||||
|
*/
|
||||||
|
if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf),
|
||||||
|
&result, &resultlen))) {
|
||||||
|
if (rv == YPERR_MAP) {
|
||||||
|
if (yp_match(yp_domain, "services.byname", buf,
|
||||||
|
strlen(buf), &result, &resultlen))
|
||||||
|
return(0);
|
||||||
|
} else
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* getservent() expects lines terminated with \n -- make it happy */
|
||||||
|
snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_getservbyname_yp(line)
|
||||||
|
char *line;
|
||||||
|
{
|
||||||
|
char *result;
|
||||||
|
int resultlen;
|
||||||
|
char buf[YPMAXRECORD + 2];
|
||||||
|
|
||||||
|
if(!yp_domain) {
|
||||||
|
if(yp_get_default_domain(&yp_domain))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp,
|
||||||
|
___getservbyproto_yp);
|
||||||
|
|
||||||
|
___getservbyname_yp = 0;
|
||||||
|
___getservbyproto_yp = NULL;
|
||||||
|
|
||||||
|
if (yp_match(yp_domain, "services.byname", buf, strlen(buf),
|
||||||
|
&result, &resultlen)) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* getservent() expects lines terminated with \n -- make it happy */
|
||||||
|
snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
_getservent_yp(line)
|
||||||
|
char *line;
|
||||||
|
{
|
||||||
|
static char *key = NULL;
|
||||||
|
static int keylen;
|
||||||
|
char *lastkey, *result;
|
||||||
|
int resultlen;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
if(!yp_domain) {
|
||||||
|
if(yp_get_default_domain(&yp_domain))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!serv_stepping_yp) {
|
||||||
|
if (key)
|
||||||
|
free(key);
|
||||||
|
if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
|
||||||
|
&result, &resultlen))) {
|
||||||
|
serv_stepping_yp = 0;
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
serv_stepping_yp = 1;
|
||||||
|
} else {
|
||||||
|
lastkey = key;
|
||||||
|
rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
|
||||||
|
&keylen, &result, &resultlen);
|
||||||
|
free(lastkey);
|
||||||
|
if (rv) {
|
||||||
|
serv_stepping_yp = 0;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* getservent() expects lines terminated with \n -- make it happy */
|
||||||
|
snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
|
||||||
|
|
||||||
|
free(result);
|
||||||
|
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
setservent(int f)
|
||||||
|
{
|
||||||
|
if (servf == NULL)
|
||||||
|
servf = fopen(_PATH_SERVICES, "r" );
|
||||||
|
else
|
||||||
|
rewind(servf);
|
||||||
|
_serv_stayopen |= f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
endservent()
|
||||||
|
{
|
||||||
|
if (servf) {
|
||||||
|
fclose(servf);
|
||||||
|
servf = NULL;
|
||||||
|
}
|
||||||
|
_serv_stayopen = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct servent *
|
||||||
|
getservent()
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
register char *cp, **q;
|
||||||
|
|
||||||
|
#ifdef YP
|
||||||
|
if (serv_stepping_yp && _getservent_yp(line)) {
|
||||||
|
p = (char *)&line;
|
||||||
|
goto unpack;
|
||||||
|
}
|
||||||
|
tryagain:
|
||||||
|
#endif
|
||||||
|
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
again:
|
||||||
|
if ((p = fgets(line, BUFSIZ, servf)) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
#ifdef YP
|
||||||
|
if (*p == '+' && _yp_check(NULL)) {
|
||||||
|
if (___getservbyname_yp != NULL) {
|
||||||
|
if (!_getservbyname_yp(line))
|
||||||
|
goto tryagain;
|
||||||
|
}
|
||||||
|
else if (___getservbyport_yp != 0) {
|
||||||
|
if (!_getservbyport_yp(line))
|
||||||
|
goto tryagain;
|
||||||
|
}
|
||||||
|
else if (!_getservent_yp(line))
|
||||||
|
goto tryagain;
|
||||||
|
}
|
||||||
|
unpack:
|
||||||
|
#endif
|
||||||
|
if (*p == '#')
|
||||||
|
goto again;
|
||||||
|
cp = strpbrk(p, "#\n");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp = '\0';
|
||||||
|
serv.s_name = p;
|
||||||
|
p = strpbrk(p, " \t");
|
||||||
|
if (p == NULL)
|
||||||
|
goto again;
|
||||||
|
*p++ = '\0';
|
||||||
|
while (*p == ' ' || *p == '\t')
|
||||||
|
p++;
|
||||||
|
cp = strpbrk(p, ",/");
|
||||||
|
if (cp == NULL)
|
||||||
|
goto again;
|
||||||
|
*cp++ = '\0';
|
||||||
|
serv.s_port = htons((u_short)atoi(p));
|
||||||
|
serv.s_proto = cp;
|
||||||
|
q = serv.s_aliases = serv_aliases;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
while (cp && *cp) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
cp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (q < &serv_aliases[MAXALIASES - 1])
|
||||||
|
*q++ = cp;
|
||||||
|
cp = strpbrk(cp, " \t");
|
||||||
|
if (cp != NULL)
|
||||||
|
*cp++ = '\0';
|
||||||
|
}
|
||||||
|
*q = NULL;
|
||||||
|
return (&serv);
|
||||||
|
}
|
73
StdLib/BsdSocketLib/getsockname.c
Normal file
73
StdLib/BsdSocketLib/getsockname.c
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the getsockname API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the local socket address.
|
||||||
|
|
||||||
|
The ::getsockname routine retrieves the local system address from the socket.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockname.html#">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [out] address Network address to receive the local system address
|
||||||
|
|
||||||
|
@param [in] address_len Length of the local network address structure
|
||||||
|
|
||||||
|
@returns ::getsockname returns zero (0) if successful or -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
getsockname (
|
||||||
|
int s,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int RetVal;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
RetVal = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Get the local socket address
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnGetLocal ( pSocketProtocol,
|
||||||
|
address,
|
||||||
|
address_len,
|
||||||
|
&errno );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
RetVal = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation status
|
||||||
|
//
|
||||||
|
return RetVal;
|
||||||
|
}
|
66
StdLib/BsdSocketLib/getsockopt.c
Normal file
66
StdLib/BsdSocketLib/getsockopt.c
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the getsockopt API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the socket options
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
@param [in] level Option protocol level
|
||||||
|
@param [in] option_name Name of the option
|
||||||
|
@param [out] option_value Buffer to receive the option value
|
||||||
|
@param [in,out] option_len Length of the buffer in bytes,
|
||||||
|
upon return length of the option value in bytes
|
||||||
|
|
||||||
|
@retval Zero (0) upon success
|
||||||
|
@retval Minus one (-1) upon failure, errno set with additional error information
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
getsockopt (
|
||||||
|
IN int s,
|
||||||
|
IN int level,
|
||||||
|
IN int option_name,
|
||||||
|
OUT void * __restrict option_value,
|
||||||
|
IN OUT socklen_t * __restrict option_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int OptionStatus;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Get the socket option
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnOptionGet ( pSocketProtocol,
|
||||||
|
level,
|
||||||
|
option_name,
|
||||||
|
option_value,
|
||||||
|
option_len,
|
||||||
|
&errno );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation stauts
|
||||||
|
//
|
||||||
|
OptionStatus = ( 0 == errno ) ? 0 : -1;
|
||||||
|
return OptionStatus;
|
||||||
|
}
|
134
StdLib/BsdSocketLib/herror.c
Normal file
134
StdLib/BsdSocketLib/herror.c
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1987, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char rcsid[] = "$Id: herror.c,v 1.1.1.1 2003/11/19 01:51:28 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
const char *h_errlist[] = {
|
||||||
|
"Resolver Error 0 (no error)",
|
||||||
|
"Unknown host", /* 1 HOST_NOT_FOUND */
|
||||||
|
"Host name lookup failure", /* 2 TRY_AGAIN */
|
||||||
|
"Unknown server error", /* 3 NO_RECOVERY */
|
||||||
|
"No address associated with name", /* 4 NO_ADDRESS */
|
||||||
|
};
|
||||||
|
int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
|
||||||
|
|
||||||
|
int h_errno;
|
||||||
|
|
||||||
|
const char *
|
||||||
|
hstrerror(
|
||||||
|
int err
|
||||||
|
);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* herror --
|
||||||
|
* print the error indicated by the h_errno value.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
herror(
|
||||||
|
const char *s
|
||||||
|
)
|
||||||
|
{
|
||||||
|
struct iovec iov[4];
|
||||||
|
register struct iovec *v = iov;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
if (s && *s) {
|
||||||
|
v->iov_base = (char *)s;
|
||||||
|
v->iov_len = strlen(s);
|
||||||
|
v++;
|
||||||
|
v->iov_base = ": ";
|
||||||
|
v->iov_len = 2;
|
||||||
|
v++;
|
||||||
|
}
|
||||||
|
v->iov_base = (char *)hstrerror(h_errno);
|
||||||
|
v->iov_len = strlen(v->iov_base);
|
||||||
|
v++;
|
||||||
|
v->iov_base = "\n";
|
||||||
|
v->iov_len = 1;
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
writev(STDERR_FILENO, iov, (v - iov) + 1);
|
||||||
|
#else
|
||||||
|
for (i = 0; i < (v - iov) + 1; i++)
|
||||||
|
fprintf( stderr, iov[i].iov_base);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
hstrerror(
|
||||||
|
int err
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (err < 0)
|
||||||
|
return ("Resolver internal error");
|
||||||
|
else if (err < h_nerr)
|
||||||
|
return (h_errlist[err]);
|
||||||
|
return ("Unknown resolver error");
|
||||||
|
}
|
142
StdLib/BsdSocketLib/inet_net_ntop.c
Normal file
142
StdLib/BsdSocketLib/inet_net_ntop.c
Normal file
@ -0,0 +1,142 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static const char orig_rcsid[] = "From Id: inet_net_ntop.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
|
||||||
|
static const char rcsid[] = "$Id: inet_net_ntop.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef SPRINTF_CHAR
|
||||||
|
# define SPRINTF(x) strlen(sprintf/**/x)
|
||||||
|
#else
|
||||||
|
# define SPRINTF(x) ((size_t)sprintf x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static char * inet_net_ntop_ipv4 (const u_char *src, int bits,
|
||||||
|
char *dst, size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* char *
|
||||||
|
* inet_net_ntop(af, src, bits, dst, size)
|
||||||
|
* convert network number from network to presentation format.
|
||||||
|
* generates CIDR style result always.
|
||||||
|
* return:
|
||||||
|
* pointer to dst, or NULL if an error occurred (check errno).
|
||||||
|
* author:
|
||||||
|
* Paul Vixie (ISC), July 1996
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
inet_net_ntop(
|
||||||
|
int af,
|
||||||
|
const void *src,
|
||||||
|
int bits,
|
||||||
|
char *dst,
|
||||||
|
size_t size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
return (inet_net_ntop_ipv4(src, bits, dst, size));
|
||||||
|
default:
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static char *
|
||||||
|
* inet_net_ntop_ipv4(src, bits, dst, size)
|
||||||
|
* convert IPv4 network number from network to presentation format.
|
||||||
|
* generates CIDR style result always.
|
||||||
|
* return:
|
||||||
|
* pointer to dst, or NULL if an error occurred (check errno).
|
||||||
|
* note:
|
||||||
|
* network byte order assumed. this means 192.5.5.240/28 has
|
||||||
|
* 0x11110000 in its fourth octet.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie (ISC), July 1996
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
inet_net_ntop_ipv4(
|
||||||
|
const u_char *src,
|
||||||
|
int bits,
|
||||||
|
char *dst,
|
||||||
|
size_t size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char *odst = dst;
|
||||||
|
char *t;
|
||||||
|
u_int m;
|
||||||
|
int b;
|
||||||
|
|
||||||
|
if (bits < 0 || bits > 32) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
if (bits == 0) {
|
||||||
|
if (size < sizeof "0")
|
||||||
|
goto emsgsize;
|
||||||
|
*dst++ = '0';
|
||||||
|
*dst = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format whole octets. */
|
||||||
|
for (b = bits / 8; b > 0; b--) {
|
||||||
|
if (size < sizeof "255.")
|
||||||
|
goto emsgsize;
|
||||||
|
t = dst;
|
||||||
|
dst += SPRINTF((dst, "%u", *src++));
|
||||||
|
if (b > 1) {
|
||||||
|
*dst++ = '.';
|
||||||
|
*dst = '\0';
|
||||||
|
}
|
||||||
|
size -= (size_t)(dst - t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format partial octet. */
|
||||||
|
b = bits % 8;
|
||||||
|
if (b > 0) {
|
||||||
|
if (size < sizeof ".255")
|
||||||
|
goto emsgsize;
|
||||||
|
t = dst;
|
||||||
|
if (dst != odst)
|
||||||
|
*dst++ = '.';
|
||||||
|
m = ((1 << b) - 1) << (8 - b);
|
||||||
|
dst += SPRINTF((dst, "%u", *src & m));
|
||||||
|
size -= (size_t)(dst - t);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Format CIDR /width. */
|
||||||
|
if (size < sizeof "/32")
|
||||||
|
goto emsgsize;
|
||||||
|
dst += SPRINTF((dst, "/%u", bits));
|
||||||
|
return (odst);
|
||||||
|
|
||||||
|
emsgsize:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (NULL);
|
||||||
|
}
|
252
StdLib/BsdSocketLib/inet_net_pton.c
Normal file
252
StdLib/BsdSocketLib/inet_net_pton.c
Normal file
@ -0,0 +1,252 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static const char orig_rcsid[] = "From Id: inet_net_pton.c,v 1.8 1996/11/21 10:28:12 vixie Exp $";
|
||||||
|
static const char rcsid[] = "$Id: inet_net_pton.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifdef SPRINTF_CHAR
|
||||||
|
# define SPRINTF(x) strlen(sprintf/**/x)
|
||||||
|
#else
|
||||||
|
# define SPRINTF(x) ((size_t)sprintf x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int inet_net_pton_ipv4 (const char *src, u_char *dst,
|
||||||
|
size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static int
|
||||||
|
* inet_net_pton(af, src, dst, size)
|
||||||
|
* convert network number from presentation to network format.
|
||||||
|
* accepts hex octets, hex strings, decimal octets, and /CIDR.
|
||||||
|
* "size" is in bytes and describes "dst".
|
||||||
|
* return:
|
||||||
|
* number of bits, either imputed classfully or specified with /CIDR,
|
||||||
|
* or -1 if some failure occurred (check errno). ENOENT means it was
|
||||||
|
* not a valid network specification.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie (ISC), June 1996
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
inet_net_pton(
|
||||||
|
int af,
|
||||||
|
const char *src,
|
||||||
|
void *dst,
|
||||||
|
size_t size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
return (inet_net_pton_ipv4(src, dst, size));
|
||||||
|
default:
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* static int
|
||||||
|
* inet_net_pton_ipv4(src, dst, size)
|
||||||
|
* convert IPv4 network number from presentation to network format.
|
||||||
|
* accepts hex octets, hex strings, decimal octets, and /CIDR.
|
||||||
|
* "size" is in bytes and describes "dst".
|
||||||
|
* return:
|
||||||
|
* number of bits, either imputed classfully or specified with /CIDR,
|
||||||
|
* or -1 if some failure occurred (check errno). ENOENT means it was
|
||||||
|
* not an IPv4 network specification.
|
||||||
|
* note:
|
||||||
|
* network byte order assumed. this means 192.5.5.240/28 has
|
||||||
|
* 0x11110000 in its fourth octet.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie (ISC), June 1996
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
inet_net_pton_ipv4(
|
||||||
|
const char *src,
|
||||||
|
u_char *dst,
|
||||||
|
size_t size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static const char xdigits[] = "0123456789abcdef";
|
||||||
|
static const char digits[] = "0123456789";
|
||||||
|
int n;
|
||||||
|
int ch;
|
||||||
|
int tmp;
|
||||||
|
int dirty;
|
||||||
|
int bits;
|
||||||
|
const u_char *odst = dst;
|
||||||
|
|
||||||
|
ch = *src++;
|
||||||
|
if (ch == '0' && (src[0] == 'x' || src[0] == 'X')
|
||||||
|
&& isascii(src[1]) && isxdigit(src[1])) {
|
||||||
|
/* Hexadecimal: Eat nybble string. */
|
||||||
|
if (size <= 0)
|
||||||
|
goto emsgsize;
|
||||||
|
*dst = 0, dirty = 0;
|
||||||
|
src++; /* skip x or X. */
|
||||||
|
while ((ch = *src++) != '\0' &&
|
||||||
|
isascii(ch) && isxdigit(ch)) {
|
||||||
|
if (isupper(ch))
|
||||||
|
ch = tolower(ch);
|
||||||
|
n = (int)(strchr(xdigits, ch) - xdigits);
|
||||||
|
assert(n >= 0 && n <= 15);
|
||||||
|
*dst |= n;
|
||||||
|
if (!dirty++)
|
||||||
|
*dst <<= 4;
|
||||||
|
else if (size-- > 0)
|
||||||
|
*++dst = 0, dirty = 0;
|
||||||
|
else
|
||||||
|
goto emsgsize;
|
||||||
|
}
|
||||||
|
if (dirty)
|
||||||
|
size--;
|
||||||
|
} else if (isascii(ch) && isdigit(ch)) {
|
||||||
|
/* Decimal: eat dotted digit string. */
|
||||||
|
for (;;) {
|
||||||
|
tmp = 0;
|
||||||
|
do {
|
||||||
|
n = (int)(strchr(digits, ch) - digits);
|
||||||
|
assert(n >= 0 && n <= 9);
|
||||||
|
tmp *= 10;
|
||||||
|
tmp += n;
|
||||||
|
if (tmp > 255)
|
||||||
|
goto enoent;
|
||||||
|
} while ((ch = *src++) != '\0' &&
|
||||||
|
isascii(ch) && isdigit(ch));
|
||||||
|
if (size-- <= 0)
|
||||||
|
goto emsgsize;
|
||||||
|
*dst++ = (u_char) tmp;
|
||||||
|
if (ch == '\0' || ch == '/')
|
||||||
|
break;
|
||||||
|
if (ch != '.')
|
||||||
|
goto enoent;
|
||||||
|
ch = *src++;
|
||||||
|
if (!isascii(ch) || !isdigit(ch))
|
||||||
|
goto enoent;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
goto enoent;
|
||||||
|
|
||||||
|
bits = -1;
|
||||||
|
if (ch == '/' && isascii(src[0]) && isdigit(src[0]) && dst > odst) {
|
||||||
|
/* CIDR width specifier. Nothing can follow it. */
|
||||||
|
ch = *src++; /* Skip over the /. */
|
||||||
|
bits = 0;
|
||||||
|
do {
|
||||||
|
n = (int)(strchr(digits, ch) - digits);
|
||||||
|
assert(n >= 0 && n <= 9);
|
||||||
|
bits *= 10;
|
||||||
|
bits += n;
|
||||||
|
} while ((ch = *src++) != '\0' && isascii(ch) && isdigit(ch));
|
||||||
|
if (ch != '\0')
|
||||||
|
goto enoent;
|
||||||
|
if (bits > 32)
|
||||||
|
goto emsgsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Firey death and destruction unless we prefetched EOS. */
|
||||||
|
if (ch != '\0')
|
||||||
|
goto enoent;
|
||||||
|
|
||||||
|
/* If nothing was written to the destination, we found no address. */
|
||||||
|
if (dst == odst)
|
||||||
|
goto enoent;
|
||||||
|
/* If no CIDR spec was given, infer width from net class. */
|
||||||
|
if (bits == -1) {
|
||||||
|
if (*odst >= 240) /* Class E */
|
||||||
|
bits = 32;
|
||||||
|
else if (*odst >= 224) /* Class D */
|
||||||
|
bits = 4;
|
||||||
|
else if (*odst >= 192) /* Class C */
|
||||||
|
bits = 24;
|
||||||
|
else if (*odst >= 128) /* Class B */
|
||||||
|
bits = 16;
|
||||||
|
else /* Class A */
|
||||||
|
bits = 8;
|
||||||
|
/* If imputed mask is narrower than specified octets, widen. */
|
||||||
|
if (bits >= 8 && bits < ((dst - odst) * 8))
|
||||||
|
bits = (int)(dst - odst) * 8;
|
||||||
|
}
|
||||||
|
/* Extend network to cover the actual mask. */
|
||||||
|
while (bits > ((dst - odst) * 8)) {
|
||||||
|
if (size-- <= 0)
|
||||||
|
goto emsgsize;
|
||||||
|
*dst++ = '\0';
|
||||||
|
}
|
||||||
|
return (bits);
|
||||||
|
|
||||||
|
enoent:
|
||||||
|
errno = ENOENT;
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
emsgsize:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
125
StdLib/BsdSocketLib/inet_neta.c
Normal file
125
StdLib/BsdSocketLib/inet_neta.c
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static const char orig_rcsid[] = "From Id: inet_neta.c,v 8.2 1996/08/08 06:54:44 vixie Exp";
|
||||||
|
static const char rcsid[] = "$Id: inet_neta.c,v 1.1.1.1 2003/11/19 01:51:29 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef SPRINTF_CHAR
|
||||||
|
# define SPRINTF(x) strlen(sprintf/**/x)
|
||||||
|
#else
|
||||||
|
# define SPRINTF(x) ((size_t)sprintf x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* char *
|
||||||
|
* inet_neta(src, dst, size)
|
||||||
|
* format a u_long network number into presentation format.
|
||||||
|
* return:
|
||||||
|
* pointer to dst, or NULL if an error occurred (check errno).
|
||||||
|
* note:
|
||||||
|
* format of ``src'' is as for inet_network().
|
||||||
|
* author:
|
||||||
|
* Paul Vixie (ISC), July 1996
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
inet_neta(
|
||||||
|
u_long src,
|
||||||
|
char *dst,
|
||||||
|
size_t size
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char *odst = dst;
|
||||||
|
char *tp;
|
||||||
|
|
||||||
|
while (src & 0xffffffff) {
|
||||||
|
u_char b = (u_char)((src & 0xff000000) >> 24);
|
||||||
|
|
||||||
|
src <<= 8;
|
||||||
|
if (b) {
|
||||||
|
if (size < sizeof "255.")
|
||||||
|
goto emsgsize;
|
||||||
|
tp = dst;
|
||||||
|
dst += SPRINTF((dst, "%u", b));
|
||||||
|
if (src != 0L) {
|
||||||
|
*dst++ = '.';
|
||||||
|
*dst = '\0';
|
||||||
|
}
|
||||||
|
size -= (size_t)(dst - tp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dst == odst) {
|
||||||
|
if (size < sizeof "0.0.0.0")
|
||||||
|
goto emsgsize;
|
||||||
|
strcpy(dst, "0.0.0.0");
|
||||||
|
}
|
||||||
|
return (odst);
|
||||||
|
|
||||||
|
emsgsize:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (NULL);
|
||||||
|
}
|
257
StdLib/BsdSocketLib/inet_pton.c
Normal file
257
StdLib/BsdSocketLib/inet_pton.c
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
/* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char rcsid[] = "$Id: inet_pton.c,v 1.1.1.1 2003/11/19 01:51:30 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WARNING: Don't even consider trying to compile this on a system where
|
||||||
|
* sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int inet_pton4 (const char *src, u_char *dst);
|
||||||
|
static int inet_pton6 (const char *src, u_char *dst);
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* inet_pton(af, src, dst)
|
||||||
|
* convert from presentation format (which usually means ASCII printable)
|
||||||
|
* to network format (which is usually some kind of binary format).
|
||||||
|
* return:
|
||||||
|
* 1 if the address was valid for the specified address family
|
||||||
|
* 0 if the address wasn't valid (`dst' is untouched in this case)
|
||||||
|
* -1 if some other error occurred (`dst' is untouched in this case, too)
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
inet_pton(
|
||||||
|
int af,
|
||||||
|
const char *src,
|
||||||
|
void *dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
switch (af) {
|
||||||
|
case AF_INET:
|
||||||
|
return (inet_pton4(src, dst));
|
||||||
|
case AF_INET6:
|
||||||
|
return (inet_pton6(src, dst));
|
||||||
|
default:
|
||||||
|
errno = EAFNOSUPPORT;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
/* NOTREACHED */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* inet_pton4(src, dst)
|
||||||
|
* like inet_aton() but without all the hexadecimal and shorthand.
|
||||||
|
* return:
|
||||||
|
* 1 if `src' is a valid dotted quad, else 0.
|
||||||
|
* notice:
|
||||||
|
* does not touch `dst' unless it's returning 1.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
inet_pton4(
|
||||||
|
const char *src,
|
||||||
|
u_char *dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static const char digits[] = "0123456789";
|
||||||
|
int saw_digit, octets, ch;
|
||||||
|
u_char tmp[NS_INADDRSZ], *tp;
|
||||||
|
|
||||||
|
saw_digit = 0;
|
||||||
|
octets = 0;
|
||||||
|
*(tp = tmp) = 0;
|
||||||
|
while ((ch = *src++) != '\0') {
|
||||||
|
const char *pch;
|
||||||
|
|
||||||
|
if ((pch = strchr(digits, ch)) != NULL) {
|
||||||
|
u_int new = *tp * 10 + (u_int)(pch - digits);
|
||||||
|
|
||||||
|
if (new > 255)
|
||||||
|
return (0);
|
||||||
|
*tp = (u_char)new;
|
||||||
|
if (! saw_digit) {
|
||||||
|
if (++octets > 4)
|
||||||
|
return (0);
|
||||||
|
saw_digit = 1;
|
||||||
|
}
|
||||||
|
} else if (ch == '.' && saw_digit) {
|
||||||
|
if (octets == 4)
|
||||||
|
return (0);
|
||||||
|
*++tp = 0;
|
||||||
|
saw_digit = 0;
|
||||||
|
} else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (octets < 4)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
memcpy(dst, tmp, NS_INADDRSZ);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* inet_pton6(src, dst)
|
||||||
|
* convert presentation level address to network order binary form.
|
||||||
|
* return:
|
||||||
|
* 1 if `src' is a valid [RFC1884 2.2] address, else 0.
|
||||||
|
* notice:
|
||||||
|
* (1) does not touch `dst' unless it's returning 1.
|
||||||
|
* (2) :: in a full address is silently ignored.
|
||||||
|
* credit:
|
||||||
|
* inspired by Mark Andrews.
|
||||||
|
* author:
|
||||||
|
* Paul Vixie, 1996.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
inet_pton6(
|
||||||
|
const char *src,
|
||||||
|
u_char *dst
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static const char xdigits_l[] = "0123456789abcdef",
|
||||||
|
xdigits_u[] = "0123456789ABCDEF";
|
||||||
|
u_char tmp[NS_IN6ADDRSZ], *tp, *endp, *colonp;
|
||||||
|
const char *xdigits, *curtok;
|
||||||
|
int ch, saw_xdigit;
|
||||||
|
u_int val;
|
||||||
|
|
||||||
|
memset((tp = tmp), '\0', NS_IN6ADDRSZ);
|
||||||
|
endp = tp + NS_IN6ADDRSZ;
|
||||||
|
colonp = NULL;
|
||||||
|
/* Leading :: requires some special handling. */
|
||||||
|
if (*src == ':')
|
||||||
|
if (*++src != ':')
|
||||||
|
return (0);
|
||||||
|
curtok = src;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
val = 0;
|
||||||
|
while ((ch = *src++) != '\0') {
|
||||||
|
const char *pch;
|
||||||
|
|
||||||
|
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
|
||||||
|
pch = strchr((xdigits = xdigits_u), ch);
|
||||||
|
if (pch != NULL) {
|
||||||
|
val <<= 4;
|
||||||
|
val |= (pch - xdigits);
|
||||||
|
if (val > 0xffff)
|
||||||
|
return (0);
|
||||||
|
saw_xdigit = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch == ':') {
|
||||||
|
curtok = src;
|
||||||
|
if (!saw_xdigit) {
|
||||||
|
if (colonp)
|
||||||
|
return (0);
|
||||||
|
colonp = tp;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (tp + NS_INT16SZ > endp)
|
||||||
|
return (0);
|
||||||
|
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||||
|
*tp++ = (u_char) val & 0xff;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
val = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (ch == '.' && ((tp + NS_INADDRSZ) <= endp) &&
|
||||||
|
inet_pton4(curtok, tp) > 0) {
|
||||||
|
tp += NS_INADDRSZ;
|
||||||
|
saw_xdigit = 0;
|
||||||
|
break; /* '\0' was seen by inet_pton4(). */
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
if (saw_xdigit) {
|
||||||
|
if (tp + NS_INT16SZ > endp)
|
||||||
|
return (0);
|
||||||
|
*tp++ = (u_char) (val >> 8) & 0xff;
|
||||||
|
*tp++ = (u_char) val & 0xff;
|
||||||
|
}
|
||||||
|
if (colonp != NULL) {
|
||||||
|
/*
|
||||||
|
* Since some memmove()'s erroneously fail to handle
|
||||||
|
* overlapping regions, we'll do the shift by hand.
|
||||||
|
*/
|
||||||
|
const int n = (int)(tp - colonp);
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 1; i <= n; i++) {
|
||||||
|
endp[- i] = colonp[n - i];
|
||||||
|
colonp[n - i] = 0;
|
||||||
|
}
|
||||||
|
tp = endp;
|
||||||
|
}
|
||||||
|
if (tp != endp)
|
||||||
|
return (0);
|
||||||
|
memcpy(dst, tmp, NS_IN6ADDRSZ);
|
||||||
|
return (1);
|
||||||
|
}
|
65
StdLib/BsdSocketLib/listen.c
Normal file
65
StdLib/BsdSocketLib/listen.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the listen API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Establish the known port to listen for network connections.
|
||||||
|
|
||||||
|
The ::listen routine places the port into a state that enables connection
|
||||||
|
attempts. Connections are placed into FIFO order in a queue to be serviced
|
||||||
|
by the application. The application calls the ::accept routine to remove
|
||||||
|
the next connection from the queue and get the associated socket. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
|
||||||
|
documentation for the bind routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] backlog backlog specifies the maximum FIFO depth for the connections
|
||||||
|
waiting for the application to call accept. Connection attempts
|
||||||
|
received while the queue is full are refused.
|
||||||
|
|
||||||
|
@returns The listen routine returns zero (0) if successful and -1 upon failure.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
listen (
|
||||||
|
IN int s,
|
||||||
|
IN int backlog
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int ListenStatus;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Enable connections on the known port
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnListen ( pSocketProtocol,
|
||||||
|
backlog,
|
||||||
|
&errno );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation stauts
|
||||||
|
//
|
||||||
|
ListenStatus = ( 0 == errno ) ? 0 : -1;
|
||||||
|
return ListenStatus;
|
||||||
|
}
|
135
StdLib/BsdSocketLib/map_v4v6.c
Normal file
135
StdLib/BsdSocketLib/map_v4v6.c
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* ++Copyright++ 1985, 1988, 1993
|
||||||
|
* -
|
||||||
|
* Copyright (c) 1985, 1988, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
* -
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
* -
|
||||||
|
* --Copyright--
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char rcsid[] = "$Id: map_v4v6.c,v 1.1.1.1 2003/11/19 01:51:31 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
#include <syslog.h>
|
||||||
|
#endif
|
||||||
|
#include "Socklib_internals.h"
|
||||||
|
|
||||||
|
typedef union {
|
||||||
|
int32_t al;
|
||||||
|
char ac;
|
||||||
|
} align;
|
||||||
|
|
||||||
|
void
|
||||||
|
_map_v4v6_address(const char *src, char *dst)
|
||||||
|
{
|
||||||
|
u_char *p = (u_char *)dst;
|
||||||
|
char tmp[INADDRSZ];
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* Stash a temporary copy so our caller can update in place. */
|
||||||
|
bcopy(src, tmp, INADDRSZ);
|
||||||
|
/* Mark this ipv6 addr as a mapped ipv4. */
|
||||||
|
for (i = 0; i < 10; i++)
|
||||||
|
*p++ = 0x00;
|
||||||
|
*p++ = 0xff;
|
||||||
|
*p++ = 0xff;
|
||||||
|
/* Retrieve the saved copy and we're done. */
|
||||||
|
bcopy(tmp, (void*)p, INADDRSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp)
|
||||||
|
{
|
||||||
|
char **ap;
|
||||||
|
|
||||||
|
if (hp->h_addrtype != AF_INET || hp->h_length != INADDRSZ)
|
||||||
|
return;
|
||||||
|
hp->h_addrtype = AF_INET6;
|
||||||
|
hp->h_length = IN6ADDRSZ;
|
||||||
|
for (ap = hp->h_addr_list; *ap; ap++) {
|
||||||
|
int i = (int)(sizeof(align) - ((size_t)*bpp % sizeof(align)));
|
||||||
|
|
||||||
|
if (*lenp < (i + IN6ADDRSZ)) {
|
||||||
|
/* Out of memory. Truncate address list here. XXX */
|
||||||
|
*ap = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
*bpp += i;
|
||||||
|
*lenp -= i;
|
||||||
|
_map_v4v6_address(*ap, *bpp);
|
||||||
|
*ap = *bpp;
|
||||||
|
*bpp += IN6ADDRSZ;
|
||||||
|
*lenp -= IN6ADDRSZ;
|
||||||
|
}
|
||||||
|
}
|
240
StdLib/BsdSocketLib/ns_addr.c
Normal file
240
StdLib/BsdSocketLib/ns_addr.c
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1986, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to Berkeley by
|
||||||
|
* J.Q. Johnson.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)ns_addr.c 8.1 (Berkeley) 6/7/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <netns/ns.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
static struct ns_addr addr, zero_addr;
|
||||||
|
|
||||||
|
static void Field(), cvtbase();
|
||||||
|
|
||||||
|
struct ns_addr
|
||||||
|
ns_addr(
|
||||||
|
const char *name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char separator;
|
||||||
|
char *hostname, *socketname, *cp;
|
||||||
|
char buf[50];
|
||||||
|
|
||||||
|
(void)strncpy(buf, name, sizeof(buf) - 1);
|
||||||
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* First, figure out what he intends as a field separtor.
|
||||||
|
* Despite the way this routine is written, the prefered
|
||||||
|
* form 2-272.AA001234H.01777, i.e. XDE standard.
|
||||||
|
* Great efforts are made to insure backward compatability.
|
||||||
|
*/
|
||||||
|
if ((hostname = strchr(buf, '#')) != NULL)
|
||||||
|
separator = '#';
|
||||||
|
else {
|
||||||
|
hostname = strchr(buf, '.');
|
||||||
|
if ((cp = strchr(buf, ':')) &&
|
||||||
|
((hostname && cp < hostname) || (hostname == 0))) {
|
||||||
|
hostname = cp;
|
||||||
|
separator = ':';
|
||||||
|
} else
|
||||||
|
separator = '.';
|
||||||
|
}
|
||||||
|
if (hostname)
|
||||||
|
*hostname++ = 0;
|
||||||
|
|
||||||
|
addr = zero_addr;
|
||||||
|
Field(buf, addr.x_net.c_net, 4);
|
||||||
|
if (hostname == 0)
|
||||||
|
return (addr); /* No separator means net only */
|
||||||
|
|
||||||
|
socketname = strchr(hostname, separator);
|
||||||
|
if (socketname) {
|
||||||
|
*socketname++ = 0;
|
||||||
|
Field(socketname, (u_char *)&addr.x_port, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Field(hostname, addr.x_host.c_host, 6);
|
||||||
|
|
||||||
|
return (addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Field(
|
||||||
|
char *buf,
|
||||||
|
u_char *out,
|
||||||
|
int len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
register char *bp = buf;
|
||||||
|
int i, ibase, base16 = 0, base10 = 0, clen = 0;
|
||||||
|
int hb[6], *hp;
|
||||||
|
char *fmt;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* first try 2-273#2-852-151-014#socket
|
||||||
|
*/
|
||||||
|
if ((*buf != '-') &&
|
||||||
|
(1 < (i = sscanf(buf, "%d-%d-%d-%d-%d",
|
||||||
|
&hb[0], &hb[1], &hb[2], &hb[3], &hb[4])))) {
|
||||||
|
cvtbase(1000L, 256, hb, i, out, len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* try form 8E1#0.0.AA.0.5E.E6#socket
|
||||||
|
*/
|
||||||
|
if (1 < (i = sscanf(buf,"%x.%x.%x.%x.%x.%x",
|
||||||
|
&hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
|
||||||
|
cvtbase(256L, 256, hb, i, out, len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* try form 8E1#0:0:AA:0:5E:E6#socket
|
||||||
|
*/
|
||||||
|
if (1 < (i = sscanf(buf,"%x:%x:%x:%x:%x:%x",
|
||||||
|
&hb[0], &hb[1], &hb[2], &hb[3], &hb[4], &hb[5]))) {
|
||||||
|
cvtbase(256L, 256, hb, i, out, len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* This is REALLY stretching it but there was a
|
||||||
|
* comma notation separting shorts -- definitely non standard
|
||||||
|
*/
|
||||||
|
if (1 < (i = sscanf(buf,"%x,%x,%x",
|
||||||
|
&hb[0], &hb[1], &hb[2]))) {
|
||||||
|
hb[0] = htons(hb[0]); hb[1] = htons(hb[1]);
|
||||||
|
hb[2] = htons(hb[2]);
|
||||||
|
cvtbase(65536L, 256, hb, i, out, len);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Need to decide if base 10, 16 or 8 */
|
||||||
|
while (*bp) switch (*bp++) {
|
||||||
|
|
||||||
|
case '0': case '1': case '2': case '3': case '4': case '5':
|
||||||
|
case '6': case '7': case '-':
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '8': case '9':
|
||||||
|
base10 = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||||
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||||
|
base16 = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'x': case 'X':
|
||||||
|
*--bp = '0';
|
||||||
|
base16 = 1;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'h': case 'H':
|
||||||
|
base16 = 1;
|
||||||
|
/* fall into */
|
||||||
|
|
||||||
|
default:
|
||||||
|
*--bp = 0; /* Ends Loop */
|
||||||
|
}
|
||||||
|
if (base16) {
|
||||||
|
fmt = "%3x";
|
||||||
|
ibase = 4096;
|
||||||
|
} else if (base10 == 0 && *buf == '0') {
|
||||||
|
fmt = "%3o";
|
||||||
|
ibase = 512;
|
||||||
|
} else {
|
||||||
|
fmt = "%3d";
|
||||||
|
ibase = 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (bp = buf; *bp++; ) clen++;
|
||||||
|
if (clen == 0) clen++;
|
||||||
|
if (clen > 18) clen = 18;
|
||||||
|
i = ((clen - 1) / 3) + 1;
|
||||||
|
bp = clen + buf - 3;
|
||||||
|
hp = hb + i - 1;
|
||||||
|
|
||||||
|
while (hp > hb) {
|
||||||
|
(void)sscanf(bp, fmt, hp);
|
||||||
|
bp[0] = 0;
|
||||||
|
hp--;
|
||||||
|
bp -= 3;
|
||||||
|
}
|
||||||
|
(void)sscanf(buf, fmt, hp);
|
||||||
|
cvtbase((long)ibase, 256, hb, i, out, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
cvtbase(
|
||||||
|
long oldbase,
|
||||||
|
int newbase,
|
||||||
|
int input[],
|
||||||
|
int inlen,
|
||||||
|
unsigned char result[],
|
||||||
|
int reslen
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int d, e;
|
||||||
|
long sum;
|
||||||
|
|
||||||
|
e = 1;
|
||||||
|
while (e > 0 && reslen > 0) {
|
||||||
|
d = 0; e = 0; sum = 0;
|
||||||
|
/* long division: input=input/newbase */
|
||||||
|
while (d < inlen) {
|
||||||
|
sum = sum*oldbase + (long) input[d];
|
||||||
|
e += (sum > 0);
|
||||||
|
input[d++] = sum / newbase;
|
||||||
|
sum %= newbase;
|
||||||
|
}
|
||||||
|
result[--reslen] = (u_char)sum; /* accumulate remainder */
|
||||||
|
}
|
||||||
|
for (d=0; d < reslen; d++)
|
||||||
|
result[d] = 0;
|
||||||
|
}
|
633
StdLib/BsdSocketLib/ns_name.c
Normal file
633
StdLib/BsdSocketLib/ns_name.c
Normal file
@ -0,0 +1,633 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "$Id: ns_name.c,v 1.1.1.1 2003/11/19 01:51:32 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* Data. */
|
||||||
|
|
||||||
|
static char digits[] = "0123456789";
|
||||||
|
|
||||||
|
/* Forward. */
|
||||||
|
|
||||||
|
static int special(int);
|
||||||
|
static int printable(int);
|
||||||
|
static int dn_find(const u_char *, const u_char *,
|
||||||
|
const u_char * const *,
|
||||||
|
const u_char * const *);
|
||||||
|
|
||||||
|
/* Public. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_ntop(src, dst, dstsiz)
|
||||||
|
* Convert an encoded domain name to printable ascii as per RFC1035.
|
||||||
|
* return:
|
||||||
|
* Number of bytes written to buffer, or -1 (with errno set)
|
||||||
|
* notes:
|
||||||
|
* The root is returned as "."
|
||||||
|
* All other domains are returned in non absolute form
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_name_ntop(const u_char *src, char *dst, size_t dstsiz) {
|
||||||
|
const u_char *cp;
|
||||||
|
char *dn, *eom;
|
||||||
|
u_char c;
|
||||||
|
u_int n;
|
||||||
|
|
||||||
|
cp = src;
|
||||||
|
dn = dst;
|
||||||
|
eom = dst + dstsiz;
|
||||||
|
|
||||||
|
while ((n = *cp++) != 0) {
|
||||||
|
if ((n & NS_CMPRSFLGS) != 0) {
|
||||||
|
/* Some kind of compression pointer. */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (dn != dst) {
|
||||||
|
if (dn >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dn++ = '.';
|
||||||
|
}
|
||||||
|
if (dn + n >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
for ((void)NULL; n > 0; n--) {
|
||||||
|
c = *cp++;
|
||||||
|
if (special(c)) {
|
||||||
|
if (dn + 1 >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dn++ = '\\';
|
||||||
|
*dn++ = (char)c;
|
||||||
|
} else if (!printable(c)) {
|
||||||
|
if (dn + 3 >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dn++ = '\\';
|
||||||
|
*dn++ = digits[c / 100];
|
||||||
|
*dn++ = digits[(c % 100) / 10];
|
||||||
|
*dn++ = digits[c % 10];
|
||||||
|
} else {
|
||||||
|
if (dn >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dn++ = (char)c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dn == dst) {
|
||||||
|
if (dn >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dn++ = '.';
|
||||||
|
}
|
||||||
|
if (dn >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dn++ = '\0';
|
||||||
|
return ((int)(dn - dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_pton(src, dst, dstsiz)
|
||||||
|
* Convert a ascii string into an encoded domain name as per RFC1035.
|
||||||
|
* return:
|
||||||
|
* -1 if it fails
|
||||||
|
* 1 if string was fully qualified
|
||||||
|
* 0 is string was not fully qualified
|
||||||
|
* notes:
|
||||||
|
* Enforces label and domain length limits.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int
|
||||||
|
ns_name_pton(const char *src, u_char *dst, size_t dstsiz) {
|
||||||
|
u_char *label, *bp, *eom;
|
||||||
|
int c, n, escaped;
|
||||||
|
char *cp;
|
||||||
|
|
||||||
|
escaped = 0;
|
||||||
|
bp = dst;
|
||||||
|
eom = dst + dstsiz;
|
||||||
|
label = bp++;
|
||||||
|
|
||||||
|
while ((c = *src++) != 0) {
|
||||||
|
if (escaped) {
|
||||||
|
if ((cp = strchr(digits, c)) != NULL) {
|
||||||
|
n = (int)(cp - digits) * 100;
|
||||||
|
if ((c = *src++) == 0 ||
|
||||||
|
(cp = strchr(digits, c)) == NULL) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
n += (int)(cp - digits) * 10;
|
||||||
|
if ((c = *src++) == 0 ||
|
||||||
|
(cp = strchr(digits, c)) == NULL) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
n += (int)(cp - digits);
|
||||||
|
if (n > 255) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
c = n;
|
||||||
|
}
|
||||||
|
escaped = 0;
|
||||||
|
} else if (c == '\\') {
|
||||||
|
escaped = 1;
|
||||||
|
continue;
|
||||||
|
} else if (c == '.') {
|
||||||
|
c = ((int)(bp - label) - 1);
|
||||||
|
if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (label >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*label = (u_char)c;
|
||||||
|
/* Fully qualified ? */
|
||||||
|
if (*src == '\0') {
|
||||||
|
if (c != 0) {
|
||||||
|
if (bp >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*bp++ = '\0';
|
||||||
|
}
|
||||||
|
if ((bp - dst) > MAXCDNAME) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
if (c == 0) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
label = bp++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (bp >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*bp++ = (u_char)c;
|
||||||
|
}
|
||||||
|
c = ((int)(bp - label) - 1);
|
||||||
|
if ((c & NS_CMPRSFLGS) != 0) { /* Label too big. */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (label >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*label = (u_char)c;
|
||||||
|
if (c != 0) {
|
||||||
|
if (bp >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*bp++ = 0;
|
||||||
|
}
|
||||||
|
if ((bp - dst) > MAXCDNAME) { /* src too big */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_unpack(msg, eom, src, dst, dstsiz)
|
||||||
|
* Unpack a domain name from a message, source may be compressed.
|
||||||
|
* return:
|
||||||
|
* -1 if it fails, or consumed octets if it succeeds.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_name_unpack(const u_char *msg, const u_char *eom, const u_char *src,
|
||||||
|
u_char *dst, size_t dstsiz)
|
||||||
|
{
|
||||||
|
const u_char *srcp, *dstlim;
|
||||||
|
u_char *dstp;
|
||||||
|
int n, len, checked;
|
||||||
|
|
||||||
|
len = -1;
|
||||||
|
checked = 0;
|
||||||
|
dstp = dst;
|
||||||
|
srcp = src;
|
||||||
|
dstlim = dst + dstsiz;
|
||||||
|
if (srcp < msg || srcp >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
/* Fetch next label in domain name. */
|
||||||
|
while ((n = *srcp++) != 0) {
|
||||||
|
/* Check for indirection. */
|
||||||
|
switch (n & NS_CMPRSFLGS) {
|
||||||
|
case 0:
|
||||||
|
/* Limit checks. */
|
||||||
|
if (dstp + n + 1 >= dstlim || srcp + n >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
checked += n + 1;
|
||||||
|
*dstp++ = (u_char)n;
|
||||||
|
memcpy(dstp, srcp, n);
|
||||||
|
dstp += n;
|
||||||
|
srcp += n;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NS_CMPRSFLGS:
|
||||||
|
if (srcp >= eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (len < 0)
|
||||||
|
len = (int)(srcp - src) + 1;
|
||||||
|
srcp = msg + (((n & 0x3f) << 8) | (*srcp & 0xff));
|
||||||
|
if (srcp < msg || srcp >= eom) { /* Out of range. */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
checked += 2;
|
||||||
|
/*
|
||||||
|
* Check for loops in the compressed name;
|
||||||
|
* if we've looked at the whole message,
|
||||||
|
* there must be a loop.
|
||||||
|
*/
|
||||||
|
if (checked >= eom - msg) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1); /* flag error */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dstp = '\0';
|
||||||
|
if (len < 0)
|
||||||
|
len = (int)(srcp - src);
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_pack(src, dst, dstsiz, dnptrs, lastdnptr)
|
||||||
|
* Pack domain name 'domain' into 'comp_dn'.
|
||||||
|
* return:
|
||||||
|
* Size of the compressed name, or -1.
|
||||||
|
* notes:
|
||||||
|
* 'dnptrs' is an array of pointers to previous compressed names.
|
||||||
|
* dnptrs[0] is a pointer to the beginning of the message. The array
|
||||||
|
* ends with NULL.
|
||||||
|
* 'lastdnptr' is a pointer to the end of the array pointed to
|
||||||
|
* by 'dnptrs'.
|
||||||
|
* Side effects:
|
||||||
|
* The list of pointers in dnptrs is updated for labels inserted into
|
||||||
|
* the message as we compress the name. If 'dnptr' is NULL, we don't
|
||||||
|
* try to compress names. If 'lastdnptr' is NULL, we don't update the
|
||||||
|
* list.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_name_pack(const u_char *src, u_char *dst, int dstsiz,
|
||||||
|
const u_char **dnptrs, const u_char **lastdnptr)
|
||||||
|
{
|
||||||
|
u_char *dstp;
|
||||||
|
const u_char **cpp, **lpp, *eob, *msg;
|
||||||
|
const u_char *srcp;
|
||||||
|
int n, l;
|
||||||
|
|
||||||
|
srcp = src;
|
||||||
|
dstp = dst;
|
||||||
|
eob = dstp + dstsiz;
|
||||||
|
lpp = cpp = NULL;
|
||||||
|
if (dnptrs != NULL) {
|
||||||
|
if ((msg = *dnptrs++) != NULL) {
|
||||||
|
for (cpp = dnptrs; *cpp != NULL; cpp++)
|
||||||
|
(void)NULL;
|
||||||
|
lpp = cpp; /* end of list to search */
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
msg = NULL;
|
||||||
|
|
||||||
|
/* make sure the domain we are about to add is legal */
|
||||||
|
l = 0;
|
||||||
|
do {
|
||||||
|
n = *srcp;
|
||||||
|
if ((n & NS_CMPRSFLGS) != 0) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
l += n + 1;
|
||||||
|
if (l > MAXCDNAME) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
srcp += n + 1;
|
||||||
|
} while (n != 0);
|
||||||
|
|
||||||
|
srcp = src;
|
||||||
|
do {
|
||||||
|
/* Look to see if we can use pointers. */
|
||||||
|
n = *srcp;
|
||||||
|
if (n != 0 && msg != NULL) {
|
||||||
|
l = dn_find(srcp, msg, (const u_char * const *)dnptrs,
|
||||||
|
(const u_char * const *)lpp);
|
||||||
|
if (l >= 0) {
|
||||||
|
if (dstp + 1 >= eob) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*dstp++ = (u_char)((l >> 8) | NS_CMPRSFLGS );
|
||||||
|
*dstp++ = (u_char)( l % 256 );
|
||||||
|
return ((int)(dstp - dst));
|
||||||
|
}
|
||||||
|
/* Not found, save it. */
|
||||||
|
if (lastdnptr != NULL && cpp < lastdnptr - 1 &&
|
||||||
|
(dstp - msg) < 0x4000) {
|
||||||
|
*cpp++ = dstp;
|
||||||
|
*cpp = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* copy label to buffer */
|
||||||
|
if (n & NS_CMPRSFLGS) { /* Should not happen. */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (dstp + 1 + n >= eob) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
memcpy(dstp, srcp, n + 1);
|
||||||
|
srcp += n + 1;
|
||||||
|
dstp += n + 1;
|
||||||
|
} while (n != 0);
|
||||||
|
|
||||||
|
if (dstp > eob) {
|
||||||
|
if (msg != NULL)
|
||||||
|
*lpp = NULL;
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return ((int)(dstp - dst));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_uncompress(msg, eom, src, dst, dstsiz)
|
||||||
|
* Expand compressed domain name to presentation format.
|
||||||
|
* return:
|
||||||
|
* Number of bytes read out of `src', or -1 (with errno set).
|
||||||
|
* note:
|
||||||
|
* Root domain returns as "." not "".
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_name_uncompress(const u_char *msg, const u_char *eom, const u_char *src,
|
||||||
|
char *dst, size_t dstsiz)
|
||||||
|
{
|
||||||
|
u_char tmp[NS_MAXCDNAME];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if ((n = ns_name_unpack(msg, eom, src, tmp, sizeof tmp)) == -1)
|
||||||
|
return (-1);
|
||||||
|
if (ns_name_ntop(tmp, dst, dstsiz) == -1)
|
||||||
|
return (-1);
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_compress(src, dst, dstsiz, dnptrs, lastdnptr)
|
||||||
|
* Compress a domain name into wire format, using compression pointers.
|
||||||
|
* return:
|
||||||
|
* Number of bytes consumed in `dst' or -1 (with errno set).
|
||||||
|
* notes:
|
||||||
|
* 'dnptrs' is an array of pointers to previous compressed names.
|
||||||
|
* dnptrs[0] is a pointer to the beginning of the message.
|
||||||
|
* The list ends with NULL. 'lastdnptr' is a pointer to the end of the
|
||||||
|
* array pointed to by 'dnptrs'. Side effect is to update the list of
|
||||||
|
* pointers for labels inserted into the message as we compress the name.
|
||||||
|
* If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr'
|
||||||
|
* is NULL, we don't update the list.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_name_compress(const char *src, u_char *dst, size_t dstsiz,
|
||||||
|
const u_char **dnptrs, const u_char **lastdnptr)
|
||||||
|
{
|
||||||
|
u_char tmp[NS_MAXCDNAME];
|
||||||
|
|
||||||
|
if (ns_name_pton(src, tmp, sizeof tmp) == -1)
|
||||||
|
return (-1);
|
||||||
|
return (ns_name_pack(tmp, dst, (int)dstsiz, dnptrs, lastdnptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ns_name_skip(ptrptr, eom)
|
||||||
|
* Advance *ptrptr to skip over the compressed name it points at.
|
||||||
|
* return:
|
||||||
|
* 0 on success, -1 (with errno set) on failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_name_skip(const u_char **ptrptr, const u_char *eom) {
|
||||||
|
const u_char *cp;
|
||||||
|
u_int n;
|
||||||
|
|
||||||
|
cp = *ptrptr;
|
||||||
|
while (cp < eom && (n = *cp++) != 0) {
|
||||||
|
/* Check for indirection. */
|
||||||
|
switch (n & NS_CMPRSFLGS) {
|
||||||
|
case 0: /* normal case, n == len */
|
||||||
|
cp += n;
|
||||||
|
continue;
|
||||||
|
case NS_CMPRSFLGS: /* indirection */
|
||||||
|
cp++;
|
||||||
|
break;
|
||||||
|
default: /* illegal type */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (cp > eom) {
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
*ptrptr = cp;
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* special(ch)
|
||||||
|
* Thinking in noninternationalized USASCII (per the DNS spec),
|
||||||
|
* is this characted special ("in need of quoting") ?
|
||||||
|
* return:
|
||||||
|
* boolean.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
special(int ch) {
|
||||||
|
switch (ch) {
|
||||||
|
case 0x22: /* '"' */
|
||||||
|
case 0x2E: /* '.' */
|
||||||
|
case 0x3B: /* ';' */
|
||||||
|
case 0x5C: /* '\\' */
|
||||||
|
/* Special modifiers in zone files. */
|
||||||
|
case 0x40: /* '@' */
|
||||||
|
case 0x24: /* '$' */
|
||||||
|
return (1);
|
||||||
|
default:
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* printable(ch)
|
||||||
|
* Thinking in noninternationalized USASCII (per the DNS spec),
|
||||||
|
* is this character visible and not a space when printed ?
|
||||||
|
* return:
|
||||||
|
* boolean.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
printable(int ch) {
|
||||||
|
return (ch > 0x20 && ch < 0x7f);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Thinking in noninternationalized USASCII (per the DNS spec),
|
||||||
|
* convert this character to lower case if it's upper case.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
mklower(int ch) {
|
||||||
|
if (ch >= 0x41 && ch <= 0x5A)
|
||||||
|
return (ch + 0x20);
|
||||||
|
return (ch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* dn_find(domain, msg, dnptrs, lastdnptr)
|
||||||
|
* Search for the counted-label name in an array of compressed names.
|
||||||
|
* return:
|
||||||
|
* offset from msg if found, or -1.
|
||||||
|
* notes:
|
||||||
|
* dnptrs is the pointer to the first name on the list,
|
||||||
|
* not the pointer to the start of the message.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
dn_find(const u_char *domain, const u_char *msg,
|
||||||
|
const u_char * const *dnptrs,
|
||||||
|
const u_char * const *lastdnptr)
|
||||||
|
{
|
||||||
|
const u_char *dn, *cp, *sp;
|
||||||
|
const u_char * const *cpp;
|
||||||
|
u_int n;
|
||||||
|
|
||||||
|
for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
|
||||||
|
dn = domain;
|
||||||
|
sp = cp = *cpp;
|
||||||
|
while ((n = *cp++) != 0) {
|
||||||
|
/*
|
||||||
|
* check for indirection
|
||||||
|
*/
|
||||||
|
switch (n & NS_CMPRSFLGS) {
|
||||||
|
case 0: /* normal case, n == len */
|
||||||
|
if (n != *dn++)
|
||||||
|
goto next;
|
||||||
|
for ((void)NULL; n > 0; n--)
|
||||||
|
if (mklower(*dn++) != mklower(*cp++))
|
||||||
|
goto next;
|
||||||
|
/* Is next root for both ? */
|
||||||
|
if (*dn == '\0' && *cp == '\0')
|
||||||
|
return ((int)(sp - msg));
|
||||||
|
if (*dn)
|
||||||
|
continue;
|
||||||
|
goto next;
|
||||||
|
|
||||||
|
case NS_CMPRSFLGS: /* indirection */
|
||||||
|
cp = msg + (((n & 0x3f) << 8) | *cp);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default: /* illegal type */
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
next: ;
|
||||||
|
}
|
||||||
|
errno = ENOENT;
|
||||||
|
return (-1);
|
||||||
|
}
|
54
StdLib/BsdSocketLib/ns_netint.c
Normal file
54
StdLib/BsdSocketLib/ns_netint.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "$Id: ns_netint.c,v 1.1.1.1 2003/11/19 01:51:33 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Import. */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
uint16_t
|
||||||
|
ns_get16(const u_char *src) {
|
||||||
|
uint16_t dst;
|
||||||
|
|
||||||
|
NS_GET16(dst, src);
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t
|
||||||
|
ns_get32(const u_char *src) {
|
||||||
|
uint32_t dst;
|
||||||
|
|
||||||
|
NS_GET32(dst, src);
|
||||||
|
return (dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ns_put16(uint16_t src, u_char *dst) {
|
||||||
|
NS_PUT16(src, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ns_put32(uint32_t src, u_char *dst) {
|
||||||
|
NS_PUT32(src, dst);
|
||||||
|
}
|
103
StdLib/BsdSocketLib/ns_ntoa.c
Normal file
103
StdLib/BsdSocketLib/ns_ntoa.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1986, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)ns_ntoa.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <netns/ns.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
static char *spectHex();
|
||||||
|
|
||||||
|
char *
|
||||||
|
ns_ntoa(
|
||||||
|
struct ns_addr addr
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static char obuf[40];
|
||||||
|
union { union ns_net net_e; u_long long_e; } net;
|
||||||
|
u_short port = htons(addr.x_port);
|
||||||
|
register char *cp;
|
||||||
|
char *cp2;
|
||||||
|
register u_char *up = addr.x_host.c_host;
|
||||||
|
u_char *uplim = up + 6;
|
||||||
|
|
||||||
|
net.net_e = addr.x_net;
|
||||||
|
sprintf(obuf, "%lx", (u_long)ntohl(net.long_e));
|
||||||
|
cp = spectHex(obuf);
|
||||||
|
cp2 = cp + 1;
|
||||||
|
while (*up==0 && up < uplim) up++;
|
||||||
|
if (up == uplim) {
|
||||||
|
if (port) {
|
||||||
|
sprintf(cp, ".0");
|
||||||
|
cp += 2;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sprintf(cp, ".%x", *up++);
|
||||||
|
while (up < uplim) {
|
||||||
|
while (*cp) cp++;
|
||||||
|
sprintf(cp, "%02x", *up++);
|
||||||
|
}
|
||||||
|
cp = spectHex(cp2);
|
||||||
|
}
|
||||||
|
if (port) {
|
||||||
|
sprintf(cp, ".%x", port);
|
||||||
|
spectHex(cp + 1);
|
||||||
|
}
|
||||||
|
return (obuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
spectHex(
|
||||||
|
char *p0
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int ok = 0;
|
||||||
|
int nonzero = 0;
|
||||||
|
register char *p = p0;
|
||||||
|
for (; *p; p++) switch (*p) {
|
||||||
|
|
||||||
|
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
|
||||||
|
*p += ('A' - 'a');
|
||||||
|
/* fall into . . . */
|
||||||
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
|
||||||
|
ok = 1;
|
||||||
|
case '1': case '2': case '3': case '4': case '5':
|
||||||
|
case '6': case '7': case '8': case '9':
|
||||||
|
nonzero = 1;
|
||||||
|
}
|
||||||
|
if (nonzero && !ok) { *p++ = 'H'; *p = 0; }
|
||||||
|
return (p);
|
||||||
|
}
|
230
StdLib/BsdSocketLib/ns_parse.c
Normal file
230
StdLib/BsdSocketLib/ns_parse.c
Normal file
@ -0,0 +1,230 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "$Id: ns_parse.c,v 1.1.1.1 2003/11/19 01:51:33 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/* These need to be in the same order as the nres.h:ns_flag enum. */
|
||||||
|
struct _ns_flagdata _ns_flagdata[16] = {
|
||||||
|
{ 0x8000, 15 }, /* qr. */
|
||||||
|
{ 0x7800, 11 }, /* opcode. */
|
||||||
|
{ 0x0400, 10 }, /* aa. */
|
||||||
|
{ 0x0200, 9 }, /* tc. */
|
||||||
|
{ 0x0100, 8 }, /* rd. */
|
||||||
|
{ 0x0080, 7 }, /* ra. */
|
||||||
|
{ 0x0040, 6 }, /* z. */
|
||||||
|
{ 0x0020, 5 }, /* ad. */
|
||||||
|
{ 0x0010, 4 }, /* cd. */
|
||||||
|
{ 0x000f, 0 }, /* rcode. */
|
||||||
|
{ 0x0000, 0 }, /* expansion (1/6). */
|
||||||
|
{ 0x0000, 0 }, /* expansion (2/6). */
|
||||||
|
{ 0x0000, 0 }, /* expansion (3/6). */
|
||||||
|
{ 0x0000, 0 }, /* expansion (4/6). */
|
||||||
|
{ 0x0000, 0 }, /* expansion (5/6). */
|
||||||
|
{ 0x0000, 0 }, /* expansion (6/6). */
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
skiprr(const u_char *ptr, const u_char *eom, ns_sect section, int count) {
|
||||||
|
const u_char *optr = ptr;
|
||||||
|
|
||||||
|
for ((void)NULL; count > 0; count--) {
|
||||||
|
int b, rdlength;
|
||||||
|
|
||||||
|
b = dn_skipname(ptr, eom);
|
||||||
|
if (b < 0)
|
||||||
|
goto emsgsize;
|
||||||
|
ptr += b/*Name*/ + NS_INT16SZ/*Type*/ + NS_INT16SZ/*Class*/;
|
||||||
|
if (section != ns_s_qd) {
|
||||||
|
if (ptr + NS_INT32SZ > eom)
|
||||||
|
goto emsgsize;
|
||||||
|
ptr += NS_INT32SZ/*TTL*/;
|
||||||
|
if (ptr + NS_INT16SZ > eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(rdlength, ptr);
|
||||||
|
ptr += rdlength/*RData*/;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ptr > eom)
|
||||||
|
goto emsgsize;
|
||||||
|
return ((int)(ptr - optr));
|
||||||
|
emsgsize:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ns_initparse(const u_char *msg, int msglen, ns_msg *handle) {
|
||||||
|
const u_char *eom = msg + msglen;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset(handle, 0x5e, sizeof *handle);
|
||||||
|
handle->_msg = msg;
|
||||||
|
handle->_eom = eom;
|
||||||
|
if (msg + NS_INT16SZ > eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(handle->_id, msg);
|
||||||
|
if (msg + NS_INT16SZ > eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(handle->_flags, msg);
|
||||||
|
for (i = 0; i < ns_s_max; i++) {
|
||||||
|
if (msg + NS_INT16SZ > eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(handle->_counts[i], msg);
|
||||||
|
}
|
||||||
|
for (i = 0; i < ns_s_max; i++)
|
||||||
|
if (handle->_counts[i] == 0)
|
||||||
|
handle->_sections[i] = NULL;
|
||||||
|
else {
|
||||||
|
int b = skiprr(msg, eom, (ns_sect)i,
|
||||||
|
handle->_counts[i]);
|
||||||
|
|
||||||
|
if (b < 0)
|
||||||
|
return (-1);
|
||||||
|
handle->_sections[i] = msg;
|
||||||
|
msg += b;
|
||||||
|
}
|
||||||
|
if (msg != eom)
|
||||||
|
goto emsgsize;
|
||||||
|
handle->_sect = ns_s_max;
|
||||||
|
handle->_rrnum = -1;
|
||||||
|
handle->_msg_ptr = NULL;
|
||||||
|
return (0);
|
||||||
|
emsgsize:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) {
|
||||||
|
int b;
|
||||||
|
|
||||||
|
/* Make section right. */
|
||||||
|
if (section < 0 || section >= ns_s_max)
|
||||||
|
goto enodev;
|
||||||
|
if ((int)section != (int)handle->_sect) {
|
||||||
|
handle->_sect = section;
|
||||||
|
handle->_rrnum = 0;
|
||||||
|
handle->_msg_ptr = handle->_sections[(int)section];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make rrnum right. */
|
||||||
|
if (rrnum == -1)
|
||||||
|
rrnum = handle->_rrnum;
|
||||||
|
if (rrnum < 0 || rrnum >= handle->_counts[(int)section])
|
||||||
|
goto enodev;
|
||||||
|
if (rrnum < handle->_rrnum) {
|
||||||
|
handle->_rrnum = 0;
|
||||||
|
handle->_msg_ptr = handle->_sections[(int)section];
|
||||||
|
}
|
||||||
|
|
||||||
|
b = skiprr(handle->_msg, handle->_eom, section,
|
||||||
|
rrnum - handle->_rrnum);
|
||||||
|
if (b < 0)
|
||||||
|
return (-1);
|
||||||
|
handle->_msg_ptr += b;
|
||||||
|
handle->_rrnum = rrnum;
|
||||||
|
|
||||||
|
/* Do the parse. */
|
||||||
|
b = dn_expand(handle->_msg, handle->_eom,
|
||||||
|
handle->_msg_ptr, rr->name, NS_MAXDNAME);
|
||||||
|
if (b < 0)
|
||||||
|
return (-1);
|
||||||
|
handle->_msg_ptr += b;
|
||||||
|
if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(rr->type, handle->_msg_ptr);
|
||||||
|
if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(rr->rr_class, handle->_msg_ptr);
|
||||||
|
if (section == ns_s_qd) {
|
||||||
|
rr->ttl = 0;
|
||||||
|
rr->rdlength = 0;
|
||||||
|
rr->rdata = NULL;
|
||||||
|
} else {
|
||||||
|
if (handle->_msg_ptr + NS_INT32SZ > handle->_eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET32(rr->ttl, handle->_msg_ptr);
|
||||||
|
if (handle->_msg_ptr + NS_INT16SZ > handle->_eom)
|
||||||
|
goto emsgsize;
|
||||||
|
NS_GET16(rr->rdlength, handle->_msg_ptr);
|
||||||
|
if (handle->_msg_ptr + rr->rdlength > handle->_eom)
|
||||||
|
goto emsgsize;
|
||||||
|
rr->rdata = handle->_msg_ptr;
|
||||||
|
handle->_msg_ptr += rr->rdlength;
|
||||||
|
}
|
||||||
|
handle->_rrnum++;
|
||||||
|
|
||||||
|
/* All done. */
|
||||||
|
return (0);
|
||||||
|
enodev:
|
||||||
|
errno = ENODEV;
|
||||||
|
return (-1);
|
||||||
|
emsgsize:
|
||||||
|
errno = EMSGSIZE;
|
||||||
|
return (-1);
|
||||||
|
}
|
780
StdLib/BsdSocketLib/ns_print.c
Normal file
780
StdLib/BsdSocketLib/ns_print.c
Normal file
@ -0,0 +1,780 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996, 1998 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "$Id: ns_print.c,v 1.1.1.1 2003/11/19 01:51:34 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Import. */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#define SPRINTF(x) (sprintf x)
|
||||||
|
|
||||||
|
/* Forward. */
|
||||||
|
|
||||||
|
static size_t prune_origin(const char *name, const char *origin);
|
||||||
|
static int charstr(const u_char *rdata, const u_char *edata,
|
||||||
|
char **buf, size_t *buflen);
|
||||||
|
static int addname(const u_char *msg, size_t msglen,
|
||||||
|
const u_char **p, const char *origin,
|
||||||
|
char **buf, size_t *buflen);
|
||||||
|
static void addlen(size_t len, char **buf, size_t *buflen);
|
||||||
|
static int addstr(const char *src, size_t len,
|
||||||
|
char **buf, size_t *buflen);
|
||||||
|
static int addtab(size_t len, size_t target, int spaced,
|
||||||
|
char **buf, size_t *buflen);
|
||||||
|
|
||||||
|
/* Macros. */
|
||||||
|
|
||||||
|
#define T(x) \
|
||||||
|
do { \
|
||||||
|
if ((ssize_t)(x) < 0) \
|
||||||
|
return (-1); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
/* Public. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* int
|
||||||
|
* ns_sprintrr(handle, rr, name_ctx, origin, buf, buflen)
|
||||||
|
* Convert an RR to presentation format.
|
||||||
|
* return:
|
||||||
|
* Number of characters written to buf, or -1 (check errno).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_sprintrr(const ns_msg *handle, const ns_rr *rr,
|
||||||
|
const char *name_ctx, const char *origin,
|
||||||
|
char *buf, size_t buflen)
|
||||||
|
{
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = ns_sprintrrf(ns_msg_base(*handle), ns_msg_size(*handle),
|
||||||
|
ns_rr_name(*rr), ns_rr_class(*rr), ns_rr_type(*rr),
|
||||||
|
ns_rr_ttl(*rr), ns_rr_rdata(*rr), ns_rr_rdlen(*rr),
|
||||||
|
name_ctx, origin, buf, buflen);
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* int
|
||||||
|
* ns_sprintrrf(msg, msglen, name, class, type, ttl, rdata, rdlen,
|
||||||
|
* name_ctx, origin, buf, buflen)
|
||||||
|
* Convert the fields of an RR into presentation format.
|
||||||
|
* return:
|
||||||
|
* Number of characters written to buf, or -1 (check errno).
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ns_sprintrrf(const u_char *msg, size_t msglen,
|
||||||
|
const char *name, ns_class class, ns_type type,
|
||||||
|
u_long ttl, const u_char *rdata, size_t rdlen,
|
||||||
|
const char *name_ctx, const char *origin,
|
||||||
|
char *buf, size_t buflen)
|
||||||
|
{
|
||||||
|
const char *obuf = buf;
|
||||||
|
const u_char *edata = rdata + rdlen;
|
||||||
|
int spaced = 0;
|
||||||
|
|
||||||
|
const char *comment;
|
||||||
|
char tmp[100];
|
||||||
|
int x;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
static char base64_key[NS_MD5RSA_MAX_BASE64];
|
||||||
|
static char t[255*3];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Owner.
|
||||||
|
*/
|
||||||
|
if (name_ctx != NULL && strcasecmp(name_ctx, name) == 0) {
|
||||||
|
T(addstr("\t\t\t", 3, &buf, &buflen));
|
||||||
|
} else {
|
||||||
|
len = prune_origin(name, origin);
|
||||||
|
if (len == 0) {
|
||||||
|
T(addstr("@\t\t\t", 4, &buf, &buflen));
|
||||||
|
} else {
|
||||||
|
T(addstr(name, len, &buf, &buflen));
|
||||||
|
/* Origin not used and no trailing dot? */
|
||||||
|
if ((!origin || !origin[0] || name[len] == '\0') &&
|
||||||
|
name[len - 1] != '.') {
|
||||||
|
T(addstr(".", 1, &buf, &buflen));
|
||||||
|
len++;
|
||||||
|
}
|
||||||
|
T(spaced = addtab(len, 24, spaced, &buf, &buflen));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TTL, Class, Type.
|
||||||
|
*/
|
||||||
|
T(x = ns_format_ttl(ttl, buf, buflen));
|
||||||
|
addlen(x, &buf, &buflen);
|
||||||
|
len = SPRINTF((tmp, " %s %s", p_class(class), p_type(type)));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
T(spaced = addtab(x + len, 16, spaced, &buf, &buflen));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RData.
|
||||||
|
*/
|
||||||
|
switch (type) {
|
||||||
|
case ns_t_a:
|
||||||
|
if (rdlen != NS_INADDRSZ)
|
||||||
|
goto formerr;
|
||||||
|
(void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
|
||||||
|
addlen(strlen(buf), &buf, &buflen);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_cname:
|
||||||
|
case ns_t_mb:
|
||||||
|
case ns_t_mg:
|
||||||
|
case ns_t_mr:
|
||||||
|
case ns_t_ns:
|
||||||
|
case ns_t_ptr:
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_hinfo:
|
||||||
|
case ns_t_isdn:
|
||||||
|
/* First word. */
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Second word. */
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_soa: {
|
||||||
|
u_long t;
|
||||||
|
|
||||||
|
/* Server name. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Administrator name. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
T(addstr(" (\n", 3, &buf, &buflen));
|
||||||
|
spaced = 0;
|
||||||
|
|
||||||
|
if ((edata - rdata) != 5*NS_INT32SZ)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Serial number. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
|
||||||
|
len = SPRINTF((tmp, "%lu", t));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
T(spaced = addtab(len, 16, spaced, &buf, &buflen));
|
||||||
|
T(addstr("; serial\n", 9, &buf, &buflen));
|
||||||
|
spaced = 0;
|
||||||
|
|
||||||
|
/* Refresh interval. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
|
||||||
|
T(len = ns_format_ttl(t, buf, buflen));
|
||||||
|
addlen(len, &buf, &buflen);
|
||||||
|
T(spaced = addtab(len, 16, spaced, &buf, &buflen));
|
||||||
|
T(addstr("; refresh\n", 10, &buf, &buflen));
|
||||||
|
spaced = 0;
|
||||||
|
|
||||||
|
/* Retry interval. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
|
||||||
|
T(len = ns_format_ttl(t, buf, buflen));
|
||||||
|
addlen(len, &buf, &buflen);
|
||||||
|
T(spaced = addtab(len, 16, spaced, &buf, &buflen));
|
||||||
|
T(addstr("; retry\n", 8, &buf, &buflen));
|
||||||
|
spaced = 0;
|
||||||
|
|
||||||
|
/* Expiry. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
|
||||||
|
T(len = ns_format_ttl(t, buf, buflen));
|
||||||
|
addlen(len, &buf, &buflen);
|
||||||
|
T(spaced = addtab(len, 16, spaced, &buf, &buflen));
|
||||||
|
T(addstr("; expiry\n", 9, &buf, &buflen));
|
||||||
|
spaced = 0;
|
||||||
|
|
||||||
|
/* Minimum TTL. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
T(addstr("\t\t\t\t\t", 5, &buf, &buflen));
|
||||||
|
T(len = ns_format_ttl(t, buf, buflen));
|
||||||
|
addlen(len, &buf, &buflen);
|
||||||
|
T(addstr(" )", 2, &buf, &buflen));
|
||||||
|
T(spaced = addtab(len, 16, spaced, &buf, &buflen));
|
||||||
|
T(addstr("; minimum\n", 10, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_mx:
|
||||||
|
case ns_t_afsdb:
|
||||||
|
case ns_t_rt: {
|
||||||
|
u_int t;
|
||||||
|
|
||||||
|
if (rdlen < NS_INT16SZ)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Priority. */
|
||||||
|
t = ns_get16(rdata);
|
||||||
|
rdata += NS_INT16SZ;
|
||||||
|
len = SPRINTF((tmp, "%u ", t));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Target. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_px: {
|
||||||
|
u_int t;
|
||||||
|
|
||||||
|
if (rdlen < NS_INT16SZ)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Priority. */
|
||||||
|
t = ns_get16(rdata);
|
||||||
|
rdata += NS_INT16SZ;
|
||||||
|
len = SPRINTF((tmp, "%u ", t));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Name1. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Name2. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_x25:
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_txt:
|
||||||
|
while (rdata < edata) {
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
if (rdata < edata)
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_nsap: {
|
||||||
|
|
||||||
|
(void) inet_nsap_ntoa((int)rdlen, rdata, t);
|
||||||
|
T(addstr(t, strlen(t), &buf, &buflen));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_aaaa:
|
||||||
|
if (rdlen != NS_IN6ADDRSZ)
|
||||||
|
goto formerr;
|
||||||
|
(void) inet_ntop(AF_INET6, rdata, buf, (socklen_t)buflen);
|
||||||
|
addlen(strlen(buf), &buf, &buflen);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_loc: {
|
||||||
|
/* XXX protocol format checking? */
|
||||||
|
(void) loc_ntoa(rdata, t);
|
||||||
|
T(addstr(t, strlen(t), &buf, &buflen));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_naptr: {
|
||||||
|
u_int order, preference;
|
||||||
|
|
||||||
|
if (rdlen < 2*NS_INT16SZ)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Order, Precedence. */
|
||||||
|
order = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
preference = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
len = SPRINTF((t, "%u %u ", order, preference));
|
||||||
|
T(addstr(t, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Flags. */
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Service. */
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Regexp. */
|
||||||
|
T(len = charstr(rdata, edata, &buf, &buflen));
|
||||||
|
if ((ssize_t)len < 0)
|
||||||
|
return (-1);
|
||||||
|
if (len == 0)
|
||||||
|
goto formerr;
|
||||||
|
rdata += len;
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Server. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_srv: {
|
||||||
|
u_int priority, weight, port;
|
||||||
|
|
||||||
|
if (rdlen < NS_INT16SZ*3)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Priority, Weight, Port. */
|
||||||
|
priority = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
weight = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
port = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
len = SPRINTF((t, "%u %u %u ", priority, weight, port));
|
||||||
|
T(addstr(t, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Server. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_minfo:
|
||||||
|
case ns_t_rp:
|
||||||
|
/* Name1. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
T(addstr(" ", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Name2. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ns_t_wks: {
|
||||||
|
int n, lcnt;
|
||||||
|
|
||||||
|
if (rdlen < NS_INT32SZ + 1)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Address. */
|
||||||
|
(void) inet_ntop(AF_INET, rdata, buf, (socklen_t)buflen);
|
||||||
|
addlen(strlen(buf), &buf, &buflen);
|
||||||
|
rdata += NS_INADDRSZ;
|
||||||
|
|
||||||
|
/* Protocol. */
|
||||||
|
len = SPRINTF((tmp, " %u ( ", *rdata));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
rdata += NS_INT8SZ;
|
||||||
|
|
||||||
|
/* Bit map. */
|
||||||
|
n = 0;
|
||||||
|
lcnt = 0;
|
||||||
|
while (rdata < edata) {
|
||||||
|
u_int c = *rdata++;
|
||||||
|
do {
|
||||||
|
if (c & 0200) {
|
||||||
|
if (lcnt == 0) {
|
||||||
|
T(addstr("\n\t\t\t\t", 5,
|
||||||
|
&buf, &buflen));
|
||||||
|
lcnt = 10;
|
||||||
|
spaced = 0;
|
||||||
|
}
|
||||||
|
len = SPRINTF((tmp, "%d ", n));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
lcnt--;
|
||||||
|
}
|
||||||
|
c <<= 1;
|
||||||
|
} while (++n & 07);
|
||||||
|
}
|
||||||
|
T(addstr(")", 1, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_key: {
|
||||||
|
u_int keyflags, protocol, algorithm;
|
||||||
|
const char *leader;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (rdlen < NS_INT16SZ + NS_INT8SZ + NS_INT8SZ)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Key flags, Protocol, Algorithm. */
|
||||||
|
keyflags = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
protocol = *rdata++;
|
||||||
|
algorithm = *rdata++;
|
||||||
|
len = SPRINTF((tmp, "0x%04x %u %u",
|
||||||
|
keyflags, protocol, algorithm));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Public key data. */
|
||||||
|
len = b64_ntop(rdata, edata - rdata,
|
||||||
|
base64_key, sizeof base64_key);
|
||||||
|
if ((ssize_t)len < 0)
|
||||||
|
goto formerr;
|
||||||
|
if (len > 15) {
|
||||||
|
T(addstr(" (", 2, &buf, &buflen));
|
||||||
|
leader = "\n\t\t";
|
||||||
|
spaced = 0;
|
||||||
|
} else
|
||||||
|
leader = " ";
|
||||||
|
for (n = 0; n < (int)len; n += 48) {
|
||||||
|
T(addstr(leader, strlen(leader), &buf, &buflen));
|
||||||
|
T(addstr(base64_key + n, MIN(len - n, 48),
|
||||||
|
&buf, &buflen));
|
||||||
|
}
|
||||||
|
if (len > 15)
|
||||||
|
T(addstr(" )", 2, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_sig: {
|
||||||
|
u_int type, algorithm, labels, footprint;
|
||||||
|
const char *leader;
|
||||||
|
u_long t;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if (rdlen < 22)
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Type covered, Algorithm, Label count, Original TTL. */
|
||||||
|
type = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
algorithm = *rdata++;
|
||||||
|
labels = *rdata++;
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
len = SPRINTF((tmp, " %s %d %lu ",
|
||||||
|
p_type((int)type), algorithm, t));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
if (labels != (u_int)dn_count_labels(name))
|
||||||
|
goto formerr;
|
||||||
|
|
||||||
|
/* Signature expiry. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
len = SPRINTF((tmp, "%s ", p_secstodate(t)));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Time signed. */
|
||||||
|
t = ns_get32(rdata); rdata += NS_INT32SZ;
|
||||||
|
len = SPRINTF((tmp, "%s ", p_secstodate(t)));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Signature Footprint. */
|
||||||
|
footprint = ns_get16(rdata); rdata += NS_INT16SZ;
|
||||||
|
len = SPRINTF((tmp, "%u ", footprint));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Signer's name. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Signature. */
|
||||||
|
len = b64_ntop(rdata, edata - rdata,
|
||||||
|
base64_key, sizeof base64_key);
|
||||||
|
if (len > 15) {
|
||||||
|
T(addstr(" (", 2, &buf, &buflen));
|
||||||
|
leader = "\n\t\t";
|
||||||
|
spaced = 0;
|
||||||
|
} else
|
||||||
|
leader = " ";
|
||||||
|
if ((ssize_t)len < 0)
|
||||||
|
goto formerr;
|
||||||
|
for (n = 0; n < (int)len; n += 48) {
|
||||||
|
T(addstr(leader, strlen(leader), &buf, &buflen));
|
||||||
|
T(addstr(base64_key + n, MIN(len - n, 48),
|
||||||
|
&buf, &buflen));
|
||||||
|
}
|
||||||
|
if (len > 15)
|
||||||
|
T(addstr(" )", 2, &buf, &buflen));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ns_t_nxt: {
|
||||||
|
int n, c;
|
||||||
|
|
||||||
|
/* Next domain name. */
|
||||||
|
T(addname(msg, msglen, &rdata, origin, &buf, &buflen));
|
||||||
|
|
||||||
|
/* Type bit map. */
|
||||||
|
n = (int)(edata - rdata);
|
||||||
|
for (c = 0; c < n*8; c++)
|
||||||
|
if (NS_NXT_BIT_ISSET(c, rdata)) {
|
||||||
|
len = SPRINTF((tmp, " %s", p_type(c)));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
comment = "unknown RR type";
|
||||||
|
goto hexify;
|
||||||
|
}
|
||||||
|
return ((int)(buf - obuf));
|
||||||
|
formerr:
|
||||||
|
comment = "RR format error";
|
||||||
|
hexify: {
|
||||||
|
int n, m;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
len = SPRINTF((tmp, "\\#(\t\t; %s", comment));
|
||||||
|
T(addstr(tmp, len, &buf, &buflen));
|
||||||
|
while (rdata < edata) {
|
||||||
|
p = tmp;
|
||||||
|
p += SPRINTF((p, "\n\t"));
|
||||||
|
spaced = 0;
|
||||||
|
n = MIN(16, (int)(edata - rdata));
|
||||||
|
for (m = 0; m < n; m++)
|
||||||
|
p += SPRINTF((p, "%02x ", rdata[m]));
|
||||||
|
T(addstr(tmp, (u_int)(p - tmp), &buf, &buflen));
|
||||||
|
if (n < 16) {
|
||||||
|
T(addstr(")", 1, &buf, &buflen));
|
||||||
|
T(addtab((u_int)(p - tmp) + 1, 48, spaced, &buf, &buflen));
|
||||||
|
}
|
||||||
|
p = tmp;
|
||||||
|
p += SPRINTF((p, "; "));
|
||||||
|
for (m = 0; m < n; m++)
|
||||||
|
*p++ = (isascii(rdata[m]) && isprint(rdata[m]))
|
||||||
|
? rdata[m]
|
||||||
|
: '.';
|
||||||
|
T(addstr(tmp, (u_int)(p - tmp), &buf, &buflen));
|
||||||
|
rdata += n;
|
||||||
|
}
|
||||||
|
return ((int)(buf - obuf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* size_t
|
||||||
|
* prune_origin(name, origin)
|
||||||
|
* Find out if the name is at or under the current origin.
|
||||||
|
* return:
|
||||||
|
* Number of characters in name before start of origin,
|
||||||
|
* or length of name if origin does not match.
|
||||||
|
* notes:
|
||||||
|
* This function should share code with samedomain().
|
||||||
|
*/
|
||||||
|
static size_t
|
||||||
|
prune_origin(const char *name, const char *origin) {
|
||||||
|
const char *oname = name;
|
||||||
|
|
||||||
|
while (*name != '\0') {
|
||||||
|
if (origin != NULL && strcasecmp(name, origin) == 0)
|
||||||
|
return ((size_t)(name - oname) - (name > oname));
|
||||||
|
while (*name != '\0') {
|
||||||
|
if (*name == '\\') {
|
||||||
|
name++;
|
||||||
|
/* XXX need to handle \nnn form. */
|
||||||
|
if (*name == '\0')
|
||||||
|
break;
|
||||||
|
} else if (*name == '.') {
|
||||||
|
name++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
name++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ((size_t)(name - oname));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* int
|
||||||
|
* charstr(rdata, edata, buf, buflen)
|
||||||
|
* Format a <character-string> into the presentation buffer.
|
||||||
|
* return:
|
||||||
|
* Number of rdata octets consumed
|
||||||
|
* 0 for protocol format error
|
||||||
|
* -1 for output buffer error
|
||||||
|
* side effects:
|
||||||
|
* buffer is advanced on success.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
charstr(const u_char *rdata, const u_char *edata, char **buf, size_t *buflen) {
|
||||||
|
const u_char *odata = rdata;
|
||||||
|
size_t save_buflen = *buflen;
|
||||||
|
char *save_buf = *buf;
|
||||||
|
|
||||||
|
if (addstr("\"", 1, buf, buflen) < 0)
|
||||||
|
goto enospc;
|
||||||
|
if (rdata < edata) {
|
||||||
|
int n = *rdata;
|
||||||
|
|
||||||
|
if (rdata + 1 + n <= edata) {
|
||||||
|
rdata++;
|
||||||
|
while (n-- > 0) {
|
||||||
|
if (strchr("\n\"\\", *rdata) != NULL)
|
||||||
|
if (addstr("\\", 1, buf, buflen) < 0)
|
||||||
|
goto enospc;
|
||||||
|
if (addstr((const char *)rdata, 1,
|
||||||
|
buf, buflen) < 0)
|
||||||
|
goto enospc;
|
||||||
|
rdata++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (addstr("\"", 1, buf, buflen) < 0)
|
||||||
|
goto enospc;
|
||||||
|
return ((int)(rdata - odata));
|
||||||
|
enospc:
|
||||||
|
errno = ENOSPC;
|
||||||
|
*buf = save_buf;
|
||||||
|
*buflen = save_buflen;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
addname(const u_char *msg, size_t msglen,
|
||||||
|
const u_char **pp, const char *origin,
|
||||||
|
char **buf, size_t *buflen)
|
||||||
|
{
|
||||||
|
size_t newlen, save_buflen = *buflen;
|
||||||
|
char *save_buf = *buf;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = dn_expand(msg, msg + msglen, *pp, *buf, (int)(*buflen));
|
||||||
|
if (n < 0)
|
||||||
|
goto enospc; /* Guess. */
|
||||||
|
newlen = prune_origin(*buf, origin);
|
||||||
|
if ((origin == NULL || origin[0] == '\0' || (*buf)[newlen] == '\0') &&
|
||||||
|
(newlen == 0 || (*buf)[newlen - 1] != '.')) {
|
||||||
|
/* No trailing dot. */
|
||||||
|
if (newlen + 2 > *buflen)
|
||||||
|
goto enospc; /* No room for ".\0". */
|
||||||
|
(*buf)[newlen++] = '.';
|
||||||
|
(*buf)[newlen] = '\0';
|
||||||
|
}
|
||||||
|
if (newlen == 0) {
|
||||||
|
/* Use "@" instead of name. */
|
||||||
|
if (newlen + 2 > *buflen)
|
||||||
|
goto enospc; /* No room for "@\0". */
|
||||||
|
(*buf)[newlen++] = '@';
|
||||||
|
(*buf)[newlen] = '\0';
|
||||||
|
}
|
||||||
|
*pp += n;
|
||||||
|
addlen(newlen, buf, buflen);
|
||||||
|
**buf = '\0';
|
||||||
|
return ((int)newlen);
|
||||||
|
enospc:
|
||||||
|
errno = ENOSPC;
|
||||||
|
*buf = save_buf;
|
||||||
|
*buflen = save_buflen;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
addlen(size_t len, char **buf, size_t *buflen) {
|
||||||
|
assert(len <= *buflen);
|
||||||
|
*buf += len;
|
||||||
|
*buflen -= len;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
addstr(const char *src, size_t len, char **buf, size_t *buflen) {
|
||||||
|
if (len > *buflen) {
|
||||||
|
errno = ENOSPC;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
memcpy(*buf, src, len);
|
||||||
|
addlen(len, buf, buflen);
|
||||||
|
**buf = '\0';
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
addtab(size_t len, size_t target, int spaced, char **buf, size_t *buflen) {
|
||||||
|
size_t save_buflen = *buflen;
|
||||||
|
char *save_buf = *buf;
|
||||||
|
int t;
|
||||||
|
|
||||||
|
if (spaced || len >= target - 1) {
|
||||||
|
T(addstr(" ", 2, buf, buflen));
|
||||||
|
spaced = 1;
|
||||||
|
} else {
|
||||||
|
for (t = (int)(target - len - 1) / 8; t >= 0; t--)
|
||||||
|
if (addstr("\t", 1, buf, buflen) < 0) {
|
||||||
|
*buflen = save_buflen;
|
||||||
|
*buf = save_buf;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
spaced = 0;
|
||||||
|
}
|
||||||
|
return (spaced);
|
||||||
|
}
|
191
StdLib/BsdSocketLib/ns_ttl.c
Normal file
191
StdLib/BsdSocketLib/ns_ttl.c
Normal file
@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef lint
|
||||||
|
static char rcsid[] = "$Id: ns_ttl.c,v 1.1.1.1 2003/11/19 01:51:34 kyu3 Exp $";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Import. */
|
||||||
|
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define SPRINTF(x) ((size_t)sprintf x)
|
||||||
|
|
||||||
|
/* Forward. */
|
||||||
|
|
||||||
|
static int fmt1(int t, char s, char **buf, size_t *buflen);
|
||||||
|
|
||||||
|
/* Macros. */
|
||||||
|
|
||||||
|
#define T(x) if ((x) < 0) return (-1); else (void)NULL
|
||||||
|
|
||||||
|
/* Public. */
|
||||||
|
|
||||||
|
int
|
||||||
|
ns_format_ttl(u_long src, char *dst, size_t dstlen) {
|
||||||
|
char *odst = dst;
|
||||||
|
int secs, mins, hours, days, weeks, x;
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
secs = (int)(src % 60); src /= 60;
|
||||||
|
mins = (int)(src % 60); src /= 60;
|
||||||
|
hours = (int)(src % 24); src /= 24;
|
||||||
|
days = (int)(src % 7); src /= 7;
|
||||||
|
weeks = (int)src; src = 0;
|
||||||
|
|
||||||
|
x = 0;
|
||||||
|
if (weeks) {
|
||||||
|
T(fmt1(weeks, 'W', &dst, &dstlen));
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
if (days) {
|
||||||
|
T(fmt1(days, 'D', &dst, &dstlen));
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
if (hours) {
|
||||||
|
T(fmt1(hours, 'H', &dst, &dstlen));
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
if (mins) {
|
||||||
|
T(fmt1(mins, 'M', &dst, &dstlen));
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
if (secs || !(weeks || days || hours || mins)) {
|
||||||
|
T(fmt1(secs, 'S', &dst, &dstlen));
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x > 1) {
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
for (p = odst; (ch = *p) != '\0'; p++)
|
||||||
|
if (isascii(ch) && isupper(ch))
|
||||||
|
*p = (char)( tolower(ch));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((int)(dst - odst));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ns_parse_ttl(const char *src, u_long *dst) {
|
||||||
|
u_long ttl, tmp;
|
||||||
|
int ch, digits, dirty;
|
||||||
|
|
||||||
|
ttl = 0;
|
||||||
|
tmp = 0;
|
||||||
|
digits = 0;
|
||||||
|
dirty = 0;
|
||||||
|
while ((ch = *src++) != '\0') {
|
||||||
|
if (!isascii(ch) || !isprint(ch))
|
||||||
|
goto einval;
|
||||||
|
if (isdigit(ch)) {
|
||||||
|
tmp *= 10;
|
||||||
|
tmp += (ch - '0');
|
||||||
|
digits++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (digits == 0)
|
||||||
|
goto einval;
|
||||||
|
if (islower(ch))
|
||||||
|
ch = toupper(ch);
|
||||||
|
switch (ch) {
|
||||||
|
case 'W': tmp *= 7;
|
||||||
|
case 'D': tmp *= 24;
|
||||||
|
case 'H': tmp *= 60;
|
||||||
|
case 'M': tmp *= 60;
|
||||||
|
case 'S': break;
|
||||||
|
default: goto einval;
|
||||||
|
}
|
||||||
|
ttl += tmp;
|
||||||
|
tmp = 0;
|
||||||
|
digits = 0;
|
||||||
|
dirty = 1;
|
||||||
|
}
|
||||||
|
if (digits > 0) {
|
||||||
|
if (dirty)
|
||||||
|
goto einval;
|
||||||
|
else
|
||||||
|
ttl += tmp;
|
||||||
|
}
|
||||||
|
*dst = ttl;
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
einval:
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Private. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
fmt1(int t, char s, char **buf, size_t *buflen) {
|
||||||
|
char tmp[50];
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
len = SPRINTF((tmp, "%d%c", t, s));
|
||||||
|
if (len + 1 > *buflen)
|
||||||
|
return (-1);
|
||||||
|
strcpy(*buf, tmp);
|
||||||
|
*buf += len;
|
||||||
|
*buflen -= len;
|
||||||
|
return (0);
|
||||||
|
}
|
108
StdLib/BsdSocketLib/nsap_addr.c
Normal file
108
StdLib/BsdSocketLib/nsap_addr.c
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996, 1998 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char rcsid[] = "$Id: nsap_addr.c,v 1.1.1.1 2003/11/19 01:51:31 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
|
||||||
|
static char
|
||||||
|
xtob(
|
||||||
|
register int c
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return (char)(c - (((c >= '0') && (c <= '9')) ? '0' : '7'));
|
||||||
|
}
|
||||||
|
|
||||||
|
u_int
|
||||||
|
inet_nsap_addr(
|
||||||
|
const char *ascii,
|
||||||
|
u_char *binary,
|
||||||
|
int maxlen
|
||||||
|
)
|
||||||
|
{
|
||||||
|
u_char c, nib;
|
||||||
|
u_int len = 0;
|
||||||
|
|
||||||
|
while ((c = *ascii++) != '\0' && len < (u_int)maxlen) {
|
||||||
|
if (c == '.' || c == '+' || c == '/')
|
||||||
|
continue;
|
||||||
|
if (!isascii(c))
|
||||||
|
return (0);
|
||||||
|
if (islower(c))
|
||||||
|
c = (u_char)( toupper(c));
|
||||||
|
if (isxdigit(c)) {
|
||||||
|
nib = xtob(c);
|
||||||
|
c = *ascii++;
|
||||||
|
if (c != '\0') {
|
||||||
|
c = (u_char)( toupper(c));
|
||||||
|
if (isxdigit(c)) {
|
||||||
|
*binary++ = (nib << 4) | xtob(c);
|
||||||
|
len++;
|
||||||
|
} else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (len);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
inet_nsap_ntoa(
|
||||||
|
int binlen,
|
||||||
|
register const u_char *binary,
|
||||||
|
register char *ascii
|
||||||
|
)
|
||||||
|
{
|
||||||
|
register int nib;
|
||||||
|
int i;
|
||||||
|
static char tmpbuf[255*3];
|
||||||
|
char *start;
|
||||||
|
|
||||||
|
if (ascii)
|
||||||
|
start = ascii;
|
||||||
|
else {
|
||||||
|
ascii = tmpbuf;
|
||||||
|
start = tmpbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (binlen > 255)
|
||||||
|
binlen = 255;
|
||||||
|
|
||||||
|
for (i = 0; i < binlen; i++) {
|
||||||
|
nib = *binary >> 4;
|
||||||
|
*ascii++ = (char)( nib + (nib < 10 ? '0' : '7'));
|
||||||
|
nib = *binary++ & 0x0f;
|
||||||
|
*ascii++ = (char)( nib + (nib < 10 ? '0' : '7'));
|
||||||
|
if (((i % 2) == 0 && (i + 1) < binlen))
|
||||||
|
*ascii++ = '.';
|
||||||
|
}
|
||||||
|
*ascii = '\0';
|
||||||
|
return (start);
|
||||||
|
}
|
57
StdLib/BsdSocketLib/poll.c
Normal file
57
StdLib/BsdSocketLib/poll.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the poll API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Poll the socket for activity
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
|
||||||
|
@param [in] Events Mask of events to detect
|
||||||
|
|
||||||
|
@returns Detected events for the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
short
|
||||||
|
BslSocketPoll (
|
||||||
|
IN struct __filedes * pDescriptor,
|
||||||
|
IN short Events
|
||||||
|
)
|
||||||
|
{
|
||||||
|
short DetectedEvents;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the socket protocol
|
||||||
|
//
|
||||||
|
DetectedEvents = 0;
|
||||||
|
pSocketProtocol = BslValidateSocketFd ( pDescriptor, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Poll the socket
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnPoll ( pSocketProtocol,
|
||||||
|
Events,
|
||||||
|
&DetectedEvents,
|
||||||
|
&errno );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the detected events
|
||||||
|
//
|
||||||
|
return DetectedEvents;
|
||||||
|
}
|
53
StdLib/BsdSocketLib/read.c
Normal file
53
StdLib/BsdSocketLib/read.c
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the read API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Read support routine for sockets
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
@param [in] pOffset File offset
|
||||||
|
@param [in] LengthInBytes Number of bytes to read
|
||||||
|
@param [in] pBuffer Address of the buffer to receive the data
|
||||||
|
|
||||||
|
@returns The number of bytes read or -1 if an error occurs.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
BslSocketRead (
|
||||||
|
struct __filedes *pDescriptor,
|
||||||
|
off_t * pOffset,
|
||||||
|
size_t LengthInBytes,
|
||||||
|
void * pBuffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ssize_t BytesRead;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Receive the data from the remote system
|
||||||
|
//
|
||||||
|
BytesRead = recvfrom ( pDescriptor->MyFD,
|
||||||
|
pBuffer,
|
||||||
|
LengthInBytes,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the number of bytes read
|
||||||
|
//
|
||||||
|
return BytesRead;
|
||||||
|
}
|
63
StdLib/BsdSocketLib/recv.c
Normal file
63
StdLib/BsdSocketLib/recv.c
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the recv API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Receive data from a network connection.
|
||||||
|
|
||||||
|
The ::recv routine waits for receive data from a remote network
|
||||||
|
connection. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] buffer Address of a buffer to receive the data.
|
||||||
|
|
||||||
|
@param [in] length Length of the buffer in bytes.
|
||||||
|
|
||||||
|
@param [in] flags Message control flags
|
||||||
|
|
||||||
|
@returns ::recv returns the number of valid bytes in the buffer,
|
||||||
|
zero if no data was received, and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
recv (
|
||||||
|
int s,
|
||||||
|
void * buffer,
|
||||||
|
size_t length,
|
||||||
|
int flags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ssize_t BytesRead;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Receive the data from the remote system
|
||||||
|
//
|
||||||
|
BytesRead = recvfrom ( s,
|
||||||
|
buffer,
|
||||||
|
length,
|
||||||
|
flags,
|
||||||
|
NULL,
|
||||||
|
NULL );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the number of bytes read
|
||||||
|
//
|
||||||
|
return BytesRead;
|
||||||
|
}
|
197
StdLib/BsdSocketLib/recvfrom.c
Normal file
197
StdLib/BsdSocketLib/recvfrom.c
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the recvfrom API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Receive data from a network connection and return the remote system's address.
|
||||||
|
|
||||||
|
The ::recvfrom routine waits for receive data from a remote network
|
||||||
|
connection. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] buffer Address of a buffer to receive the data.
|
||||||
|
|
||||||
|
@param [in] length Length of the buffer in bytes.
|
||||||
|
|
||||||
|
@param [in] flags Message control flags
|
||||||
|
|
||||||
|
@param [out] address Network address to receive the remote system address
|
||||||
|
|
||||||
|
@param [in] address_len Length of the remote network address structure
|
||||||
|
|
||||||
|
@returns ::recvfrom returns the number of valid bytes in the buffer,
|
||||||
|
zero if no data was received, and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
recvfrom (
|
||||||
|
int s,
|
||||||
|
void * buffer,
|
||||||
|
size_t length,
|
||||||
|
int flags,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
socklen_t ByteCount;
|
||||||
|
ssize_t LengthInBytes;
|
||||||
|
UINT8 * pData;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
struct timeval TimeVal;
|
||||||
|
EFI_EVENT pTimer;
|
||||||
|
UINT64 Timeout;
|
||||||
|
ssize_t TotalBytes;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
LengthInBytes = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Receive the data from the socket
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnReceive ( pSocketProtocol,
|
||||||
|
flags,
|
||||||
|
length,
|
||||||
|
buffer,
|
||||||
|
(size_t *)&LengthInBytes,
|
||||||
|
address,
|
||||||
|
address_len,
|
||||||
|
&errno );
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
LengthInBytes = -1;
|
||||||
|
if ( EAGAIN == errno ) {
|
||||||
|
//
|
||||||
|
// Get the timeout
|
||||||
|
//
|
||||||
|
ByteCount = sizeof ( TimeVal );
|
||||||
|
LengthInBytes = getsockopt ( s,
|
||||||
|
SOL_SOCKET,
|
||||||
|
SO_RCVTIMEO,
|
||||||
|
&TimeVal,
|
||||||
|
&ByteCount );
|
||||||
|
if ( 0 == LengthInBytes ) {
|
||||||
|
//
|
||||||
|
// Compute the timeout
|
||||||
|
//
|
||||||
|
Timeout = TimeVal.tv_sec;
|
||||||
|
Timeout *= 1000 * 1000;
|
||||||
|
Timeout += TimeVal.tv_usec;
|
||||||
|
Timeout *= 10;
|
||||||
|
|
||||||
|
//
|
||||||
|
// The timer is only necessary if a timeout is running
|
||||||
|
//
|
||||||
|
LengthInBytes = -1;
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
pTimer = NULL;
|
||||||
|
if ( 0 != Timeout ) {
|
||||||
|
Status = gBS->CreateEvent ( EVT_TIMER,
|
||||||
|
TPL_NOTIFY,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
&pTimer );
|
||||||
|
}
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Start the timer
|
||||||
|
//
|
||||||
|
if ( NULL != pTimer ) {
|
||||||
|
Status = gBS->SetTimer ( pTimer,
|
||||||
|
TimerRelative,
|
||||||
|
Timeout );
|
||||||
|
}
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Loop until data is received or the timeout
|
||||||
|
// expires
|
||||||
|
//
|
||||||
|
TotalBytes = 0;
|
||||||
|
pData = (UINT8 *)buffer;
|
||||||
|
do {
|
||||||
|
//
|
||||||
|
// Determine if the timeout expired
|
||||||
|
//
|
||||||
|
if ( NULL != pTimer ) {
|
||||||
|
Status = gBS->CheckEvent ( pTimer );
|
||||||
|
if ( EFI_SUCCESS == Status ) {
|
||||||
|
errno = ETIMEDOUT;
|
||||||
|
if ( 0 == TotalBytes ) {
|
||||||
|
TotalBytes = -1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Attempt to receive some data
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnReceive ( pSocketProtocol,
|
||||||
|
flags,
|
||||||
|
length,
|
||||||
|
pData,
|
||||||
|
(size_t *)&LengthInBytes,
|
||||||
|
address,
|
||||||
|
address_len,
|
||||||
|
&errno );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Account for the data received
|
||||||
|
//
|
||||||
|
TotalBytes += LengthInBytes;
|
||||||
|
pData += LengthInBytes;
|
||||||
|
length -= LengthInBytes;
|
||||||
|
}
|
||||||
|
} while ( EFI_NOT_READY == Status );
|
||||||
|
LengthInBytes = TotalBytes;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Stop the timer
|
||||||
|
//
|
||||||
|
if ( NULL != pTimer ) {
|
||||||
|
gBS->SetTimer ( pTimer,
|
||||||
|
TimerCancel,
|
||||||
|
0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release the timer
|
||||||
|
//
|
||||||
|
if ( NULL != pTimer ) {
|
||||||
|
gBS->CloseEvent ( pTimer );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the receive data length, -1 for errors
|
||||||
|
//
|
||||||
|
return LengthInBytes;
|
||||||
|
}
|
272
StdLib/BsdSocketLib/res_comp.c
Normal file
272
StdLib/BsdSocketLib/res_comp.c
Normal file
@ -0,0 +1,272 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1985, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char orig_rcsid[] = "From: Id: res_comp.c,v 8.11 1997/05/21 19:31:04 halley Exp $";
|
||||||
|
static char rcsid[] = "$Id: res_comp.c,v 1.1.1.1 2003/11/19 01:51:35 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define BIND_4_COMPAT
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Expand compressed domain name 'comp_dn' to full domain name.
|
||||||
|
* 'msg' is a pointer to the begining of the message,
|
||||||
|
* 'eomorig' points to the first location after the message,
|
||||||
|
* 'exp_dn' is a pointer to a buffer of size 'length' for the result.
|
||||||
|
* Return size of compressed name or -1 if there was an error.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
dn_expand(const u_char *msg, const u_char *eom, const u_char *src,
|
||||||
|
char *dst, int dstsiz)
|
||||||
|
{
|
||||||
|
int n = ns_name_uncompress(msg, eom, src, dst, (size_t)dstsiz);
|
||||||
|
|
||||||
|
if (n > 0 && dst[0] == '.')
|
||||||
|
dst[0] = '\0';
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Pack domain name 'exp_dn' in presentation form into 'comp_dn'.
|
||||||
|
* Return the size of the compressed name or -1.
|
||||||
|
* 'length' is the size of the array pointed to by 'comp_dn'.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
dn_comp(const char *src, u_char *dst, int dstsiz,
|
||||||
|
u_char **dnptrs, u_char **lastdnptr)
|
||||||
|
{
|
||||||
|
return (ns_name_compress(src, dst, (size_t)dstsiz,
|
||||||
|
(const u_char **)dnptrs,
|
||||||
|
(const u_char **)lastdnptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Skip over a compressed domain name. Return the size or -1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
dn_skipname(const u_char *ptr, const u_char *eom) {
|
||||||
|
const u_char *saveptr = ptr;
|
||||||
|
|
||||||
|
if (ns_name_skip(&ptr, eom) == -1)
|
||||||
|
return (-1);
|
||||||
|
return ((int)(ptr - saveptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Verify that a domain name uses an acceptable character set.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Note the conspicuous absence of ctype macros in these definitions. On
|
||||||
|
* non-ASCII hosts, we can't depend on string literals or ctype macros to
|
||||||
|
* tell us anything about network-format data. The rest of the BIND system
|
||||||
|
* is not careful about this, but for some reason, we're doing it right here.
|
||||||
|
*/
|
||||||
|
#define PERIOD 0x2e
|
||||||
|
#define hyphenchar(c) ((c) == 0x2d)
|
||||||
|
#define bslashchar(c) ((c) == 0x5c)
|
||||||
|
#define periodchar(c) ((c) == PERIOD)
|
||||||
|
#define asterchar(c) ((c) == 0x2a)
|
||||||
|
#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) \
|
||||||
|
|| ((c) >= 0x61 && (c) <= 0x7a))
|
||||||
|
#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
|
||||||
|
|
||||||
|
#define borderchar(c) (alphachar(c) || digitchar(c))
|
||||||
|
#define middlechar(c) (borderchar(c) || hyphenchar(c))
|
||||||
|
#define domainchar(c) ((c) > 0x20 && (c) < 0x7f)
|
||||||
|
|
||||||
|
int
|
||||||
|
res_hnok(
|
||||||
|
const char *dn
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int ppch = '\0', pch = PERIOD, ch = *dn++;
|
||||||
|
|
||||||
|
while (ch != '\0') {
|
||||||
|
int nch = *dn++;
|
||||||
|
|
||||||
|
if (periodchar(ch)) {
|
||||||
|
(void)NULL;
|
||||||
|
} else if (periodchar(pch)) {
|
||||||
|
if (!borderchar(ch))
|
||||||
|
return (0);
|
||||||
|
} else if (periodchar(nch) || nch == '\0') {
|
||||||
|
if (!borderchar(ch))
|
||||||
|
return (0);
|
||||||
|
} else {
|
||||||
|
if (!middlechar(ch))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
ppch = pch, pch = ch, ch = nch;
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* hostname-like (A, MX, WKS) owners can have "*" as their first label
|
||||||
|
* but must otherwise be as a host name.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_ownok(
|
||||||
|
const char *dn
|
||||||
|
)
|
||||||
|
{
|
||||||
|
if (asterchar(dn[0])) {
|
||||||
|
if (periodchar(dn[1]))
|
||||||
|
return (res_hnok(dn+2));
|
||||||
|
if (dn[1] == '\0')
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (res_hnok(dn));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SOA RNAMEs and RP RNAMEs can have any printable character in their first
|
||||||
|
* label, but the rest of the name has to look like a host name.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_mailok(
|
||||||
|
const char *dn
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int ch, escaped = 0;
|
||||||
|
|
||||||
|
/* "." is a valid missing representation */
|
||||||
|
if (*dn == '\0')
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
/* otherwise <label>.<hostname> */
|
||||||
|
while ((ch = *dn++) != '\0') {
|
||||||
|
if (!domainchar(ch))
|
||||||
|
return (0);
|
||||||
|
if (!escaped && periodchar(ch))
|
||||||
|
break;
|
||||||
|
if (escaped)
|
||||||
|
escaped = 0;
|
||||||
|
else if (bslashchar(ch))
|
||||||
|
escaped = 1;
|
||||||
|
}
|
||||||
|
if (periodchar(ch))
|
||||||
|
return (res_hnok(dn));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function is quite liberal, since RFC 1034's character sets are only
|
||||||
|
* recommendations.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_dnok(
|
||||||
|
const char *dn
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int ch;
|
||||||
|
|
||||||
|
while ((ch = *dn++) != '\0')
|
||||||
|
if (!domainchar(ch))
|
||||||
|
return (0);
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef BIND_4_COMPAT
|
||||||
|
/*
|
||||||
|
* This module must export the following externally-visible symbols:
|
||||||
|
* ___putlong
|
||||||
|
* ___putshort
|
||||||
|
* __getlong
|
||||||
|
* __getshort
|
||||||
|
* Note that one _ comes from C and the others come from us.
|
||||||
|
*/
|
||||||
|
void __putlong(u_int32_t src, u_char *dst) { ns_put32(src, dst); }
|
||||||
|
void __putshort(u_int16_t src, u_char *dst) { ns_put16(src, dst); }
|
||||||
|
u_int32_t _getlong(const u_char *src) { return (ns_get32(src)); }
|
||||||
|
u_int16_t _getshort(const u_char *src) { return (ns_get16(src)); }
|
||||||
|
#endif /*BIND_4_COMPAT*/
|
8
StdLib/BsdSocketLib/res_config.h
Normal file
8
StdLib/BsdSocketLib/res_config.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#define DEBUG 1 /* enable debugging code (needed for dig) */
|
||||||
|
#define RESOLVSORT /* allow sorting of addresses in gethostbyname */
|
||||||
|
#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/
|
||||||
|
#undef USELOOPBACK /* res_init() bind to localhost */
|
||||||
|
#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */
|
||||||
|
#define MULTI_PTRS_ARE_ALIASES 1 /* fold multiple PTR records into aliases */
|
||||||
|
#define CHECK_SRVR_ADDR 1 /* confirm that the server requested sent the reply */
|
||||||
|
#define BIND_UPDATE 1 /* update support */
|
83
StdLib/BsdSocketLib/res_data.c
Normal file
83
StdLib/BsdSocketLib/res_data.c
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1995,1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char rcsid[] = "$Id: res_data.c,v 1.1.1.1 2003/11/19 01:51:35 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
|
||||||
|
const char *_res_opcodes[] = {
|
||||||
|
"QUERY",
|
||||||
|
"IQUERY",
|
||||||
|
"CQUERYM",
|
||||||
|
"CQUERYU", /* experimental */
|
||||||
|
"NOTIFY", /* experimental */
|
||||||
|
"UPDATE",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9",
|
||||||
|
"10",
|
||||||
|
"11",
|
||||||
|
"12",
|
||||||
|
"13",
|
||||||
|
"ZONEINIT",
|
||||||
|
"ZONEREF",
|
||||||
|
};
|
||||||
|
|
||||||
|
const char *_res_resultcodes[] = {
|
||||||
|
"NOERROR",
|
||||||
|
"FORMERR",
|
||||||
|
"SERVFAIL",
|
||||||
|
"NXDOMAIN",
|
||||||
|
"NOTIMP",
|
||||||
|
"REFUSED",
|
||||||
|
"YXDOMAIN",
|
||||||
|
"YXRRSET",
|
||||||
|
"NXRRSET",
|
||||||
|
"NOTAUTH",
|
||||||
|
"ZONEERR",
|
||||||
|
"11",
|
||||||
|
"12",
|
||||||
|
"13",
|
||||||
|
"14",
|
||||||
|
"NOCHANGE",
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef BIND_UPDATE
|
||||||
|
const char *_res_sectioncodes[] = {
|
||||||
|
"ZONE",
|
||||||
|
"PREREQUISITES",
|
||||||
|
"UPDATE",
|
||||||
|
"ADDITIONAL",
|
||||||
|
};
|
||||||
|
#endif
|
988
StdLib/BsdSocketLib/res_debug.c
Normal file
988
StdLib/BsdSocketLib/res_debug.c
Normal file
@ -0,0 +1,988 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1985
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1995 by International Business Machines, Inc.
|
||||||
|
*
|
||||||
|
* International Business Machines, Inc. (hereinafter called IBM) grants
|
||||||
|
* permission under its copyrights to use, copy, modify, and distribute this
|
||||||
|
* Software with or without fee, provided that the above copyright notice and
|
||||||
|
* all paragraphs of this notice appear in all copies, and that the name of IBM
|
||||||
|
* not be used in connection with the marketing of any product incorporating
|
||||||
|
* the Software or modifications thereof, without specific, written prior
|
||||||
|
* permission.
|
||||||
|
*
|
||||||
|
* To the extent it has a right to do so, IBM grants an immunity from suit
|
||||||
|
* under its patents, if any, for the use, sale or manufacture of products to
|
||||||
|
* the extent that such products are used for performing Domain Name System
|
||||||
|
* dynamic updates in TCP/IP networks by means of the Software. No immunity is
|
||||||
|
* granted for any product per se or for any other function of any product.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
|
||||||
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
|
||||||
|
* DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
|
||||||
|
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char rcsid[] = "$Id: res_debug.c,v 1.1.1.1 2003/11/19 01:51:36 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#define SPRINTF(x) sprintf x
|
||||||
|
|
||||||
|
extern const char *_res_opcodes[];
|
||||||
|
extern const char *_res_resultcodes[];
|
||||||
|
extern const char *_res_sectioncodes[];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print the current options.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
fp_resstat(struct __res_state *statp, FILE *file) {
|
||||||
|
u_long mask;
|
||||||
|
|
||||||
|
fprintf(file, ";; res options:");
|
||||||
|
if (!statp)
|
||||||
|
statp = &_res;
|
||||||
|
for (mask = 1; mask != 0; mask <<= 1)
|
||||||
|
if (statp->options & mask)
|
||||||
|
fprintf(file, " %s", p_option(mask));
|
||||||
|
putc('\n', file);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
do_section(ns_msg *handle, ns_sect section, int pflag, FILE *file) {
|
||||||
|
int n, sflag, rrnum;
|
||||||
|
ns_opcode opcode;
|
||||||
|
ns_rr rr;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print answer records.
|
||||||
|
*/
|
||||||
|
sflag = (int)(_res.pfcode & pflag);
|
||||||
|
if (_res.pfcode && !sflag)
|
||||||
|
return;
|
||||||
|
|
||||||
|
opcode = ns_msg_getflag(*handle, ns_f_opcode);
|
||||||
|
rrnum = 0;
|
||||||
|
for (;;) {
|
||||||
|
if (ns_parserr(handle, section, rrnum, &rr)) {
|
||||||
|
if (errno != ENODEV)
|
||||||
|
fprintf(file, ";; ns_parserr: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
else if (rrnum > 0 && sflag != 0 &&
|
||||||
|
(_res.pfcode & RES_PRF_HEAD1))
|
||||||
|
putc('\n', file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (rrnum == 0 && sflag != 0 && (_res.pfcode & RES_PRF_HEAD1))
|
||||||
|
fprintf(file, ";; %s SECTION:\n",
|
||||||
|
p_section(section, opcode));
|
||||||
|
if (section == ns_s_qd)
|
||||||
|
fprintf(file, ";;\t%s, type = %s, class = %s\n",
|
||||||
|
ns_rr_name(rr),
|
||||||
|
p_type(ns_rr_type(rr)),
|
||||||
|
p_class(ns_rr_class(rr)));
|
||||||
|
else {
|
||||||
|
char *buf;
|
||||||
|
buf = (char*)malloc(2024);
|
||||||
|
if (buf) {
|
||||||
|
n = ns_sprintrr(handle, &rr, NULL, NULL,
|
||||||
|
buf, sizeof buf);
|
||||||
|
if (n < 0) {
|
||||||
|
fprintf(file, ";; ns_sprintrr: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
free(buf);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fputs(buf, file);
|
||||||
|
fputc('\n', file);
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rrnum++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
p_query(const u_char *msg) {
|
||||||
|
fp_query(msg, stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
fp_query(const u_char *msg, FILE *file) {
|
||||||
|
fp_nquery(msg, PACKETSZ, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print the contents of a query.
|
||||||
|
* This is intended to be primarily a debugging routine.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
fp_nquery(const u_char *msg, int len, FILE *file) {
|
||||||
|
ns_msg handle;
|
||||||
|
int qdcount, ancount, nscount, arcount;
|
||||||
|
u_int opcode, rcode, id;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (ns_initparse(msg, len, &handle) < 0) {
|
||||||
|
fprintf(file, ";; ns_initparse: %s\n", strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
opcode = ns_msg_getflag(handle, ns_f_opcode);
|
||||||
|
rcode = ns_msg_getflag(handle, ns_f_rcode);
|
||||||
|
id = ns_msg_id(handle);
|
||||||
|
qdcount = ns_msg_count(handle, ns_s_qd);
|
||||||
|
ancount = ns_msg_count(handle, ns_s_an);
|
||||||
|
nscount = ns_msg_count(handle, ns_s_ns);
|
||||||
|
arcount = ns_msg_count(handle, ns_s_ar);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Print header fields.
|
||||||
|
*/
|
||||||
|
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX) || rcode)
|
||||||
|
fprintf(file,
|
||||||
|
";; ->>HEADER<<- opcode: %s, status: %s, id: %d\n",
|
||||||
|
_res_opcodes[opcode], _res_resultcodes[rcode], id);
|
||||||
|
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
|
||||||
|
putc(';', file);
|
||||||
|
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
|
||||||
|
fprintf(file, "; flags:");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_qr))
|
||||||
|
fprintf(file, " qr");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_aa))
|
||||||
|
fprintf(file, " aa");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_tc))
|
||||||
|
fprintf(file, " tc");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_rd))
|
||||||
|
fprintf(file, " rd");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_ra))
|
||||||
|
fprintf(file, " ra");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_z))
|
||||||
|
fprintf(file, " ??");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_ad))
|
||||||
|
fprintf(file, " ad");
|
||||||
|
if (ns_msg_getflag(handle, ns_f_cd))
|
||||||
|
fprintf(file, " cd");
|
||||||
|
}
|
||||||
|
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
|
||||||
|
fprintf(file, "; %s: %d",
|
||||||
|
p_section(ns_s_qd, (int)opcode), qdcount);
|
||||||
|
fprintf(file, ", %s: %d",
|
||||||
|
p_section(ns_s_an, (int)opcode), ancount);
|
||||||
|
fprintf(file, ", %s: %d",
|
||||||
|
p_section(ns_s_ns, (int)opcode), nscount);
|
||||||
|
fprintf(file, ", %s: %d",
|
||||||
|
p_section(ns_s_ar, (int)opcode), arcount);
|
||||||
|
}
|
||||||
|
if ((!_res.pfcode) || (_res.pfcode &
|
||||||
|
(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
|
||||||
|
putc('\n',file);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Print the various sections.
|
||||||
|
*/
|
||||||
|
do_section(&handle, ns_s_qd, RES_PRF_QUES, file);
|
||||||
|
do_section(&handle, ns_s_an, RES_PRF_ANS, file);
|
||||||
|
do_section(&handle, ns_s_ns, RES_PRF_AUTH, file);
|
||||||
|
do_section(&handle, ns_s_ar, RES_PRF_ADD, file);
|
||||||
|
if (qdcount == 0 && ancount == 0 &&
|
||||||
|
nscount == 0 && arcount == 0)
|
||||||
|
putc('\n', file);
|
||||||
|
}
|
||||||
|
|
||||||
|
const u_char *
|
||||||
|
p_cdnname(const u_char *cp, const u_char *msg, int len, FILE *file) {
|
||||||
|
char name[MAXDNAME];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
if ((n = dn_expand(msg, msg + len, cp, name, sizeof name)) < 0)
|
||||||
|
return (NULL);
|
||||||
|
if (name[0] == '\0')
|
||||||
|
putc('.', file);
|
||||||
|
else
|
||||||
|
fputs(name, file);
|
||||||
|
return (cp + n);
|
||||||
|
}
|
||||||
|
|
||||||
|
const u_char *
|
||||||
|
p_cdname(const u_char *cp, const u_char *msg, FILE *file) {
|
||||||
|
return (p_cdnname(cp, msg, PACKETSZ, file));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return a fully-qualified domain name from a compressed name (with
|
||||||
|
length supplied). */
|
||||||
|
|
||||||
|
const u_char *
|
||||||
|
p_fqnname(
|
||||||
|
const u_char *cp,
|
||||||
|
const u_char *msg,
|
||||||
|
int msglen,
|
||||||
|
char *name,
|
||||||
|
int namelen
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int n, newlen;
|
||||||
|
|
||||||
|
if ((n = dn_expand(msg, cp + msglen, cp, name, namelen)) < 0)
|
||||||
|
return (NULL);
|
||||||
|
newlen = (int)strlen(name);
|
||||||
|
if (newlen == 0 || name[newlen - 1] != '.') {
|
||||||
|
if (newlen + 1 >= namelen) /* Lack space for final dot */
|
||||||
|
return (NULL);
|
||||||
|
else
|
||||||
|
strcpy(name + newlen, ".");
|
||||||
|
}
|
||||||
|
return (cp + n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* XXX: the rest of these functions need to become length-limited, too. */
|
||||||
|
|
||||||
|
const u_char *
|
||||||
|
p_fqname(const u_char *cp, const u_char *msg, FILE *file) {
|
||||||
|
char name[MAXDNAME];
|
||||||
|
const u_char *n;
|
||||||
|
|
||||||
|
n = p_fqnname(cp, msg, MAXCDNAME, name, sizeof name);
|
||||||
|
if (n == NULL)
|
||||||
|
return (NULL);
|
||||||
|
fputs(name, file);
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Names of RR classes and qclasses. Classes and qclasses are the same, except
|
||||||
|
* that C_ANY is a qclass but not a class. (You can ask for records of class
|
||||||
|
* C_ANY, but you can't have any records of that class in the database.)
|
||||||
|
*/
|
||||||
|
const struct res_sym __p_class_syms[] = {
|
||||||
|
{C_IN, "IN"},
|
||||||
|
{C_CHAOS, "CHAOS"},
|
||||||
|
{C_HS, "HS"},
|
||||||
|
{C_HS, "HESIOD"},
|
||||||
|
{C_ANY, "ANY"},
|
||||||
|
{C_NONE, "NONE"},
|
||||||
|
{C_IN, (char *)0}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Names of message sections.
|
||||||
|
*/
|
||||||
|
const struct res_sym __p_default_section_syms[] = {
|
||||||
|
{ns_s_qd, "QUERY"},
|
||||||
|
{ns_s_an, "ANSWER"},
|
||||||
|
{ns_s_ns, "AUTHORITY"},
|
||||||
|
{ns_s_ar, "ADDITIONAL"},
|
||||||
|
{0, (char *)0}
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct res_sym __p_update_section_syms[] = {
|
||||||
|
{S_ZONE, "ZONE"},
|
||||||
|
{S_PREREQ, "PREREQUISITE"},
|
||||||
|
{S_UPDATE, "UPDATE"},
|
||||||
|
{S_ADDT, "ADDITIONAL"},
|
||||||
|
{0, (char *)0}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Names of RR types and qtypes. Types and qtypes are the same, except
|
||||||
|
* that T_ANY is a qtype but not a type. (You can ask for records of type
|
||||||
|
* T_ANY, but you can't have any records of that type in the database.)
|
||||||
|
*/
|
||||||
|
const struct res_sym __p_type_syms[] = {
|
||||||
|
{T_A, "A", "address"},
|
||||||
|
{T_NS, "NS", "name server"},
|
||||||
|
{T_MD, "MD", "mail destination (deprecated)"},
|
||||||
|
{T_MF, "MF", "mail forwarder (deprecated)"},
|
||||||
|
{T_CNAME, "CNAME", "canonical name"},
|
||||||
|
{T_SOA, "SOA", "start of authority"},
|
||||||
|
{T_MB, "MB", "mailbox"},
|
||||||
|
{T_MG, "MG", "mail group member"},
|
||||||
|
{T_MR, "MR", "mail rename"},
|
||||||
|
{T_NULL, "NULL", "null"},
|
||||||
|
{T_WKS, "WKS", "well-known service (deprecated)"},
|
||||||
|
{T_PTR, "PTR", "domain name pointer"},
|
||||||
|
{T_HINFO, "HINFO", "host information"},
|
||||||
|
{T_MINFO, "MINFO", "mailbox information"},
|
||||||
|
{T_MX, "MX", "mail exchanger"},
|
||||||
|
{T_TXT, "TXT", "text"},
|
||||||
|
{T_RP, "RP", "responsible person"},
|
||||||
|
{T_AFSDB, "AFSDB", "DCE or AFS server"},
|
||||||
|
{T_X25, "X25", "X25 address"},
|
||||||
|
{T_ISDN, "ISDN", "ISDN address"},
|
||||||
|
{T_RT, "RT", "router"},
|
||||||
|
{T_NSAP, "NSAP", "nsap address"},
|
||||||
|
{T_NSAP_PTR, "NSAP_PTR", "domain name pointer"},
|
||||||
|
{T_SIG, "SIG", "signature"},
|
||||||
|
{T_KEY, "KEY", "key"},
|
||||||
|
{T_PX, "PX", "mapping information"},
|
||||||
|
{T_GPOS, "GPOS", "geographical position (withdrawn)"},
|
||||||
|
{T_AAAA, "AAAA", "IPv6 address"},
|
||||||
|
{T_LOC, "LOC", "location"},
|
||||||
|
{T_NXT, "NXT", "next valid name (unimplemented)"},
|
||||||
|
{T_EID, "EID", "endpoint identifier (unimplemented)"},
|
||||||
|
{T_NIMLOC, "NIMLOC", "NIMROD locator (unimplemented)"},
|
||||||
|
{T_SRV, "SRV", "server selection"},
|
||||||
|
{T_ATMA, "ATMA", "ATM address (unimplemented)"},
|
||||||
|
{T_IXFR, "IXFR", "incremental zone transfer"},
|
||||||
|
{T_AXFR, "AXFR", "zone transfer"},
|
||||||
|
{T_MAILB, "MAILB", "mailbox-related data (deprecated)"},
|
||||||
|
{T_MAILA, "MAILA", "mail agent (deprecated)"},
|
||||||
|
{T_NAPTR, "NAPTR", "URN Naming Authority"},
|
||||||
|
{T_ANY, "ANY", "\"any\""},
|
||||||
|
{0, NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
int
|
||||||
|
sym_ston(const struct res_sym *syms, const char *name, int *success) {
|
||||||
|
for ((void)NULL; syms->name != 0; syms++) {
|
||||||
|
if (strcasecmp (name, syms->name) == 0) {
|
||||||
|
if (success)
|
||||||
|
*success = 1;
|
||||||
|
return (syms->number);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (success)
|
||||||
|
*success = 0;
|
||||||
|
return (syms->number); /* The default value. */
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
sym_ntos(const struct res_sym *syms, int number, int *success) {
|
||||||
|
static char unname[20];
|
||||||
|
|
||||||
|
for ((void)NULL; syms->name != 0; syms++) {
|
||||||
|
if (number == syms->number) {
|
||||||
|
if (success)
|
||||||
|
*success = 1;
|
||||||
|
return (syms->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sprintf(unname, "%d", number);
|
||||||
|
if (success)
|
||||||
|
*success = 0;
|
||||||
|
return (unname);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
sym_ntop(const struct res_sym *syms, int number, int *success) {
|
||||||
|
static char unname[20];
|
||||||
|
|
||||||
|
for ((void)NULL; syms->name != 0; syms++) {
|
||||||
|
if (number == syms->number) {
|
||||||
|
if (success)
|
||||||
|
*success = 1;
|
||||||
|
return (syms->humanname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sprintf(unname, "%d", number);
|
||||||
|
if (success)
|
||||||
|
*success = 0;
|
||||||
|
return (unname);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a string for the type.
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
p_type(int type) {
|
||||||
|
return (sym_ntos(__p_type_syms, type, (int *)0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a string for the type.
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
p_section(int section, int opcode) {
|
||||||
|
const struct res_sym *symbols;
|
||||||
|
|
||||||
|
switch (opcode) {
|
||||||
|
case ns_o_update:
|
||||||
|
symbols = __p_update_section_syms;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
symbols = __p_default_section_syms;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (sym_ntos(symbols, section, (int *)0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a mnemonic for class.
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
p_class(int class) {
|
||||||
|
return (sym_ntos(__p_class_syms, class, (int *)0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a mnemonic for an option
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
p_option(u_long option) {
|
||||||
|
static char nbuf[40];
|
||||||
|
|
||||||
|
switch (option) {
|
||||||
|
case RES_INIT: return "init";
|
||||||
|
case RES_DEBUG: return "debug";
|
||||||
|
case RES_AAONLY: return "aaonly(unimpl)";
|
||||||
|
case RES_USEVC: return "usevc";
|
||||||
|
case RES_PRIMARY: return "primry(unimpl)";
|
||||||
|
case RES_IGNTC: return "igntc";
|
||||||
|
case RES_RECURSE: return "recurs";
|
||||||
|
case RES_DEFNAMES: return "defnam";
|
||||||
|
case RES_STAYOPEN: return "styopn";
|
||||||
|
case RES_DNSRCH: return "dnsrch";
|
||||||
|
case RES_INSECURE1: return "insecure1";
|
||||||
|
case RES_INSECURE2: return "insecure2";
|
||||||
|
default: sprintf(nbuf, "?0x%lx?", (u_long)option);
|
||||||
|
return (nbuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Return a mnemonic for a time to live.
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
p_time(u_int32_t value) {
|
||||||
|
static char nbuf[40];
|
||||||
|
|
||||||
|
if (ns_format_ttl(value, nbuf, sizeof nbuf) < 0)
|
||||||
|
sprintf(nbuf, "%u", value);
|
||||||
|
return (nbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* routines to convert between on-the-wire RR format and zone file format.
|
||||||
|
* Does not contain conversion to/from decimal degrees; divide or multiply
|
||||||
|
* by 60*60*1000 for that.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static unsigned int poweroften[10] = {1, 10, 100, 1000, 10000, 100000,
|
||||||
|
1000000,10000000,100000000,1000000000};
|
||||||
|
|
||||||
|
/* takes an XeY precision/size value, returns a string representation. */
|
||||||
|
static const char *
|
||||||
|
precsize_ntoa(
|
||||||
|
u_int8_t prec
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static char retbuf[sizeof "90000000.00"];
|
||||||
|
unsigned long val;
|
||||||
|
int mantissa, exponent;
|
||||||
|
|
||||||
|
mantissa = (int)((prec >> 4) & 0x0f) % 10;
|
||||||
|
exponent = (int)((prec >> 0) & 0x0f) % 10;
|
||||||
|
|
||||||
|
val = mantissa * poweroften[exponent];
|
||||||
|
|
||||||
|
(void) sprintf(retbuf, "%ld.%.2ld", val/100, val%100);
|
||||||
|
return (retbuf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* converts ascii size/precision X * 10**Y(cm) to 0xXY. moves pointer. */
|
||||||
|
static u_int8_t
|
||||||
|
precsize_aton(
|
||||||
|
char **strptr
|
||||||
|
)
|
||||||
|
{
|
||||||
|
unsigned int mval = 0, cmval = 0;
|
||||||
|
u_int8_t retval = 0;
|
||||||
|
char *cp;
|
||||||
|
int exponent;
|
||||||
|
int mantissa;
|
||||||
|
|
||||||
|
cp = *strptr;
|
||||||
|
|
||||||
|
while (isdigit(*cp))
|
||||||
|
mval = mval * 10 + (*cp++ - '0');
|
||||||
|
|
||||||
|
if (*cp == '.') { /* centimeters */
|
||||||
|
cp++;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
cmval = (*cp++ - '0') * 10;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
cmval += (*cp++ - '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmval = (mval * 100) + cmval;
|
||||||
|
|
||||||
|
for (exponent = 0; exponent < 9; exponent++)
|
||||||
|
if (cmval < poweroften[exponent+1])
|
||||||
|
break;
|
||||||
|
|
||||||
|
mantissa = cmval / poweroften[exponent];
|
||||||
|
if (mantissa > 9)
|
||||||
|
mantissa = 9;
|
||||||
|
|
||||||
|
retval = (u_int8_t)((mantissa << 4) | exponent);
|
||||||
|
|
||||||
|
*strptr = cp;
|
||||||
|
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* converts ascii lat/lon to unsigned encoded 32-bit number. moves pointer. */
|
||||||
|
static u_int32_t
|
||||||
|
latlon2ul(
|
||||||
|
char **latlonstrptr,
|
||||||
|
int *which
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char *cp;
|
||||||
|
u_int32_t retval;
|
||||||
|
int deg = 0, min = 0, secs = 0, secsfrac = 0;
|
||||||
|
|
||||||
|
cp = *latlonstrptr;
|
||||||
|
|
||||||
|
while (isdigit(*cp))
|
||||||
|
deg = deg * 10 + (*cp++ - '0');
|
||||||
|
|
||||||
|
while (isspace(*cp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
if (!(isdigit(*cp)))
|
||||||
|
goto fndhemi;
|
||||||
|
|
||||||
|
while (isdigit(*cp))
|
||||||
|
min = min * 10 + (*cp++ - '0');
|
||||||
|
|
||||||
|
while (isspace(*cp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
if (!(isdigit(*cp)))
|
||||||
|
goto fndhemi;
|
||||||
|
|
||||||
|
while (isdigit(*cp))
|
||||||
|
secs = secs * 10 + (*cp++ - '0');
|
||||||
|
|
||||||
|
if (*cp == '.') { /* decimal seconds */
|
||||||
|
cp++;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
secsfrac = (*cp++ - '0') * 100;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
secsfrac += (*cp++ - '0') * 10;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
secsfrac += (*cp++ - '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!isspace(*cp)) /* if any trailing garbage */
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
while (isspace(*cp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
fndhemi:
|
||||||
|
switch (*cp) {
|
||||||
|
case 'N': case 'n':
|
||||||
|
case 'E': case 'e':
|
||||||
|
retval = ((unsigned)1<<31)
|
||||||
|
+ (((((deg * 60) + min) * 60) + secs) * 1000)
|
||||||
|
+ secsfrac;
|
||||||
|
break;
|
||||||
|
case 'S': case 's':
|
||||||
|
case 'W': case 'w':
|
||||||
|
retval = ((unsigned)1<<31)
|
||||||
|
- (((((deg * 60) + min) * 60) + secs) * 1000)
|
||||||
|
- secsfrac;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
retval = 0; /* invalid value -- indicates error */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (*cp) {
|
||||||
|
case 'N': case 'n':
|
||||||
|
case 'S': case 's':
|
||||||
|
*which = 1; /* latitude */
|
||||||
|
break;
|
||||||
|
case 'E': case 'e':
|
||||||
|
case 'W': case 'w':
|
||||||
|
*which = 2; /* longitude */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*which = 0; /* error */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
cp++; /* skip the hemisphere */
|
||||||
|
|
||||||
|
while (!isspace(*cp)) /* if any trailing garbage */
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
while (isspace(*cp)) /* move to next field */
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
*latlonstrptr = cp;
|
||||||
|
|
||||||
|
return (retval);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* converts a zone file representation in a string to an RDATA on-the-wire
|
||||||
|
* representation. */
|
||||||
|
int
|
||||||
|
loc_aton(
|
||||||
|
const char *ascii,
|
||||||
|
u_char *binary
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const char *cp, *maxcp;
|
||||||
|
u_char *bcp;
|
||||||
|
|
||||||
|
u_int32_t latit = 0, longit = 0, alt = 0;
|
||||||
|
u_int32_t lltemp1 = 0, lltemp2 = 0;
|
||||||
|
int altmeters = 0, altfrac = 0, altsign = 1;
|
||||||
|
u_int8_t hp = 0x16; /* default = 1e6 cm = 10000.00m = 10km */
|
||||||
|
u_int8_t vp = 0x13; /* default = 1e3 cm = 10.00m */
|
||||||
|
u_int8_t siz = 0x12; /* default = 1e2 cm = 1.00m */
|
||||||
|
int which1 = 0, which2 = 0;
|
||||||
|
|
||||||
|
cp = ascii;
|
||||||
|
maxcp = cp + strlen(ascii);
|
||||||
|
|
||||||
|
lltemp1 = latlon2ul((char **)&cp, &which1);
|
||||||
|
|
||||||
|
lltemp2 = latlon2ul((char **)&cp, &which2);
|
||||||
|
|
||||||
|
switch (which1 + which2) {
|
||||||
|
case 3: /* 1 + 2, the only valid combination */
|
||||||
|
if ((which1 == 1) && (which2 == 2)) { /* normal case */
|
||||||
|
latit = lltemp1;
|
||||||
|
longit = lltemp2;
|
||||||
|
} else if ((which1 == 2) && (which2 == 1)) { /* reversed */
|
||||||
|
longit = lltemp1;
|
||||||
|
latit = lltemp2;
|
||||||
|
} else { /* some kind of brokenness */
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: /* we didn't get one of each */
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* altitude */
|
||||||
|
if (*cp == '-') {
|
||||||
|
altsign = -1;
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*cp == '+')
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
while (isdigit(*cp))
|
||||||
|
altmeters = altmeters * 10 + (*cp++ - '0');
|
||||||
|
|
||||||
|
if (*cp == '.') { /* decimal meters */
|
||||||
|
cp++;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
altfrac = (*cp++ - '0') * 10;
|
||||||
|
if (isdigit(*cp)) {
|
||||||
|
altfrac += (*cp++ - '0');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
alt = (10000000 + (altsign * (altmeters * 100 + altfrac)));
|
||||||
|
|
||||||
|
while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
while (isspace(*cp) && (cp < maxcp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
if (cp >= maxcp)
|
||||||
|
goto defaults;
|
||||||
|
|
||||||
|
siz = precsize_aton((char **)&cp);
|
||||||
|
|
||||||
|
while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
while (isspace(*cp) && (cp < maxcp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
if (cp >= maxcp)
|
||||||
|
goto defaults;
|
||||||
|
|
||||||
|
hp = precsize_aton((char **)&cp);
|
||||||
|
|
||||||
|
while (!isspace(*cp) && (cp < maxcp)) /* if trailing garbage or m */
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
while (isspace(*cp) && (cp < maxcp))
|
||||||
|
cp++;
|
||||||
|
|
||||||
|
if (cp >= maxcp)
|
||||||
|
goto defaults;
|
||||||
|
|
||||||
|
vp = precsize_aton((char **)&cp);
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
|
||||||
|
bcp = binary;
|
||||||
|
*bcp++ = (u_int8_t) 0; /* version byte */
|
||||||
|
*bcp++ = siz;
|
||||||
|
*bcp++ = hp;
|
||||||
|
*bcp++ = vp;
|
||||||
|
PUTLONG(latit,bcp);
|
||||||
|
PUTLONG(longit,bcp);
|
||||||
|
PUTLONG(alt,bcp);
|
||||||
|
|
||||||
|
return (16); /* size of RR in octets */
|
||||||
|
}
|
||||||
|
|
||||||
|
/* takes an on-the-wire LOC RR and formats it in a human readable format. */
|
||||||
|
const char *
|
||||||
|
loc_ntoa(
|
||||||
|
const u_char *binary,
|
||||||
|
char *ascii
|
||||||
|
)
|
||||||
|
{
|
||||||
|
static char *error = "?";
|
||||||
|
const u_char *cp = binary;
|
||||||
|
|
||||||
|
int latdeg, latmin, latsec, latsecfrac;
|
||||||
|
int longdeg, longmin, longsec, longsecfrac;
|
||||||
|
char northsouth, eastwest;
|
||||||
|
int altmeters, altfrac, altsign;
|
||||||
|
|
||||||
|
const u_int32_t referencealt = 100000 * 100;
|
||||||
|
|
||||||
|
int32_t latval, longval, altval;
|
||||||
|
u_int32_t templ;
|
||||||
|
u_int8_t sizeval, hpval, vpval, versionval;
|
||||||
|
|
||||||
|
char *sizestr, *hpstr, *vpstr;
|
||||||
|
|
||||||
|
versionval = *cp++;
|
||||||
|
|
||||||
|
if (versionval) {
|
||||||
|
(void) sprintf(ascii, "; error: unknown LOC RR version");
|
||||||
|
return (ascii);
|
||||||
|
}
|
||||||
|
|
||||||
|
sizeval = *cp++;
|
||||||
|
|
||||||
|
hpval = *cp++;
|
||||||
|
vpval = *cp++;
|
||||||
|
|
||||||
|
GETLONG(templ, cp);
|
||||||
|
latval = (templ - ((unsigned)1<<31));
|
||||||
|
|
||||||
|
GETLONG(templ, cp);
|
||||||
|
longval = (templ - ((unsigned)1<<31));
|
||||||
|
|
||||||
|
GETLONG(templ, cp);
|
||||||
|
if (templ < referencealt) { /* below WGS 84 spheroid */
|
||||||
|
altval = referencealt - templ;
|
||||||
|
altsign = -1;
|
||||||
|
} else {
|
||||||
|
altval = templ - referencealt;
|
||||||
|
altsign = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (latval < 0) {
|
||||||
|
northsouth = 'S';
|
||||||
|
latval = -latval;
|
||||||
|
} else
|
||||||
|
northsouth = 'N';
|
||||||
|
|
||||||
|
latsecfrac = latval % 1000;
|
||||||
|
latval = latval / 1000;
|
||||||
|
latsec = latval % 60;
|
||||||
|
latval = latval / 60;
|
||||||
|
latmin = latval % 60;
|
||||||
|
latval = latval / 60;
|
||||||
|
latdeg = latval;
|
||||||
|
|
||||||
|
if (longval < 0) {
|
||||||
|
eastwest = 'W';
|
||||||
|
longval = -longval;
|
||||||
|
} else
|
||||||
|
eastwest = 'E';
|
||||||
|
|
||||||
|
longsecfrac = longval % 1000;
|
||||||
|
longval = longval / 1000;
|
||||||
|
longsec = longval % 60;
|
||||||
|
longval = longval / 60;
|
||||||
|
longmin = longval % 60;
|
||||||
|
longval = longval / 60;
|
||||||
|
longdeg = longval;
|
||||||
|
|
||||||
|
altfrac = altval % 100;
|
||||||
|
altmeters = (altval / 100) * altsign;
|
||||||
|
|
||||||
|
if ((sizestr = strdup(precsize_ntoa(sizeval))) == NULL)
|
||||||
|
sizestr = error;
|
||||||
|
if ((hpstr = strdup(precsize_ntoa(hpval))) == NULL)
|
||||||
|
hpstr = error;
|
||||||
|
if ((vpstr = strdup(precsize_ntoa(vpval))) == NULL)
|
||||||
|
vpstr = error;
|
||||||
|
|
||||||
|
sprintf(ascii,
|
||||||
|
"%d %.2d %.2d.%.3d %c %d %.2d %.2d.%.3d %c %d.%.2dm %sm %sm %sm",
|
||||||
|
latdeg, latmin, latsec, latsecfrac, northsouth,
|
||||||
|
longdeg, longmin, longsec, longsecfrac, eastwest,
|
||||||
|
altmeters, altfrac, sizestr, hpstr, vpstr);
|
||||||
|
|
||||||
|
if (sizestr != error)
|
||||||
|
free(sizestr);
|
||||||
|
if (hpstr != error)
|
||||||
|
free(hpstr);
|
||||||
|
if (vpstr != error)
|
||||||
|
free(vpstr);
|
||||||
|
|
||||||
|
return (ascii);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Return the number of DNS hierarchy levels in the name. */
|
||||||
|
int
|
||||||
|
dn_count_labels(const char *name) {
|
||||||
|
int i, len, count;
|
||||||
|
|
||||||
|
len = (int)strlen(name);
|
||||||
|
for (i = 0, count = 0; i < len; i++) {
|
||||||
|
/* XXX need to check for \. or use named's nlabels(). */
|
||||||
|
if (name[i] == '.')
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* don't count initial wildcard */
|
||||||
|
if (name[0] == '*')
|
||||||
|
if (count)
|
||||||
|
count--;
|
||||||
|
|
||||||
|
/* don't count the null label for root. */
|
||||||
|
/* if terminating '.' not found, must adjust */
|
||||||
|
/* count to include last label */
|
||||||
|
if (len > 0 && name[len-1] != '.')
|
||||||
|
count++;
|
||||||
|
return (count);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make dates expressed in seconds-since-Jan-1-1970 easy to read.
|
||||||
|
* SIG records are required to be printed like this, by the Secure DNS RFC.
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
p_secstodate (u_long secs) {
|
||||||
|
static char output[15]; /* YYYYMMDDHHMMSS and null */
|
||||||
|
time_t clock = (time_t)secs;
|
||||||
|
struct tm *time;
|
||||||
|
|
||||||
|
time = gmtime(&clock);
|
||||||
|
time->tm_year += 1900;
|
||||||
|
time->tm_mon += 1;
|
||||||
|
sprintf(output, "%04d%02d%02d%02d%02d%02d",
|
||||||
|
time->tm_year, time->tm_mon, time->tm_mday,
|
||||||
|
time->tm_hour, time->tm_min, time->tm_sec);
|
||||||
|
return (output);
|
||||||
|
}
|
514
StdLib/BsdSocketLib/res_init.c
Normal file
514
StdLib/BsdSocketLib/res_init.c
Normal file
@ -0,0 +1,514 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1985, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
|
||||||
|
static char orig_rcsid[] = "From: Id: res_init.c,v 8.7 1996/11/18 09:10:04 vixie Exp $";
|
||||||
|
static char rcsid[] = "$Id: res_init.c,v 1.1.1.1 2003/11/19 01:51:37 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
|
||||||
|
static void res_setoptions __P((char *, char *));
|
||||||
|
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
static const char sort_mask[] = "/&";
|
||||||
|
#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
|
||||||
|
static u_int32_t net_mask __P((struct in_addr));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(isascii) /* XXX - could be a function */
|
||||||
|
# define isascii(c) (!(c & 0200))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolver state default settings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct __res_state _res
|
||||||
|
# if defined(__BIND_RES_TEXT)
|
||||||
|
= { RES_TIMEOUT, } /* Motorola, et al. */
|
||||||
|
# endif
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set up default settings. If the configuration file exist, the values
|
||||||
|
* there will have precedence. Otherwise, the server address is set to
|
||||||
|
* INADDR_ANY and the default domain name comes from the gethostname().
|
||||||
|
*
|
||||||
|
* An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
|
||||||
|
* rather than INADDR_ANY ("0.0.0.0") as the default name server address
|
||||||
|
* since it was noted that INADDR_ANY actually meant ``the first interface
|
||||||
|
* you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
|
||||||
|
* it had to be "up" in order for you to reach your own name server. It
|
||||||
|
* was later decided that since the recommended practice is to always
|
||||||
|
* install local static routes through 127.0.0.1 for all your network
|
||||||
|
* interfaces, that we could solve this problem without a code change.
|
||||||
|
*
|
||||||
|
* The configuration file should always be used, since it is the only way
|
||||||
|
* to specify a default domain. If you are running a server on your local
|
||||||
|
* machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
|
||||||
|
* in the configuration file.
|
||||||
|
*
|
||||||
|
* Return 0 if completes successfully, -1 on error
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_init()
|
||||||
|
{
|
||||||
|
register FILE *fp;
|
||||||
|
register char *cp, **pp;
|
||||||
|
register int n;
|
||||||
|
char buf[MAXDNAME];
|
||||||
|
int nserv = 0; /* number of nameserver records read from file */
|
||||||
|
int haveenv = 0;
|
||||||
|
int havesearch = 0;
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
int nsort = 0;
|
||||||
|
char *net;
|
||||||
|
#endif
|
||||||
|
#ifndef RFC1535
|
||||||
|
int dots;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These three fields used to be statically initialized. This made
|
||||||
|
* it hard to use this code in a shared library. It is necessary,
|
||||||
|
* now that we're doing dynamic initialization here, that we preserve
|
||||||
|
* the old semantics: if an application modifies one of these three
|
||||||
|
* fields of _res before res_init() is called, res_init() will not
|
||||||
|
* alter them. Of course, if an application is setting them to
|
||||||
|
* _zero_ before calling res_init(), hoping to override what used
|
||||||
|
* to be the static default, we can't detect it and unexpected results
|
||||||
|
* will follow. Zero for any of these fields would make no sense,
|
||||||
|
* so one can safely assume that the applications were already getting
|
||||||
|
* unexpected results.
|
||||||
|
*
|
||||||
|
* _res.options is tricky since some apps were known to diddle the bits
|
||||||
|
* before res_init() was first called. We can't replicate that semantic
|
||||||
|
* with dynamic initialization (they may have turned bits off that are
|
||||||
|
* set in RES_DEFAULT). Our solution is to declare such applications
|
||||||
|
* "broken". They could fool us by setting RES_INIT but none do (yet).
|
||||||
|
*/
|
||||||
|
if (!_res.retrans)
|
||||||
|
_res.retrans = RES_TIMEOUT;
|
||||||
|
if (!_res.retry)
|
||||||
|
_res.retry = 4;
|
||||||
|
if (!(_res.options & RES_INIT))
|
||||||
|
_res.options = RES_DEFAULT;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This one used to initialize implicitly to zero, so unless the app
|
||||||
|
* has set it to something in particular, we can randomize it now.
|
||||||
|
*/
|
||||||
|
if (!_res.id)
|
||||||
|
_res.id = (u_short)res_randomid();
|
||||||
|
|
||||||
|
#ifdef USELOOPBACK
|
||||||
|
_res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
|
||||||
|
#else
|
||||||
|
_res.nsaddr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
#endif
|
||||||
|
_res.nsaddr.sin_family = AF_INET;
|
||||||
|
_res.nsaddr.sin_port = htons(NAMESERVER_PORT);
|
||||||
|
_res.nscount = 1;
|
||||||
|
_res.ndots = 1;
|
||||||
|
_res.pfcode = 0;
|
||||||
|
|
||||||
|
/* Allow user to override the local domain definition */
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL)
|
||||||
|
#else
|
||||||
|
if ((cp = getenv("LOCALDOMAIN")) != NULL)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
(void)strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
|
||||||
|
_res.defdname[sizeof(_res.defdname) - 1] = '\0';
|
||||||
|
haveenv++;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set search list to be blank-separated strings
|
||||||
|
* from rest of env value. Permits users of LOCALDOMAIN
|
||||||
|
* to still have a search list, and anyone to set the
|
||||||
|
* one that they want to use as an individual (even more
|
||||||
|
* important now that the rfc1535 stuff restricts searches)
|
||||||
|
*/
|
||||||
|
cp = _res.defdname;
|
||||||
|
pp = _res.dnsrch;
|
||||||
|
*pp++ = cp;
|
||||||
|
for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
|
||||||
|
if (*cp == '\n') /* silly backwards compat */
|
||||||
|
break;
|
||||||
|
else if (*cp == ' ' || *cp == '\t') {
|
||||||
|
*cp = 0;
|
||||||
|
n = 1;
|
||||||
|
} else if (n) {
|
||||||
|
*pp++ = cp;
|
||||||
|
n = 0;
|
||||||
|
havesearch = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* null terminate last domain if there are excess */
|
||||||
|
while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
|
||||||
|
cp++;
|
||||||
|
*cp = '\0';
|
||||||
|
*pp++ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define MATCH(line, name) \
|
||||||
|
(!strncmp(line, name, sizeof(name) - 1) && \
|
||||||
|
(line[sizeof(name) - 1] == ' ' || \
|
||||||
|
line[sizeof(name) - 1] == '\t'))
|
||||||
|
|
||||||
|
if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
|
||||||
|
/* read the config file */
|
||||||
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
|
/* skip comments */
|
||||||
|
if (*buf == ';' || *buf == '#')
|
||||||
|
continue;
|
||||||
|
/* read default domain name */
|
||||||
|
if (MATCH(buf, "domain")) {
|
||||||
|
if (haveenv) /* skip if have from environ */
|
||||||
|
continue;
|
||||||
|
cp = buf + sizeof("domain") - 1;
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
if ((*cp == '\0') || (*cp == '\n'))
|
||||||
|
continue;
|
||||||
|
strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
|
||||||
|
_res.defdname[sizeof(_res.defdname) - 1] = '\0';
|
||||||
|
if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
|
||||||
|
*cp = '\0';
|
||||||
|
havesearch = 0;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* set search list */
|
||||||
|
if (MATCH(buf, "search")) {
|
||||||
|
if (haveenv) /* skip if have from environ */
|
||||||
|
continue;
|
||||||
|
cp = buf + sizeof("search") - 1;
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
if ((*cp == '\0') || (*cp == '\n'))
|
||||||
|
continue;
|
||||||
|
strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
|
||||||
|
_res.defdname[sizeof(_res.defdname) - 1] = '\0';
|
||||||
|
if ((cp = strchr(_res.defdname, '\n')) != NULL)
|
||||||
|
*cp = '\0';
|
||||||
|
/*
|
||||||
|
* Set search list to be blank-separated strings
|
||||||
|
* on rest of line.
|
||||||
|
*/
|
||||||
|
cp = _res.defdname;
|
||||||
|
pp = _res.dnsrch;
|
||||||
|
*pp++ = cp;
|
||||||
|
for (n = 0; *cp && pp < _res.dnsrch + MAXDNSRCH; cp++) {
|
||||||
|
if (*cp == ' ' || *cp == '\t') {
|
||||||
|
*cp = 0;
|
||||||
|
n = 1;
|
||||||
|
} else if (n) {
|
||||||
|
*pp++ = cp;
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* null terminate last domain if there are excess */
|
||||||
|
while (*cp != '\0' && *cp != ' ' && *cp != '\t')
|
||||||
|
cp++;
|
||||||
|
*cp = '\0';
|
||||||
|
*pp++ = 0;
|
||||||
|
havesearch = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* read nameservers to query */
|
||||||
|
if (MATCH(buf, "nameserver") && nserv < MAXNS) {
|
||||||
|
struct in_addr a;
|
||||||
|
|
||||||
|
cp = buf + sizeof("nameserver") - 1;
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
|
||||||
|
_res.nsaddr_list[nserv].sin_addr = a;
|
||||||
|
_res.nsaddr_list[nserv].sin_family = AF_INET;
|
||||||
|
_res.nsaddr_list[nserv].sin_port =
|
||||||
|
htons(NAMESERVER_PORT);
|
||||||
|
nserv++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
if (MATCH(buf, "sortlist")) {
|
||||||
|
struct in_addr a;
|
||||||
|
|
||||||
|
cp = buf + sizeof("sortlist") - 1;
|
||||||
|
while (nsort < MAXRESOLVSORT) {
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
if (*cp == '\0' || *cp == '\n' || *cp == ';')
|
||||||
|
break;
|
||||||
|
net = cp;
|
||||||
|
while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
|
||||||
|
isascii(*cp) && !isspace(*cp))
|
||||||
|
cp++;
|
||||||
|
n = *cp;
|
||||||
|
*cp = 0;
|
||||||
|
if (inet_aton(net, &a)) {
|
||||||
|
_res.sort_list[nsort].addr = a;
|
||||||
|
if (ISSORTMASK(n)) {
|
||||||
|
*cp++ = (char)n;
|
||||||
|
net = cp;
|
||||||
|
while (*cp && *cp != ';' &&
|
||||||
|
isascii(*cp) && !isspace(*cp))
|
||||||
|
cp++;
|
||||||
|
n = *cp;
|
||||||
|
*cp = 0;
|
||||||
|
if (inet_aton(net, &a)) {
|
||||||
|
_res.sort_list[nsort].mask = a.s_addr;
|
||||||
|
} else {
|
||||||
|
_res.sort_list[nsort].mask =
|
||||||
|
net_mask(_res.sort_list[nsort].addr);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_res.sort_list[nsort].mask =
|
||||||
|
net_mask(_res.sort_list[nsort].addr);
|
||||||
|
}
|
||||||
|
nsort++;
|
||||||
|
}
|
||||||
|
*cp = (char)n;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (MATCH(buf, "options")) {
|
||||||
|
res_setoptions(buf + sizeof("options") - 1, "conf");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nserv > 1)
|
||||||
|
_res.nscount = nserv;
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
_res.nsort = nsort;
|
||||||
|
#endif
|
||||||
|
(void) fclose(fp);
|
||||||
|
}
|
||||||
|
if (_res.defdname[0] == 0 &&
|
||||||
|
gethostname(buf, sizeof(_res.defdname) - 1) == 0 &&
|
||||||
|
(cp = strchr(buf, '.')) != NULL)
|
||||||
|
strcpy(_res.defdname, cp + 1);
|
||||||
|
|
||||||
|
/* find components of local domain that might be searched */
|
||||||
|
if (havesearch == 0) {
|
||||||
|
pp = _res.dnsrch;
|
||||||
|
*pp++ = _res.defdname;
|
||||||
|
*pp = NULL;
|
||||||
|
|
||||||
|
#ifndef RFC1535
|
||||||
|
dots = 0;
|
||||||
|
for (cp = _res.defdname; *cp; cp++)
|
||||||
|
dots += (*cp == '.');
|
||||||
|
|
||||||
|
cp = _res.defdname;
|
||||||
|
while (pp < _res.dnsrch + MAXDFLSRCH) {
|
||||||
|
if (dots < LOCALDOMAINPARTS)
|
||||||
|
break;
|
||||||
|
cp = strchr(cp, '.') + 1; /* we know there is one */
|
||||||
|
*pp++ = cp;
|
||||||
|
dots--;
|
||||||
|
}
|
||||||
|
*pp = NULL;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG) {
|
||||||
|
printf(";; res_init()... default dnsrch list:\n");
|
||||||
|
for (pp = _res.dnsrch; *pp; pp++)
|
||||||
|
printf(";;\t%s\n", *pp);
|
||||||
|
printf(";;\t..END..\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif /* !RFC1535 */
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
if (issetugid())
|
||||||
|
#else
|
||||||
|
if (1)
|
||||||
|
#endif
|
||||||
|
_res.options |= RES_NOALIASES;
|
||||||
|
else if ((cp = getenv("RES_OPTIONS")) != NULL)
|
||||||
|
res_setoptions(cp, "env");
|
||||||
|
_res.options |= RES_INIT;
|
||||||
|
if ( 0 == nserv ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
res_setoptions(
|
||||||
|
char *options,
|
||||||
|
char *source
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char *cp = options;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; res_setoptions(\"%s\", \"%s\")...\n",
|
||||||
|
options, source);
|
||||||
|
#endif
|
||||||
|
while (*cp) {
|
||||||
|
/* skip leading and inner runs of spaces */
|
||||||
|
while (*cp == ' ' || *cp == '\t')
|
||||||
|
cp++;
|
||||||
|
/* search for and process individual options */
|
||||||
|
if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
|
||||||
|
i = atoi(cp + sizeof("ndots:") - 1);
|
||||||
|
if (i <= RES_MAXNDOTS)
|
||||||
|
_res.ndots = i;
|
||||||
|
else
|
||||||
|
_res.ndots = RES_MAXNDOTS;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";;\tndots=%d\n", _res.ndots);
|
||||||
|
#endif
|
||||||
|
} else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (!(_res.options & RES_DEBUG)) {
|
||||||
|
printf(";; res_setoptions(\"%s\", \"%s\")..\n",
|
||||||
|
options, source);
|
||||||
|
_res.options |= RES_DEBUG;
|
||||||
|
}
|
||||||
|
printf(";;\tdebug\n");
|
||||||
|
#endif
|
||||||
|
} else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
|
||||||
|
_res.options |= RES_USE_INET6;
|
||||||
|
} else if (!strncmp(cp, "no_tld_query", sizeof("no_tld_query") - 1)) {
|
||||||
|
_res.options |= RES_NOTLDQUERY;
|
||||||
|
} else {
|
||||||
|
/* XXX - print a warning here? */
|
||||||
|
}
|
||||||
|
/* skip to next run of spaces */
|
||||||
|
while (*cp && *cp != ' ' && *cp != '\t')
|
||||||
|
cp++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef RESOLVSORT
|
||||||
|
/* XXX - should really support CIDR which means explicit masks always. */
|
||||||
|
static u_int32_t
|
||||||
|
net_mask(
|
||||||
|
struct in_addr in
|
||||||
|
)
|
||||||
|
{
|
||||||
|
register u_int32_t i = ntohl(in.s_addr);
|
||||||
|
|
||||||
|
if (IN_CLASSA(i))
|
||||||
|
return (htonl(IN_CLASSA_NET));
|
||||||
|
else if (IN_CLASSB(i))
|
||||||
|
return (htonl(IN_CLASSB_NET));
|
||||||
|
return (htonl(IN_CLASSC_NET));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
u_int
|
||||||
|
res_randomid()
|
||||||
|
{
|
||||||
|
struct timeval now;
|
||||||
|
|
||||||
|
gettimeofday(&now, NULL);
|
||||||
|
return (0xffff & (now.tv_sec ^ now.tv_usec /* ^ getpid() */));
|
||||||
|
}
|
211
StdLib/BsdSocketLib/res_mkquery.c
Normal file
211
StdLib/BsdSocketLib/res_mkquery.c
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1985, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char orig_rcsid[] = "From: Id: res_mkquery.c,v 8.9 1997/04/24 22:22:36 vixie Exp $";
|
||||||
|
static char rcsid[] = "$Id: res_mkquery.c,v 1.1.1.1 2003/11/19 01:51:37 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Form all types of queries.
|
||||||
|
* Returns the size of the result or -1.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_mkquery(
|
||||||
|
int op, /* opcode of query */
|
||||||
|
const char *dname, /* domain name */
|
||||||
|
int class, /* class of query */
|
||||||
|
int type, /* type of query */
|
||||||
|
const u_char *data, /* resource record data */
|
||||||
|
int datalen, /* length of data */
|
||||||
|
const u_char *newrr_in, /* new rr for modify or append */
|
||||||
|
u_char *buf, /* buffer to put query */
|
||||||
|
int buflen /* size of buffer */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
register HEADER *hp;
|
||||||
|
register u_char *cp;
|
||||||
|
register int n;
|
||||||
|
u_char *dnptrs[20], **dpp, **lastdnptr;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; res_mkquery(%d, %s, %d, %d)\n",
|
||||||
|
op, dname, class, type);
|
||||||
|
#endif
|
||||||
|
/*
|
||||||
|
* Initialize header fields.
|
||||||
|
*/
|
||||||
|
if ((buf == NULL) || (buflen < HFIXEDSZ))
|
||||||
|
return (-1);
|
||||||
|
memset(buf, 0, HFIXEDSZ);
|
||||||
|
hp = (HEADER *) buf;
|
||||||
|
hp->id = htons(++_res.id);
|
||||||
|
hp->opcode = op;
|
||||||
|
hp->rd = (_res.options & RES_RECURSE) != 0;
|
||||||
|
hp->rcode = NOERROR;
|
||||||
|
cp = buf + HFIXEDSZ;
|
||||||
|
buflen -= HFIXEDSZ;
|
||||||
|
dpp = dnptrs;
|
||||||
|
*dpp++ = buf;
|
||||||
|
*dpp++ = NULL;
|
||||||
|
lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
|
||||||
|
/*
|
||||||
|
* perform opcode specific processing
|
||||||
|
*/
|
||||||
|
switch (op) {
|
||||||
|
case QUERY: /*FALLTHROUGH*/
|
||||||
|
case NS_NOTIFY_OP:
|
||||||
|
if ((buflen -= QFIXEDSZ) < 0)
|
||||||
|
return (-1);
|
||||||
|
if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
buflen -= n;
|
||||||
|
__putshort((u_int16_t)type, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
__putshort((u_int16_t)class, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
hp->qdcount = htons(1);
|
||||||
|
if (op == QUERY || data == NULL)
|
||||||
|
break;
|
||||||
|
/*
|
||||||
|
* Make an additional record for completion domain.
|
||||||
|
*/
|
||||||
|
buflen -= RRFIXEDSZ;
|
||||||
|
n = dn_comp((char *)data, cp, buflen, dnptrs, lastdnptr);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
buflen -= n;
|
||||||
|
__putshort(T_NULL, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
__putshort((u_int16_t)class, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
__putlong(0, cp);
|
||||||
|
cp += INT32SZ;
|
||||||
|
__putshort(0, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
hp->arcount = htons(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case IQUERY:
|
||||||
|
/*
|
||||||
|
* Initialize answer section
|
||||||
|
*/
|
||||||
|
if (buflen < 1 + RRFIXEDSZ + datalen)
|
||||||
|
return (-1);
|
||||||
|
*cp++ = '\0'; /* no domain name */
|
||||||
|
__putshort((u_int16_t)type, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
__putshort((u_int16_t)class, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
__putlong(0, cp);
|
||||||
|
cp += INT32SZ;
|
||||||
|
__putshort((u_int16_t)datalen, cp);
|
||||||
|
cp += INT16SZ;
|
||||||
|
if (datalen) {
|
||||||
|
memcpy(cp, data, datalen);
|
||||||
|
cp += datalen;
|
||||||
|
}
|
||||||
|
hp->ancount = htons(1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return ((int)(cp - buf));
|
||||||
|
}
|
454
StdLib/BsdSocketLib/res_mkupdate.c
Normal file
454
StdLib/BsdSocketLib/res_mkupdate.c
Normal file
@ -0,0 +1,454 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Based on the Dynamic DNS reference implementation by Viraj Bais
|
||||||
|
* <viraj_bais@ccm.fm.intel.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if !defined(lint) && !defined(SABER)
|
||||||
|
static char rcsid[] = "$Id: res_mkupdate.c,v 1.1.1.1 2003/11/19 01:51:38 kyu3 Exp $";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
|
||||||
|
static int getnum_str(u_char **, u_char *);
|
||||||
|
static int getword_str(char *, int, u_char **, u_char *);
|
||||||
|
|
||||||
|
#define ShrinkBuffer(x) if ((buflen -= x) < 0) return (-2);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Form update packets.
|
||||||
|
* Returns the size of the resulting packet if no error
|
||||||
|
* On error,
|
||||||
|
* returns -1 if error in reading a word/number in rdata
|
||||||
|
* portion for update packets
|
||||||
|
* -2 if length of buffer passed is insufficient
|
||||||
|
* -3 if zone section is not the first section in
|
||||||
|
* the linked list, or section order has a problem
|
||||||
|
* -4 on a number overflow
|
||||||
|
* -5 unknown operation or no records
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_mkupdate(ns_updrec *rrecp_in, u_char *buf, int buflen) {
|
||||||
|
ns_updrec *rrecp_start = rrecp_in;
|
||||||
|
HEADER *hp;
|
||||||
|
u_char *cp, *sp1, *sp2, *startp, *endp;
|
||||||
|
int n, i, soanum, multiline;
|
||||||
|
ns_updrec *rrecp;
|
||||||
|
struct in_addr ina;
|
||||||
|
char buf2[MAXDNAME];
|
||||||
|
int section, numrrs = 0, counts[ns_s_max];
|
||||||
|
u_int16_t rtype, rclass;
|
||||||
|
u_int32_t n1, rttl;
|
||||||
|
u_char *dnptrs[20], **dpp, **lastdnptr;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Initialize header fields.
|
||||||
|
*/
|
||||||
|
if ((buf == NULL) || (buflen < HFIXEDSZ))
|
||||||
|
return (-1);
|
||||||
|
memset(buf, 0, HFIXEDSZ);
|
||||||
|
hp = (HEADER *) buf;
|
||||||
|
hp->id = htons(++_res.id);
|
||||||
|
hp->opcode = ns_o_update;
|
||||||
|
hp->rcode = NOERROR;
|
||||||
|
sp1 = buf + 2*INT16SZ; /* save pointer to zocount */
|
||||||
|
cp = buf + HFIXEDSZ;
|
||||||
|
buflen -= HFIXEDSZ;
|
||||||
|
dpp = dnptrs;
|
||||||
|
*dpp++ = buf;
|
||||||
|
*dpp++ = NULL;
|
||||||
|
lastdnptr = dnptrs + sizeof dnptrs / sizeof dnptrs[0];
|
||||||
|
|
||||||
|
if (rrecp_start == NULL)
|
||||||
|
return (-5);
|
||||||
|
else if (rrecp_start->r_section != S_ZONE)
|
||||||
|
return (-3);
|
||||||
|
|
||||||
|
memset(counts, 0, sizeof counts);
|
||||||
|
for (rrecp = rrecp_start; rrecp; rrecp = rrecp->r_grpnext) {
|
||||||
|
numrrs++;
|
||||||
|
section = rrecp->r_section;
|
||||||
|
if (section < 0 || section >= ns_s_max)
|
||||||
|
return (-1);
|
||||||
|
counts[section]++;
|
||||||
|
for (i = section + 1; i < ns_s_max; i++)
|
||||||
|
if (counts[i])
|
||||||
|
return (-3);
|
||||||
|
rtype = rrecp->r_type;
|
||||||
|
rclass = rrecp->r_class;
|
||||||
|
rttl = rrecp->r_ttl;
|
||||||
|
/* overload class and type */
|
||||||
|
if (section == S_PREREQ) {
|
||||||
|
rttl = 0;
|
||||||
|
switch (rrecp->r_opcode) {
|
||||||
|
case YXDOMAIN:
|
||||||
|
rclass = C_ANY;
|
||||||
|
rtype = T_ANY;
|
||||||
|
rrecp->r_size = 0;
|
||||||
|
break;
|
||||||
|
case NXDOMAIN:
|
||||||
|
rclass = C_NONE;
|
||||||
|
rtype = T_ANY;
|
||||||
|
rrecp->r_size = 0;
|
||||||
|
break;
|
||||||
|
case NXRRSET:
|
||||||
|
rclass = C_NONE;
|
||||||
|
rrecp->r_size = 0;
|
||||||
|
break;
|
||||||
|
case YXRRSET:
|
||||||
|
if (rrecp->r_size == 0)
|
||||||
|
rclass = C_ANY;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr,
|
||||||
|
"res_mkupdate: incorrect opcode: %d\n",
|
||||||
|
rrecp->r_opcode);
|
||||||
|
fflush(stderr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (section == S_UPDATE) {
|
||||||
|
switch (rrecp->r_opcode) {
|
||||||
|
case DELETE:
|
||||||
|
rclass = rrecp->r_size == 0 ? C_ANY : C_NONE;
|
||||||
|
break;
|
||||||
|
case ADD:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf(stderr,
|
||||||
|
"res_mkupdate: incorrect opcode: %d\n",
|
||||||
|
rrecp->r_opcode);
|
||||||
|
fflush(stderr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX appending default domain to owner name is omitted,
|
||||||
|
* fqdn must be provided
|
||||||
|
*/
|
||||||
|
if ((n = dn_comp(rrecp->r_dname, cp, buflen, dnptrs,
|
||||||
|
lastdnptr)) < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
ShrinkBuffer(n + 2*INT16SZ);
|
||||||
|
PUTSHORT(rtype, cp);
|
||||||
|
PUTSHORT(rclass, cp);
|
||||||
|
if (section == S_ZONE) {
|
||||||
|
if (numrrs != 1 || rrecp->r_type != T_SOA)
|
||||||
|
return (-3);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
ShrinkBuffer(INT32SZ + INT16SZ);
|
||||||
|
PUTLONG(rttl, cp);
|
||||||
|
sp2 = cp; /* save pointer to length byte */
|
||||||
|
cp += INT16SZ;
|
||||||
|
if (rrecp->r_size == 0) {
|
||||||
|
if (section == S_UPDATE && rclass != C_ANY)
|
||||||
|
return (-1);
|
||||||
|
else {
|
||||||
|
PUTSHORT(0, sp2);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
startp = rrecp->r_data;
|
||||||
|
endp = startp + rrecp->r_size - 1;
|
||||||
|
/* XXX this should be done centrally. */
|
||||||
|
switch (rrecp->r_type) {
|
||||||
|
case T_A:
|
||||||
|
if (!getword_str(buf2, sizeof buf2, &startp, endp))
|
||||||
|
return (-1);
|
||||||
|
if (!inet_aton(buf2, &ina))
|
||||||
|
return (-1);
|
||||||
|
n1 = ntohl(ina.s_addr);
|
||||||
|
ShrinkBuffer(INT32SZ);
|
||||||
|
PUTLONG(n1, cp);
|
||||||
|
break;
|
||||||
|
case T_CNAME:
|
||||||
|
case T_MB:
|
||||||
|
case T_MG:
|
||||||
|
case T_MR:
|
||||||
|
case T_NS:
|
||||||
|
case T_PTR:
|
||||||
|
if (!getword_str(buf2, sizeof buf2, &startp, endp))
|
||||||
|
return (-1);
|
||||||
|
n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
ShrinkBuffer(n);
|
||||||
|
break;
|
||||||
|
case T_MINFO:
|
||||||
|
case T_SOA:
|
||||||
|
case T_RP:
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
if (!getword_str(buf2, sizeof buf2, &startp,
|
||||||
|
endp))
|
||||||
|
return (-1);
|
||||||
|
n = dn_comp(buf2, cp, buflen,
|
||||||
|
dnptrs, lastdnptr);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
ShrinkBuffer(n);
|
||||||
|
}
|
||||||
|
if (rrecp->r_type == T_SOA) {
|
||||||
|
ShrinkBuffer(5 * INT32SZ);
|
||||||
|
while (isspace(*startp) || !*startp)
|
||||||
|
startp++;
|
||||||
|
if (*startp == '(') {
|
||||||
|
multiline = 1;
|
||||||
|
startp++;
|
||||||
|
} else
|
||||||
|
multiline = 0;
|
||||||
|
/* serial, refresh, retry, expire, minimum */
|
||||||
|
for (i = 0; i < 5; i++) {
|
||||||
|
soanum = getnum_str(&startp, endp);
|
||||||
|
if (soanum < 0)
|
||||||
|
return (-1);
|
||||||
|
PUTLONG(soanum, cp);
|
||||||
|
}
|
||||||
|
if (multiline) {
|
||||||
|
while (isspace(*startp) || !*startp)
|
||||||
|
startp++;
|
||||||
|
if (*startp != ')')
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case T_MX:
|
||||||
|
case T_AFSDB:
|
||||||
|
case T_RT:
|
||||||
|
n = getnum_str(&startp, endp);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
PUTSHORT(n, cp);
|
||||||
|
ShrinkBuffer(INT16SZ);
|
||||||
|
if (!getword_str(buf2, sizeof buf2, &startp, endp))
|
||||||
|
return (-1);
|
||||||
|
n = dn_comp(buf2, cp, buflen, dnptrs, lastdnptr);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
ShrinkBuffer(n);
|
||||||
|
break;
|
||||||
|
case T_PX:
|
||||||
|
n = getnum_str(&startp, endp);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
PUTSHORT(n, cp);
|
||||||
|
ShrinkBuffer(INT16SZ);
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
if (!getword_str(buf2, sizeof buf2, &startp,
|
||||||
|
endp))
|
||||||
|
return (-1);
|
||||||
|
n = dn_comp(buf2, cp, buflen, dnptrs,
|
||||||
|
lastdnptr);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
ShrinkBuffer(n);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case T_WKS:
|
||||||
|
case T_HINFO:
|
||||||
|
case T_TXT:
|
||||||
|
case T_X25:
|
||||||
|
case T_ISDN:
|
||||||
|
case T_NSAP:
|
||||||
|
case T_LOC:
|
||||||
|
/* XXX - more fine tuning needed here */
|
||||||
|
ShrinkBuffer(rrecp->r_size);
|
||||||
|
memcpy(cp, rrecp->r_data, rrecp->r_size);
|
||||||
|
cp += rrecp->r_size;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return (-1);
|
||||||
|
} /*switch*/
|
||||||
|
n = (u_int16_t)((cp - sp2) - INT16SZ);
|
||||||
|
PUTSHORT(n, sp2);
|
||||||
|
} /*for*/
|
||||||
|
|
||||||
|
hp->qdcount = htons(counts[0]);
|
||||||
|
hp->ancount = htons(counts[1]);
|
||||||
|
hp->nscount = htons(counts[2]);
|
||||||
|
hp->arcount = htons(counts[3]);
|
||||||
|
return ((int)(cp - buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a whitespace delimited word from a string (not file)
|
||||||
|
* into buf. modify the start pointer to point after the
|
||||||
|
* word in the string.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
getword_str(char *buf, int size, u_char **startpp, u_char *endp) {
|
||||||
|
char *cp;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
for (cp = buf; *startpp <= endp; ) {
|
||||||
|
c = **startpp;
|
||||||
|
if (isspace(c) || c == '\0') {
|
||||||
|
if (cp != buf) /* trailing whitespace */
|
||||||
|
break;
|
||||||
|
else { /* leading whitespace */
|
||||||
|
(*startpp)++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(*startpp)++;
|
||||||
|
if (cp >= buf+size-1)
|
||||||
|
break;
|
||||||
|
*cp++ = (u_char)c;
|
||||||
|
}
|
||||||
|
*cp = '\0';
|
||||||
|
return (cp != buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get a whitespace delimited number from a string (not file) into buf
|
||||||
|
* update the start pointer to point after the number in the string.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
getnum_str(u_char **startpp, u_char *endp) {
|
||||||
|
int c;
|
||||||
|
int n;
|
||||||
|
int seendigit = 0;
|
||||||
|
int m = 0;
|
||||||
|
|
||||||
|
for (n = 0; *startpp <= endp; ) {
|
||||||
|
c = **startpp;
|
||||||
|
if (isspace(c) || c == '\0') {
|
||||||
|
if (seendigit) /* trailing whitespace */
|
||||||
|
break;
|
||||||
|
else { /* leading whitespace */
|
||||||
|
(*startpp)++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (c == ';') {
|
||||||
|
while ((*startpp <= endp) &&
|
||||||
|
((c = **startpp) != '\n'))
|
||||||
|
(*startpp)++;
|
||||||
|
if (seendigit)
|
||||||
|
break;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!isdigit(c)) {
|
||||||
|
if (c == ')' && seendigit) {
|
||||||
|
(*startpp)--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
(*startpp)++;
|
||||||
|
n = n * 10 + (c - '0');
|
||||||
|
seendigit = 1;
|
||||||
|
}
|
||||||
|
return (n + m);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocate a resource record buffer & save rr info.
|
||||||
|
*/
|
||||||
|
ns_updrec *
|
||||||
|
res_mkupdrec(int section, const char *dname,
|
||||||
|
u_int class, u_int type, u_long ttl) {
|
||||||
|
ns_updrec *rrecp = (ns_updrec *)calloc(1, sizeof(ns_updrec));
|
||||||
|
|
||||||
|
if (!rrecp || !(rrecp->r_dname = strdup(dname)))
|
||||||
|
return (NULL);
|
||||||
|
rrecp->r_class = (u_int16_t)class;
|
||||||
|
rrecp->r_type = (u_int16_t)type;
|
||||||
|
rrecp->r_ttl = (u_int32_t)ttl;
|
||||||
|
rrecp->r_section = (u_int8_t)section;
|
||||||
|
return (rrecp);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free a resource record buffer created by res_mkupdrec.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
res_freeupdrec(ns_updrec *rrecp) {
|
||||||
|
/* Note: freeing r_dp is the caller's responsibility. */
|
||||||
|
if (rrecp->r_dname != NULL)
|
||||||
|
free(rrecp->r_dname);
|
||||||
|
free(rrecp);
|
||||||
|
}
|
430
StdLib/BsdSocketLib/res_query.c
Normal file
430
StdLib/BsdSocketLib/res_query.c
Normal file
@ -0,0 +1,430 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1988, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char orig_rcsid = "From: Id: res_query.c,v 8.14 1997/06/09 17:47:05 halley Exp $";
|
||||||
|
static char rcsid[] = "$Id: res_query.c,v 1.1.1.1 2003/11/19 01:51:38 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
|
||||||
|
#if PACKETSZ > 1024
|
||||||
|
#define MAXPACKET PACKETSZ
|
||||||
|
#else
|
||||||
|
#define MAXPACKET 1024
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Formulate a normal query, send, and await answer.
|
||||||
|
* Returned answer is placed in supplied buffer "answer".
|
||||||
|
* Perform preliminary check of answer, returning success only
|
||||||
|
* if no error is indicated and the answer count is nonzero.
|
||||||
|
* Return the size of the response on success, -1 on error.
|
||||||
|
* Error number is left in h_errno.
|
||||||
|
*
|
||||||
|
* Caller must parse answer and determine whether it answers the question.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_query(
|
||||||
|
const char *name, /* domain name */
|
||||||
|
int class, /* class of query */
|
||||||
|
int type, /* type of query */
|
||||||
|
u_char *answer, /* buffer to put answer */
|
||||||
|
int anslen /* size of answer buffer */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
u_char buf[MAXPACKET];
|
||||||
|
HEADER *hp = (HEADER *) answer;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
hp->rcode = NOERROR; /* default */
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; res_query(%s, %d, %d)\n", name, class, type);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
n = res_mkquery(QUERY, name, class, type, NULL, 0, NULL,
|
||||||
|
buf, sizeof(buf));
|
||||||
|
if (n <= 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; res_query: mkquery failed\n");
|
||||||
|
#endif
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
n = res_send(buf, n, answer, anslen);
|
||||||
|
if (n < 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; res_query: send error\n");
|
||||||
|
#endif
|
||||||
|
h_errno = TRY_AGAIN;
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; rcode = %d, ancount=%d\n", hp->rcode,
|
||||||
|
ntohs(hp->ancount));
|
||||||
|
#endif
|
||||||
|
switch (hp->rcode) {
|
||||||
|
case NXDOMAIN:
|
||||||
|
h_errno = HOST_NOT_FOUND;
|
||||||
|
break;
|
||||||
|
case SERVFAIL:
|
||||||
|
h_errno = TRY_AGAIN;
|
||||||
|
break;
|
||||||
|
case NOERROR:
|
||||||
|
h_errno = NO_DATA;
|
||||||
|
break;
|
||||||
|
case FORMERR:
|
||||||
|
case NOTIMP:
|
||||||
|
case REFUSED:
|
||||||
|
default:
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Formulate a normal query, send, and retrieve answer in supplied buffer.
|
||||||
|
* Return the size of the response on success, -1 on error.
|
||||||
|
* If enabled, implement search rules until answer or unrecoverable failure
|
||||||
|
* is detected. Error code, if any, is left in h_errno.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_search(
|
||||||
|
const char *name, /* domain name */
|
||||||
|
int class, /* class of query */
|
||||||
|
int type, /* type of query */
|
||||||
|
u_char *answer, /* buffer to put answer */
|
||||||
|
int anslen /* size of answer */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const char *cp, * const *domain;
|
||||||
|
HEADER *hp = (HEADER *) answer;
|
||||||
|
u_int dots;
|
||||||
|
int trailing_dot, ret, saved_herrno;
|
||||||
|
int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
h_errno = HOST_NOT_FOUND; /* default, if we never query */
|
||||||
|
dots = 0;
|
||||||
|
for (cp = name; *cp; cp++)
|
||||||
|
dots += (*cp == '.');
|
||||||
|
trailing_dot = 0;
|
||||||
|
if (cp > name && *--cp == '.')
|
||||||
|
trailing_dot++;
|
||||||
|
|
||||||
|
/* If there aren't any dots, it could be a user-level alias */
|
||||||
|
if (!dots && (cp = hostalias(name)) != NULL)
|
||||||
|
return (res_query(cp, class, type, answer, anslen));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If there are dots in the name already, let's just give it a try
|
||||||
|
* 'as is'. The threshold can be set with the "ndots" option.
|
||||||
|
*/
|
||||||
|
saved_herrno = -1;
|
||||||
|
if (dots >= _res.ndots) {
|
||||||
|
ret = res_querydomain(name, NULL, class, type, answer, anslen);
|
||||||
|
if (ret > 0)
|
||||||
|
return (ret);
|
||||||
|
saved_herrno = h_errno;
|
||||||
|
tried_as_is++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We do at least one level of search if
|
||||||
|
* - there is no dot and RES_DEFNAME is set, or
|
||||||
|
* - there is at least one dot, there is no trailing dot,
|
||||||
|
* and RES_DNSRCH is set.
|
||||||
|
*/
|
||||||
|
if ((!dots && (_res.options & RES_DEFNAMES)) ||
|
||||||
|
(dots && !trailing_dot && (_res.options & RES_DNSRCH))) {
|
||||||
|
int done = 0;
|
||||||
|
|
||||||
|
for (domain = (const char * const *)_res.dnsrch;
|
||||||
|
*domain && !done;
|
||||||
|
domain++) {
|
||||||
|
|
||||||
|
ret = res_querydomain(name, *domain, class, type,
|
||||||
|
answer, anslen);
|
||||||
|
if (ret > 0)
|
||||||
|
return (ret);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If no server present, give up.
|
||||||
|
* If name isn't found in this domain,
|
||||||
|
* keep trying higher domains in the search list
|
||||||
|
* (if that's enabled).
|
||||||
|
* On a NO_DATA error, keep trying, otherwise
|
||||||
|
* a wildcard entry of another type could keep us
|
||||||
|
* from finding this entry higher in the domain.
|
||||||
|
* If we get some other error (negative answer or
|
||||||
|
* server failure), then stop searching up,
|
||||||
|
* but try the input name below in case it's
|
||||||
|
* fully-qualified.
|
||||||
|
*/
|
||||||
|
if (errno == ECONNREFUSED) {
|
||||||
|
h_errno = TRY_AGAIN;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (h_errno) {
|
||||||
|
case NO_DATA:
|
||||||
|
got_nodata++;
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
case HOST_NOT_FOUND:
|
||||||
|
/* keep trying */
|
||||||
|
break;
|
||||||
|
case TRY_AGAIN:
|
||||||
|
if (hp->rcode == SERVFAIL) {
|
||||||
|
/* try next search element, if any */
|
||||||
|
got_servfail++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
default:
|
||||||
|
/* anything else implies that we're done */
|
||||||
|
done++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we got here for some reason other than DNSRCH,
|
||||||
|
* we only wanted one iteration of the loop, so stop.
|
||||||
|
*/
|
||||||
|
if (!(_res.options & RES_DNSRCH))
|
||||||
|
done++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we have not already tried the name "as is", do that now.
|
||||||
|
* note that we do this regardless of how many dots were in the
|
||||||
|
* name or whether it ends with a dot unless NOTLDQUERY is set.
|
||||||
|
*/
|
||||||
|
if (!tried_as_is && (dots || !(_res.options & RES_NOTLDQUERY))) {
|
||||||
|
ret = res_querydomain(name, NULL, class, type, answer, anslen);
|
||||||
|
if (ret > 0)
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we got here, we didn't satisfy the search.
|
||||||
|
* if we did an initial full query, return that query's h_errno
|
||||||
|
* (note that we wouldn't be here if that query had succeeded).
|
||||||
|
* else if we ever got a nodata, send that back as the reason.
|
||||||
|
* else send back meaningless h_errno, that being the one from
|
||||||
|
* the last DNSRCH we did.
|
||||||
|
*/
|
||||||
|
if (saved_herrno != -1)
|
||||||
|
h_errno = saved_herrno;
|
||||||
|
else if (got_nodata)
|
||||||
|
h_errno = NO_DATA;
|
||||||
|
else if (got_servfail)
|
||||||
|
h_errno = TRY_AGAIN;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Perform a call on res_query on the concatenation of name and domain,
|
||||||
|
* removing a trailing dot from name if domain is NULL.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_querydomain(
|
||||||
|
const char *name,
|
||||||
|
const char *domain,
|
||||||
|
int class, /* class of query */
|
||||||
|
int type, /* type of query */
|
||||||
|
u_char *answer, /* buffer to put answer */
|
||||||
|
int anslen /* size of answer */
|
||||||
|
)
|
||||||
|
{
|
||||||
|
char nbuf[MAXDNAME];
|
||||||
|
const char *longname = nbuf;
|
||||||
|
int n, d;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_res.options & RES_DEBUG)
|
||||||
|
printf(";; res_querydomain(%s, %s, %d, %d)\n",
|
||||||
|
name, domain?domain:"<Nil>", class, type);
|
||||||
|
#endif
|
||||||
|
if (domain == NULL) {
|
||||||
|
/*
|
||||||
|
* Check for trailing '.';
|
||||||
|
* copy without '.' if present.
|
||||||
|
*/
|
||||||
|
n = (int)strlen(name);
|
||||||
|
if (n >= MAXDNAME) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
n--;
|
||||||
|
if (n >= 0 && name[n] == '.') {
|
||||||
|
strncpy(nbuf, name, n);
|
||||||
|
nbuf[n] = '\0';
|
||||||
|
} else
|
||||||
|
longname = name;
|
||||||
|
} else {
|
||||||
|
n = (int)strlen(name);
|
||||||
|
d = (int)strlen(domain);
|
||||||
|
if (n + d + 1 >= MAXDNAME) {
|
||||||
|
h_errno = NO_RECOVERY;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
sprintf(nbuf, "%s.%s", name, domain);
|
||||||
|
}
|
||||||
|
return (res_query(longname, class, type, answer, anslen));
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *
|
||||||
|
hostalias(
|
||||||
|
const char *name
|
||||||
|
)
|
||||||
|
{
|
||||||
|
register char *cp1, *cp2;
|
||||||
|
FILE *fp;
|
||||||
|
char *file;
|
||||||
|
char buf[BUFSIZ];
|
||||||
|
static char abuf[MAXDNAME];
|
||||||
|
|
||||||
|
if (_res.options & RES_NOALIASES)
|
||||||
|
return (NULL);
|
||||||
|
#ifdef _ORG_FREEBSD_
|
||||||
|
if (issetugid())
|
||||||
|
return (NULL);
|
||||||
|
#endif
|
||||||
|
file = getenv("HOSTALIASES");
|
||||||
|
if (file == NULL || (fp = fopen(file, "r")) == NULL)
|
||||||
|
return (NULL);
|
||||||
|
setbuf(fp, NULL);
|
||||||
|
buf[sizeof(buf) - 1] = '\0';
|
||||||
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
|
for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
|
||||||
|
;
|
||||||
|
if (!*cp1)
|
||||||
|
break;
|
||||||
|
*cp1 = '\0';
|
||||||
|
if (!strcasecmp(buf, name)) {
|
||||||
|
while (isspace(*++cp1))
|
||||||
|
;
|
||||||
|
if (!*cp1)
|
||||||
|
break;
|
||||||
|
for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
|
||||||
|
;
|
||||||
|
abuf[sizeof(abuf) - 1] = *cp2 = '\0';
|
||||||
|
strncpy(abuf, cp1, sizeof(abuf) - 1);
|
||||||
|
fclose(fp);
|
||||||
|
return (abuf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
return (NULL);
|
||||||
|
}
|
934
StdLib/BsdSocketLib/res_send.c
Normal file
934
StdLib/BsdSocketLib/res_send.c
Normal file
@ -0,0 +1,934 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1985, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies, and that
|
||||||
|
* the name of Digital Equipment Corporation not be used in advertising or
|
||||||
|
* publicity pertaining to distribution of the document or software without
|
||||||
|
* specific, written prior permission.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
|
||||||
|
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
|
||||||
|
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(LIBC_SCCS) && !defined(lint)
|
||||||
|
static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
|
||||||
|
static char orig_rcsid[] = "From: Id: res_send.c,v 8.20 1998/04/06 23:27:51 halley Exp $";
|
||||||
|
static char rcsid[] = "$Id: res_send.c,v 1.1.1.1 2003/11/19 01:51:39 kyu3 Exp $";
|
||||||
|
#endif /* LIBC_SCCS and not lint */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send query to name server and wait for reply.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/uio.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "res_config.h"
|
||||||
|
|
||||||
|
#ifndef _ORG_FREEBSD_
|
||||||
|
#define NOPOLL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef NOPOLL /* libc_r doesn't wrap poll yet() */
|
||||||
|
static int use_poll = 0;
|
||||||
|
#else
|
||||||
|
#include <poll.h>
|
||||||
|
static int use_poll = 1; /* adapt to poll() syscall availability */
|
||||||
|
/* 0 = not present, 1 = try it, 2 = exists */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static int s = -1; /* socket used for communications */
|
||||||
|
static int connected = 0; /* is the socket connected */
|
||||||
|
static int vc = 0; /* is the socket a virtual circuit? */
|
||||||
|
static res_send_qhook Qhook = NULL;
|
||||||
|
static res_send_rhook Rhook = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
#define CAN_RECONNECT 1
|
||||||
|
|
||||||
|
#ifndef DEBUG
|
||||||
|
# define Dprint(cond, args) /*empty*/
|
||||||
|
# define DprintQ(cond, args, query, size) /*empty*/
|
||||||
|
# define Aerror(file, string, error, address) /*empty*/
|
||||||
|
# define Perror(file, string, error) /*empty*/
|
||||||
|
#else
|
||||||
|
# define Dprint(cond, args) if (cond) {fprintf args;} else {}
|
||||||
|
# define DprintQ(cond, args, query, size) if (cond) {\
|
||||||
|
fprintf args;\
|
||||||
|
__fp_nquery(query, size, stdout);\
|
||||||
|
} else {}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Aerror(
|
||||||
|
FILE *file,
|
||||||
|
char *string,
|
||||||
|
int error,
|
||||||
|
struct sockaddr_in address
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int save = errno;
|
||||||
|
|
||||||
|
if (_res.options & RES_DEBUG) {
|
||||||
|
fprintf(file, "res_send: %s ([%s].%u): %s\n",
|
||||||
|
string,
|
||||||
|
inet_ntoa(address.sin_addr),
|
||||||
|
ntohs(address.sin_port),
|
||||||
|
strerror(error));
|
||||||
|
}
|
||||||
|
errno = save;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
Perror(
|
||||||
|
FILE *file,
|
||||||
|
char *string,
|
||||||
|
int error
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int save = errno;
|
||||||
|
|
||||||
|
if (_res.options & RES_DEBUG) {
|
||||||
|
fprintf(file, "res_send: %s: %s\n",
|
||||||
|
string, strerror(error));
|
||||||
|
}
|
||||||
|
errno = save;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void
|
||||||
|
res_send_setqhook(
|
||||||
|
res_send_qhook hook
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
Qhook = hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
res_send_setrhook(
|
||||||
|
res_send_rhook hook
|
||||||
|
)
|
||||||
|
{
|
||||||
|
|
||||||
|
Rhook = hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* res_isourserver(ina)
|
||||||
|
* looks up "ina" in _res.ns_addr_list[]
|
||||||
|
* returns:
|
||||||
|
* 0 : not found
|
||||||
|
* >0 : found
|
||||||
|
* author:
|
||||||
|
* paul vixie, 29may94
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_isourserver(
|
||||||
|
const struct sockaddr_in *inp
|
||||||
|
)
|
||||||
|
{
|
||||||
|
struct sockaddr_in ina;
|
||||||
|
int ns, ret;
|
||||||
|
|
||||||
|
ina = *inp;
|
||||||
|
ret = 0;
|
||||||
|
for (ns = 0; ns < _res.nscount; ns++) {
|
||||||
|
const struct sockaddr_in *srv = &_res.nsaddr_list[ns];
|
||||||
|
|
||||||
|
if (srv->sin_family == ina.sin_family &&
|
||||||
|
srv->sin_port == ina.sin_port &&
|
||||||
|
(srv->sin_addr.s_addr == INADDR_ANY ||
|
||||||
|
srv->sin_addr.s_addr == ina.sin_addr.s_addr)) {
|
||||||
|
ret++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* res_nameinquery(name, type, class, buf, eom)
|
||||||
|
* look for (name,type,class) in the query section of packet (buf,eom)
|
||||||
|
* requires:
|
||||||
|
* buf + HFIXEDSZ <= eom
|
||||||
|
* returns:
|
||||||
|
* -1 : format error
|
||||||
|
* 0 : not found
|
||||||
|
* >0 : found
|
||||||
|
* author:
|
||||||
|
* paul vixie, 29may94
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_nameinquery(
|
||||||
|
const char *name,
|
||||||
|
int type,
|
||||||
|
int class,
|
||||||
|
const u_char *buf,
|
||||||
|
const u_char *eom
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const u_char *cp = buf + HFIXEDSZ;
|
||||||
|
int qdcount = ntohs(((HEADER*)buf)->qdcount);
|
||||||
|
|
||||||
|
while (qdcount-- > 0) {
|
||||||
|
char tname[MAXDNAME+1];
|
||||||
|
int n, ttype, tclass;
|
||||||
|
|
||||||
|
n = dn_expand(buf, eom, cp, tname, sizeof tname);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
if (cp + 2 * INT16SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
ttype = ns_get16(cp); cp += INT16SZ;
|
||||||
|
tclass = ns_get16(cp); cp += INT16SZ;
|
||||||
|
if (ttype == type &&
|
||||||
|
tclass == class &&
|
||||||
|
strcasecmp(tname, name) == 0)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* int
|
||||||
|
* res_queriesmatch(buf1, eom1, buf2, eom2)
|
||||||
|
* is there a 1:1 mapping of (name,type,class)
|
||||||
|
* in (buf1,eom1) and (buf2,eom2)?
|
||||||
|
* returns:
|
||||||
|
* -1 : format error
|
||||||
|
* 0 : not a 1:1 mapping
|
||||||
|
* >0 : is a 1:1 mapping
|
||||||
|
* author:
|
||||||
|
* paul vixie, 29may94
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
res_queriesmatch(
|
||||||
|
const u_char *buf1,
|
||||||
|
const u_char *eom1,
|
||||||
|
const u_char *buf2,
|
||||||
|
const u_char *eom2
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const u_char *cp = buf1 + HFIXEDSZ;
|
||||||
|
int qdcount = ntohs(((HEADER*)buf1)->qdcount);
|
||||||
|
|
||||||
|
if (buf1 + HFIXEDSZ > eom1 || buf2 + HFIXEDSZ > eom2)
|
||||||
|
return (-1);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only header section present in replies to
|
||||||
|
* dynamic update packets.
|
||||||
|
*/
|
||||||
|
if ( (((HEADER *)buf1)->opcode == ns_o_update) &&
|
||||||
|
(((HEADER *)buf2)->opcode == ns_o_update) )
|
||||||
|
return (1);
|
||||||
|
|
||||||
|
if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
|
||||||
|
return (0);
|
||||||
|
while (qdcount-- > 0) {
|
||||||
|
char tname[MAXDNAME+1];
|
||||||
|
int n, ttype, tclass;
|
||||||
|
|
||||||
|
n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
if (cp + 2 * INT16SZ > eom1)
|
||||||
|
return (-1);
|
||||||
|
ttype = ns_get16(cp); cp += INT16SZ;
|
||||||
|
tclass = ns_get16(cp); cp += INT16SZ;
|
||||||
|
if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
res_send(
|
||||||
|
const u_char *buf,
|
||||||
|
int buflen,
|
||||||
|
u_char *ans,
|
||||||
|
int anssiz
|
||||||
|
)
|
||||||
|
{
|
||||||
|
HEADER *hp = (HEADER *) buf;
|
||||||
|
HEADER *anhp = (HEADER *) ans;
|
||||||
|
int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns;
|
||||||
|
ssize_t n;
|
||||||
|
u_int32_t badns; /* XXX NSMAX can't exceed #/bits in this variable */
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
/* errno should have been set by res_init() in this case. */
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (anssiz < HFIXEDSZ) {
|
||||||
|
errno = EINVAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
|
||||||
|
(stdout, ";; res_send()\n"), buf, buflen);
|
||||||
|
v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
|
||||||
|
gotsomewhere = 0;
|
||||||
|
connreset = 0;
|
||||||
|
terrno = ETIMEDOUT;
|
||||||
|
badns = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Send request, RETRY times, or until successful
|
||||||
|
*/
|
||||||
|
for (try = 0; try < _res.retry; try++) {
|
||||||
|
for (ns = 0; ns < _res.nscount; ns++) {
|
||||||
|
struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
|
||||||
|
same_ns:
|
||||||
|
if (badns & (1 << ns)) {
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Qhook) {
|
||||||
|
int done = 0, loops = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
res_sendhookact act;
|
||||||
|
|
||||||
|
act = (*Qhook)(&nsap, &buf, &buflen,
|
||||||
|
ans, anssiz, &resplen);
|
||||||
|
switch (act) {
|
||||||
|
case res_goahead:
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
|
case res_nextns:
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
case res_done:
|
||||||
|
return (resplen);
|
||||||
|
case res_modified:
|
||||||
|
/* give the hook another try */
|
||||||
|
if (++loops < 42) /*doug adams*/
|
||||||
|
break;
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
case res_error:
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
default:
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} while (!done);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; Querying server (# %d) address = %s\n",
|
||||||
|
ns + 1, inet_ntoa(nsap->sin_addr)));
|
||||||
|
|
||||||
|
if (v_circuit) {
|
||||||
|
int truncated;
|
||||||
|
struct iovec iov[2];
|
||||||
|
u_short len;
|
||||||
|
u_char *cp;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Use virtual circuit;
|
||||||
|
* at most one attempt per server.
|
||||||
|
*/
|
||||||
|
try = _res.retry;
|
||||||
|
truncated = 0;
|
||||||
|
if (s < 0 || !vc || hp->opcode == ns_o_update) {
|
||||||
|
if (s >= 0)
|
||||||
|
res_close();
|
||||||
|
|
||||||
|
s = socket(PF_INET, SOCK_STREAM, 0);
|
||||||
|
if (s < 0) {
|
||||||
|
terrno = errno;
|
||||||
|
Perror(stderr, "socket(vc)", errno);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
nsap->sin_len = sizeof ( *nsap );
|
||||||
|
if (connect(s, (struct sockaddr *)nsap,
|
||||||
|
sizeof *nsap) < 0) {
|
||||||
|
terrno = errno;
|
||||||
|
Aerror(stderr, "connect/vc",
|
||||||
|
errno, *nsap);
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
vc = 1;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Send length & message
|
||||||
|
*/
|
||||||
|
putshort((u_short)buflen, (u_char*)&len);
|
||||||
|
iov[0].iov_base = (caddr_t)&len;
|
||||||
|
iov[0].iov_len = INT16SZ;
|
||||||
|
iov[1].iov_base = (caddr_t)buf;
|
||||||
|
iov[1].iov_len = buflen;
|
||||||
|
if (writev(s, iov, 2) != (INT16SZ + buflen)) {
|
||||||
|
terrno = errno;
|
||||||
|
Perror(stderr, "write failed", errno);
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* Receive length & response
|
||||||
|
*/
|
||||||
|
read_len:
|
||||||
|
cp = ans;
|
||||||
|
len = INT16SZ;
|
||||||
|
while ((n = read(s, (char *)cp, (int)len)) > 0) {
|
||||||
|
cp += n;
|
||||||
|
len = (u_short)( len - n );
|
||||||
|
if (len <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (n <= 0) {
|
||||||
|
terrno = errno;
|
||||||
|
Perror(stderr, "read failed", errno);
|
||||||
|
res_close();
|
||||||
|
/*
|
||||||
|
* A long running process might get its TCP
|
||||||
|
* connection reset if the remote server was
|
||||||
|
* restarted. Requery the server instead of
|
||||||
|
* trying a new one. When there is only one
|
||||||
|
* server, this means that a query might work
|
||||||
|
* instead of failing. We only allow one reset
|
||||||
|
* per query to prevent looping.
|
||||||
|
*/
|
||||||
|
if (terrno == ECONNRESET && !connreset) {
|
||||||
|
connreset = 1;
|
||||||
|
res_close();
|
||||||
|
goto same_ns;
|
||||||
|
}
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
resplen = ns_get16(ans);
|
||||||
|
if (resplen > anssiz) {
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; response truncated\n")
|
||||||
|
);
|
||||||
|
truncated = 1;
|
||||||
|
len = (ushort)anssiz;
|
||||||
|
} else
|
||||||
|
len = (ushort)resplen;
|
||||||
|
if (len < HFIXEDSZ) {
|
||||||
|
/*
|
||||||
|
* Undersized message.
|
||||||
|
*/
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; undersized: %d\n", len));
|
||||||
|
terrno = EMSGSIZE;
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
cp = ans;
|
||||||
|
while (len != 0 &&
|
||||||
|
(n = read(s, (char *)cp, (int)len)) > 0) {
|
||||||
|
cp += n;
|
||||||
|
len = (u_short)( len - n );
|
||||||
|
}
|
||||||
|
if (n <= 0) {
|
||||||
|
terrno = errno;
|
||||||
|
Perror(stderr, "read(vc)", errno);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
if (truncated) {
|
||||||
|
/*
|
||||||
|
* Flush rest of answer
|
||||||
|
* so connection stays in synch.
|
||||||
|
*/
|
||||||
|
anhp->tc = 1;
|
||||||
|
len = (ushort)( resplen - anssiz );
|
||||||
|
while (len != 0) {
|
||||||
|
char junk[PACKETSZ];
|
||||||
|
|
||||||
|
n = (len > sizeof(junk)
|
||||||
|
? sizeof(junk)
|
||||||
|
: len);
|
||||||
|
if ((n = read(s, junk, n)) > 0)
|
||||||
|
len = (u_short)( len - n );
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
* The calling applicating has bailed out of
|
||||||
|
* a previous call and failed to arrange to have
|
||||||
|
* the circuit closed or the server has got
|
||||||
|
* itself confused. Anyway drop the packet and
|
||||||
|
* wait for the correct one.
|
||||||
|
*/
|
||||||
|
if (hp->id != anhp->id) {
|
||||||
|
DprintQ((_res.options & RES_DEBUG) ||
|
||||||
|
(_res.pfcode & RES_PRF_REPLY),
|
||||||
|
(stdout, ";; old answer (unexpected):\n"),
|
||||||
|
ans, (resplen>anssiz)?anssiz:resplen);
|
||||||
|
goto read_len;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Use datagrams.
|
||||||
|
*/
|
||||||
|
#ifndef NOPOLL
|
||||||
|
struct pollfd pfd;
|
||||||
|
int msec;
|
||||||
|
#endif
|
||||||
|
struct timeval timeout;
|
||||||
|
fd_set dsmask, *dsmaskp;
|
||||||
|
int dsmasklen;
|
||||||
|
struct sockaddr_in from;
|
||||||
|
int fromlen;
|
||||||
|
|
||||||
|
if ((s < 0) || vc) {
|
||||||
|
if (vc)
|
||||||
|
res_close();
|
||||||
|
s = socket(PF_INET, SOCK_DGRAM, 0);
|
||||||
|
if (s < 0) {
|
||||||
|
#ifndef CAN_RECONNECT
|
||||||
|
bad_dg_sock:
|
||||||
|
#endif
|
||||||
|
terrno = errno;
|
||||||
|
Perror(stderr, "socket(dg)", errno);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
connected = 0;
|
||||||
|
}
|
||||||
|
#ifndef CANNOT_CONNECT_DGRAM
|
||||||
|
/*
|
||||||
|
* On a 4.3BSD+ machine (client and server,
|
||||||
|
* actually), sending to a nameserver datagram
|
||||||
|
* port with no nameserver will cause an
|
||||||
|
* ICMP port unreachable message to be returned.
|
||||||
|
* If our datagram socket is "connected" to the
|
||||||
|
* server, we get an ECONNREFUSED error on the next
|
||||||
|
* socket operation, and select returns if the
|
||||||
|
* error message is received. We can thus detect
|
||||||
|
* the absence of a nameserver without timing out.
|
||||||
|
* If we have sent queries to at least two servers,
|
||||||
|
* however, we don't want to remain connected,
|
||||||
|
* as we wish to receive answers from the first
|
||||||
|
* server to respond.
|
||||||
|
*/
|
||||||
|
if (_res.nscount == 1 || (try == 0 && ns == 0)) {
|
||||||
|
/*
|
||||||
|
* Connect only if we are sure we won't
|
||||||
|
* receive a response from another server.
|
||||||
|
*/
|
||||||
|
if (!connected) {
|
||||||
|
nsap->sin_len = sizeof ( *nsap );
|
||||||
|
if (connect(s, (struct sockaddr *)nsap,
|
||||||
|
sizeof *nsap
|
||||||
|
) < 0) {
|
||||||
|
Aerror(stderr,
|
||||||
|
"connect(dg)",
|
||||||
|
errno, *nsap);
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
connected = 1;
|
||||||
|
}
|
||||||
|
if (send(s, (char*)buf, buflen, 0) != buflen) {
|
||||||
|
Perror(stderr, "send", errno);
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Disconnect if we want to listen
|
||||||
|
* for responses from more than one server.
|
||||||
|
*/
|
||||||
|
if (connected) {
|
||||||
|
#ifdef CAN_RECONNECT
|
||||||
|
struct sockaddr_in no_addr;
|
||||||
|
|
||||||
|
no_addr.sin_family = AF_INET;
|
||||||
|
no_addr.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
no_addr.sin_port = 0;
|
||||||
|
(void) connect(s,
|
||||||
|
(struct sockaddr *)
|
||||||
|
&no_addr,
|
||||||
|
sizeof no_addr);
|
||||||
|
#else
|
||||||
|
int s1 = socket(PF_INET, SOCK_DGRAM,0);
|
||||||
|
if (s1 < 0)
|
||||||
|
goto bad_dg_sock;
|
||||||
|
(void) dup2(s1, s);
|
||||||
|
(void) close(s1);
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; new DG socket\n"))
|
||||||
|
#endif /* CAN_RECONNECT */
|
||||||
|
connected = 0;
|
||||||
|
errno = 0;
|
||||||
|
}
|
||||||
|
#endif /* !CANNOT_CONNECT_DGRAM */
|
||||||
|
if (sendto(s, (char*)buf, buflen, 0,
|
||||||
|
(struct sockaddr *)nsap,
|
||||||
|
sizeof *nsap)
|
||||||
|
!= buflen) {
|
||||||
|
Aerror(stderr, "sendto", errno, *nsap);
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
#ifndef CANNOT_CONNECT_DGRAM
|
||||||
|
}
|
||||||
|
#endif /* !CANNOT_CONNECT_DGRAM */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wait for reply
|
||||||
|
*/
|
||||||
|
#ifndef NOPOLL
|
||||||
|
othersyscall:
|
||||||
|
if (use_poll) {
|
||||||
|
msec = (_res.retrans << try) * 1000;
|
||||||
|
if (try > 0)
|
||||||
|
msec /= _res.nscount;
|
||||||
|
if (msec <= 0)
|
||||||
|
msec = 1000;
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
timeout.tv_sec = (_res.retrans << try);
|
||||||
|
if (try > 0)
|
||||||
|
timeout.tv_sec /= _res.nscount;
|
||||||
|
if ((long) timeout.tv_sec <= 0)
|
||||||
|
timeout.tv_sec = 1;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
#ifndef NOPOLL
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
wait:
|
||||||
|
if (s < 0) {
|
||||||
|
Perror(stderr, "s out-of-bounds", EMFILE);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
#ifndef NOPOLL
|
||||||
|
if (use_poll) {
|
||||||
|
struct sigaction sa, osa;
|
||||||
|
int sigsys_installed = 0;
|
||||||
|
|
||||||
|
pfd.fd = s;
|
||||||
|
pfd.events = POLLIN;
|
||||||
|
if (use_poll == 1) {
|
||||||
|
bzero(&sa, sizeof(sa));
|
||||||
|
sa.sa_handler = SIG_IGN;
|
||||||
|
if (sigaction(SIGSYS, &sa, &osa) >= 0)
|
||||||
|
sigsys_installed = 1;
|
||||||
|
}
|
||||||
|
n = poll(&pfd, 1, msec);
|
||||||
|
if (sigsys_installed == 1) {
|
||||||
|
int oerrno = errno;
|
||||||
|
sigaction(SIGSYS, &osa, NULL);
|
||||||
|
errno = oerrno;
|
||||||
|
}
|
||||||
|
/* XXX why does nosys() return EINVAL? */
|
||||||
|
if (n < 0 && (errno == ENOSYS ||
|
||||||
|
errno == EINVAL)) {
|
||||||
|
use_poll = 0;
|
||||||
|
goto othersyscall;
|
||||||
|
} else if (use_poll == 1)
|
||||||
|
use_poll = 2;
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno == EINTR)
|
||||||
|
goto wait;
|
||||||
|
Perror(stderr, "poll", errno);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
#endif
|
||||||
|
dsmasklen = howmany(s + 1, NFDBITS) *
|
||||||
|
sizeof(fd_mask);
|
||||||
|
if (dsmasklen > sizeof(fd_set)) {
|
||||||
|
dsmaskp = (fd_set *)malloc(dsmasklen);
|
||||||
|
if (dsmaskp == NULL) {
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
dsmaskp = &dsmask;
|
||||||
|
/* only zero what we need */
|
||||||
|
memset((char *)dsmaskp, 0, dsmasklen);
|
||||||
|
FD_SET(s, dsmaskp);
|
||||||
|
n = select(s + 1, dsmaskp, (fd_set *)NULL,
|
||||||
|
(fd_set *)NULL, &timeout);
|
||||||
|
if (dsmaskp != &dsmask)
|
||||||
|
free(dsmaskp);
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno == EINTR)
|
||||||
|
goto wait;
|
||||||
|
Perror(stderr, "select", errno);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
#ifndef NOPOLL
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (n == 0) {
|
||||||
|
/*
|
||||||
|
* timeout
|
||||||
|
*/
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; timeout\n"));
|
||||||
|
gotsomewhere = 1;
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
errno = 0;
|
||||||
|
fromlen = sizeof(struct sockaddr_in);
|
||||||
|
resplen = (int)recvfrom(s, (char*)ans, anssiz, 0,
|
||||||
|
(struct sockaddr *)&from, &fromlen);
|
||||||
|
if (resplen <= 0) {
|
||||||
|
Perror(stderr, "recvfrom", errno);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
gotsomewhere = 1;
|
||||||
|
if (resplen < HFIXEDSZ) {
|
||||||
|
/*
|
||||||
|
* Undersized message.
|
||||||
|
*/
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; undersized: %d\n",
|
||||||
|
resplen));
|
||||||
|
terrno = EMSGSIZE;
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
if (hp->id != anhp->id) {
|
||||||
|
/*
|
||||||
|
* response from old query, ignore it.
|
||||||
|
* XXX - potential security hazard could
|
||||||
|
* be detected here.
|
||||||
|
*/
|
||||||
|
DprintQ((_res.options & RES_DEBUG) ||
|
||||||
|
(_res.pfcode & RES_PRF_REPLY),
|
||||||
|
(stdout, ";; old answer:\n"),
|
||||||
|
ans, (resplen>anssiz)?anssiz:resplen);
|
||||||
|
goto wait;
|
||||||
|
}
|
||||||
|
#ifdef CHECK_SRVR_ADDR
|
||||||
|
if (!(_res.options & RES_INSECURE1) &&
|
||||||
|
!res_isourserver(&from)) {
|
||||||
|
/*
|
||||||
|
* response from wrong server? ignore it.
|
||||||
|
* XXX - potential security hazard could
|
||||||
|
* be detected here.
|
||||||
|
*/
|
||||||
|
DprintQ((_res.options & RES_DEBUG) ||
|
||||||
|
(_res.pfcode & RES_PRF_REPLY),
|
||||||
|
(stdout, ";; not our server:\n"),
|
||||||
|
ans, (resplen>anssiz)?anssiz:resplen);
|
||||||
|
goto wait;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (!(_res.options & RES_INSECURE2) &&
|
||||||
|
!res_queriesmatch(buf, buf + buflen,
|
||||||
|
ans, ans + anssiz)) {
|
||||||
|
/*
|
||||||
|
* response contains wrong query? ignore it.
|
||||||
|
* XXX - potential security hazard could
|
||||||
|
* be detected here.
|
||||||
|
*/
|
||||||
|
DprintQ((_res.options & RES_DEBUG) ||
|
||||||
|
(_res.pfcode & RES_PRF_REPLY),
|
||||||
|
(stdout, ";; wrong query name:\n"),
|
||||||
|
ans, (resplen>anssiz)?anssiz:resplen);
|
||||||
|
goto wait;
|
||||||
|
}
|
||||||
|
if (anhp->rcode == SERVFAIL ||
|
||||||
|
anhp->rcode == NOTIMP ||
|
||||||
|
anhp->rcode == REFUSED) {
|
||||||
|
DprintQ(_res.options & RES_DEBUG,
|
||||||
|
(stdout, "server rejected query:\n"),
|
||||||
|
ans, (resplen>anssiz)?anssiz:resplen);
|
||||||
|
badns |= (1 << ns);
|
||||||
|
res_close();
|
||||||
|
/* don't retry if called from dig */
|
||||||
|
if (!_res.pfcode)
|
||||||
|
goto next_ns;
|
||||||
|
}
|
||||||
|
if (!(_res.options & RES_IGNTC) && anhp->tc) {
|
||||||
|
/*
|
||||||
|
* get rest of answer;
|
||||||
|
* use TCP with same server.
|
||||||
|
*/
|
||||||
|
Dprint(_res.options & RES_DEBUG,
|
||||||
|
(stdout, ";; truncated answer\n"));
|
||||||
|
v_circuit = 1;
|
||||||
|
res_close();
|
||||||
|
goto same_ns;
|
||||||
|
}
|
||||||
|
} /*if vc/dg*/
|
||||||
|
Dprint((_res.options & RES_DEBUG) ||
|
||||||
|
((_res.pfcode & RES_PRF_REPLY) &&
|
||||||
|
(_res.pfcode & RES_PRF_HEAD1)),
|
||||||
|
(stdout, ";; got answer:\n"));
|
||||||
|
DprintQ((_res.options & RES_DEBUG) ||
|
||||||
|
(_res.pfcode & RES_PRF_REPLY),
|
||||||
|
(stdout, ""),
|
||||||
|
ans, (resplen>anssiz)?anssiz:resplen);
|
||||||
|
/*
|
||||||
|
* If using virtual circuits, we assume that the first server
|
||||||
|
* is preferred over the rest (i.e. it is on the local
|
||||||
|
* machine) and only keep that one open.
|
||||||
|
* If we have temporarily opened a virtual circuit,
|
||||||
|
* or if we haven't been asked to keep a socket open,
|
||||||
|
* close the socket.
|
||||||
|
*/
|
||||||
|
if ((v_circuit && (!(_res.options & RES_USEVC) || ns != 0)) ||
|
||||||
|
!(_res.options & RES_STAYOPEN)) {
|
||||||
|
res_close();
|
||||||
|
}
|
||||||
|
if (Rhook) {
|
||||||
|
int done = 0, loops = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
res_sendhookact act;
|
||||||
|
|
||||||
|
act = (*Rhook)(nsap, buf, buflen,
|
||||||
|
ans, anssiz, &resplen);
|
||||||
|
switch (act) {
|
||||||
|
case res_goahead:
|
||||||
|
case res_done:
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
|
case res_nextns:
|
||||||
|
res_close();
|
||||||
|
goto next_ns;
|
||||||
|
case res_modified:
|
||||||
|
/* give the hook another try */
|
||||||
|
if (++loops < 42) /*doug adams*/
|
||||||
|
break;
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
case res_error:
|
||||||
|
/*FALLTHROUGH*/
|
||||||
|
default:
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} while (!done);
|
||||||
|
|
||||||
|
}
|
||||||
|
return (resplen);
|
||||||
|
next_ns: ;
|
||||||
|
} /*foreach ns*/
|
||||||
|
} /*foreach retry*/
|
||||||
|
res_close();
|
||||||
|
if (!v_circuit) {
|
||||||
|
if (!gotsomewhere)
|
||||||
|
errno = ECONNREFUSED; /* no nameservers found */
|
||||||
|
else
|
||||||
|
errno = ETIMEDOUT; /* no answer obtained */
|
||||||
|
} else
|
||||||
|
errno = terrno;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This routine is for closing the socket if a virtual circuit is used and
|
||||||
|
* the program wants to close it. This provides support for endhostent()
|
||||||
|
* which expects to close the socket.
|
||||||
|
*
|
||||||
|
* This routine is not expected to be user visible.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
res_close()
|
||||||
|
{
|
||||||
|
if (s >= 0) {
|
||||||
|
(void) close(s);
|
||||||
|
s = -1;
|
||||||
|
connected = 0;
|
||||||
|
vc = 0;
|
||||||
|
}
|
||||||
|
}
|
556
StdLib/BsdSocketLib/res_update.c
Normal file
556
StdLib/BsdSocketLib/res_update.c
Normal file
@ -0,0 +1,556 @@
|
|||||||
|
#if !defined(lint) && !defined(SABER)
|
||||||
|
static char rcsid[] = "$Id: res_update.c,v 1.1.1.1 2003/11/19 01:51:39 kyu3 Exp $";
|
||||||
|
#endif /* not lint */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and
|
||||||
|
* its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Based on the Dynamic DNS reference implementation by Viraj Bais
|
||||||
|
* <viraj_bais@ccm.fm.intel.com>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
#include <resolv.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Separate a linked list of records into groups so that all records
|
||||||
|
* in a group will belong to a single zone on the nameserver.
|
||||||
|
* Create a dynamic update packet for each zone and send it to the
|
||||||
|
* nameservers for that zone, and await answer.
|
||||||
|
* Abort if error occurs in updating any zone.
|
||||||
|
* Return the number of zones updated on success, < 0 on error.
|
||||||
|
*
|
||||||
|
* On error, caller must deal with the unsynchronized zones
|
||||||
|
* eg. an A record might have been successfully added to the forward
|
||||||
|
* zone but the corresponding PTR record would be missing if error
|
||||||
|
* was encountered while updating the reverse zone.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define NSMAX 16
|
||||||
|
|
||||||
|
struct ns1 {
|
||||||
|
char nsname[MAXDNAME];
|
||||||
|
struct in_addr nsaddr1;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct zonegrp {
|
||||||
|
char z_origin[MAXDNAME];
|
||||||
|
int16_t z_class;
|
||||||
|
char z_soardata[MAXDNAME + 5 * INT32SZ];
|
||||||
|
struct ns1 z_ns[NSMAX];
|
||||||
|
int z_nscount;
|
||||||
|
ns_updrec * z_rr;
|
||||||
|
struct zonegrp *z_next;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
res_update(ns_updrec *rrecp_in) {
|
||||||
|
ns_updrec *rrecp, *tmprrecp;
|
||||||
|
u_char buf[PACKETSZ], answer[PACKETSZ], packet[2*PACKETSZ];
|
||||||
|
char name[MAXDNAME], zname[MAXDNAME], primary[MAXDNAME],
|
||||||
|
mailaddr[MAXDNAME];
|
||||||
|
u_char soardata[2*MAXCDNAME+5*INT32SZ];
|
||||||
|
char *dname, *svdname, *cp1, *target;
|
||||||
|
u_char *cp, *eom;
|
||||||
|
HEADER *hp = (HEADER *) answer;
|
||||||
|
struct zonegrp *zptr = NULL, *tmpzptr, *prevzptr, *zgrp_start = NULL;
|
||||||
|
int i, j, k = 0, n, ancount, nscount, arcount, rcode, rdatasize,
|
||||||
|
newgroup, done, myzone, seen_before, numzones = 0;
|
||||||
|
u_int16_t dlen, class, qclass, type, qtype;
|
||||||
|
u_int32_t ttl;
|
||||||
|
|
||||||
|
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
|
||||||
|
h_errno = NETDB_INTERNAL;
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (rrecp = rrecp_in; rrecp; rrecp = rrecp->r_next) {
|
||||||
|
dname = rrecp->r_dname;
|
||||||
|
n = (int)strlen(dname);
|
||||||
|
if (dname[n-1] == '.')
|
||||||
|
dname[n-1] = '\0';
|
||||||
|
qtype = T_SOA;
|
||||||
|
qclass = rrecp->r_class;
|
||||||
|
done = 0;
|
||||||
|
seen_before = 0;
|
||||||
|
|
||||||
|
while (!done && dname) {
|
||||||
|
if (qtype == T_SOA) {
|
||||||
|
for (tmpzptr = zgrp_start;
|
||||||
|
tmpzptr && !seen_before;
|
||||||
|
tmpzptr = tmpzptr->z_next) {
|
||||||
|
if (strcasecmp(dname,
|
||||||
|
tmpzptr->z_origin) == 0 &&
|
||||||
|
tmpzptr->z_class == qclass)
|
||||||
|
seen_before++;
|
||||||
|
for (tmprrecp = tmpzptr->z_rr;
|
||||||
|
tmprrecp && !seen_before;
|
||||||
|
tmprrecp = tmprrecp->r_grpnext)
|
||||||
|
if (strcasecmp(dname, tmprrecp->r_dname) == 0
|
||||||
|
&& tmprrecp->r_class == qclass) {
|
||||||
|
seen_before++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (seen_before) {
|
||||||
|
/*
|
||||||
|
* Append to the end of
|
||||||
|
* current group.
|
||||||
|
*/
|
||||||
|
for (tmprrecp = tmpzptr->z_rr;
|
||||||
|
tmprrecp->r_grpnext;
|
||||||
|
tmprrecp = tmprrecp->r_grpnext)
|
||||||
|
(void)NULL;
|
||||||
|
tmprrecp->r_grpnext = rrecp;
|
||||||
|
rrecp->r_grpnext = NULL;
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (qtype == T_A) {
|
||||||
|
for (tmpzptr = zgrp_start;
|
||||||
|
tmpzptr && !done;
|
||||||
|
tmpzptr = tmpzptr->z_next)
|
||||||
|
for (i = 0; i < tmpzptr->z_nscount; i++)
|
||||||
|
if (tmpzptr->z_class == qclass &&
|
||||||
|
strcasecmp(tmpzptr->z_ns[i].nsname,
|
||||||
|
dname) == 0 &&
|
||||||
|
tmpzptr->z_ns[i].nsaddr1.s_addr != 0) {
|
||||||
|
zptr->z_ns[k].nsaddr1.s_addr =
|
||||||
|
tmpzptr->z_ns[i].nsaddr1.s_addr;
|
||||||
|
done = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (done)
|
||||||
|
break;
|
||||||
|
n = res_mkquery(QUERY, dname, qclass, qtype, NULL,
|
||||||
|
0, NULL, buf, sizeof buf);
|
||||||
|
if (n <= 0) {
|
||||||
|
fprintf(stderr, "res_update: mkquery failed\n");
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
n = res_send(buf, n, answer, sizeof answer);
|
||||||
|
if (n < 0) {
|
||||||
|
fprintf(stderr, "res_update: send error for %s\n",
|
||||||
|
rrecp->r_dname);
|
||||||
|
return (n);
|
||||||
|
}
|
||||||
|
if (n < HFIXEDSZ)
|
||||||
|
return (-1);
|
||||||
|
ancount = ntohs(hp->ancount);
|
||||||
|
nscount = ntohs(hp->nscount);
|
||||||
|
arcount = ntohs(hp->arcount);
|
||||||
|
rcode = hp->rcode;
|
||||||
|
cp = answer + HFIXEDSZ;
|
||||||
|
eom = answer + n;
|
||||||
|
/* skip the question section */
|
||||||
|
n = dn_skipname(cp, eom);
|
||||||
|
if (n < 0 || cp + n + 2 * INT16SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
cp += n + 2 * INT16SZ;
|
||||||
|
|
||||||
|
if (qtype == T_SOA) {
|
||||||
|
if (ancount == 0 && nscount == 0 && arcount == 0) {
|
||||||
|
/*
|
||||||
|
* if (rcode == NOERROR) then the dname exists but
|
||||||
|
* has no soa record associated with it.
|
||||||
|
* if (rcode == NXDOMAIN) then the dname does not
|
||||||
|
* exist and the server is replying out of NCACHE.
|
||||||
|
* in either case, proceed with the next try
|
||||||
|
*/
|
||||||
|
dname = strchr(dname, '.');
|
||||||
|
if (dname != NULL)
|
||||||
|
dname++;
|
||||||
|
continue;
|
||||||
|
} else if ((rcode == NOERROR || rcode == NXDOMAIN) &&
|
||||||
|
ancount == 0 &&
|
||||||
|
nscount == 1 && arcount == 0) {
|
||||||
|
/*
|
||||||
|
* name/data does not exist, soa record supplied in the
|
||||||
|
* authority section
|
||||||
|
*/
|
||||||
|
/* authority section must contain the soa record */
|
||||||
|
if ((n = dn_expand(answer, eom, cp, zname,
|
||||||
|
sizeof zname)) < 0)
|
||||||
|
return (n);
|
||||||
|
cp += n;
|
||||||
|
if (cp + 2 * INT16SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
GETSHORT(type, cp);
|
||||||
|
GETSHORT(class, cp);
|
||||||
|
if (type != T_SOA || class != qclass) {
|
||||||
|
fprintf(stderr, "unknown answer\n");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
myzone = 0;
|
||||||
|
svdname = dname;
|
||||||
|
while (dname)
|
||||||
|
if (strcasecmp(dname, zname) == 0) {
|
||||||
|
myzone = 1;
|
||||||
|
break;
|
||||||
|
} else if ((dname = strchr(dname, '.')) != NULL)
|
||||||
|
dname++;
|
||||||
|
if (!myzone) {
|
||||||
|
dname = strchr(svdname, '.');
|
||||||
|
if (dname != NULL)
|
||||||
|
dname++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
nscount = 0;
|
||||||
|
/* fallthrough */
|
||||||
|
} else if (rcode == NOERROR && ancount == 1) {
|
||||||
|
/*
|
||||||
|
* found the zone name
|
||||||
|
* new servers will supply NS records for the zone
|
||||||
|
* in authority section and A records for those
|
||||||
|
* nameservers in the additional section
|
||||||
|
* older servers have to be explicitly queried for
|
||||||
|
* NS records for the zone
|
||||||
|
*/
|
||||||
|
/* answer section must contain the soa record */
|
||||||
|
if ((n = dn_expand(answer, eom, cp, zname,
|
||||||
|
sizeof zname)) < 0)
|
||||||
|
return (n);
|
||||||
|
else
|
||||||
|
cp += n;
|
||||||
|
if (cp + 2 * INT16SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
GETSHORT(type, cp);
|
||||||
|
GETSHORT(class, cp);
|
||||||
|
if (type == T_CNAME) {
|
||||||
|
dname = strchr(dname, '.');
|
||||||
|
if (dname != NULL)
|
||||||
|
dname++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (strcasecmp(dname, zname) != 0 ||
|
||||||
|
type != T_SOA ||
|
||||||
|
class != rrecp->r_class) {
|
||||||
|
fprintf(stderr, "unknown answer\n");
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
/* FALLTHROUGH */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr,
|
||||||
|
"unknown response: ans=%d, auth=%d, add=%d, rcode=%d\n",
|
||||||
|
ancount, nscount, arcount, hp->rcode);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
if (cp + INT32SZ + INT16SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
/* continue processing the soa record */
|
||||||
|
GETLONG(ttl, cp);
|
||||||
|
GETSHORT(dlen, cp);
|
||||||
|
if (cp + dlen > eom)
|
||||||
|
return (-1);
|
||||||
|
newgroup = 1;
|
||||||
|
zptr = zgrp_start;
|
||||||
|
prevzptr = NULL;
|
||||||
|
while (zptr) {
|
||||||
|
if (strcasecmp(zname, zptr->z_origin) == 0 &&
|
||||||
|
type == T_SOA && class == qclass) {
|
||||||
|
newgroup = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
prevzptr = zptr;
|
||||||
|
zptr = zptr->z_next;
|
||||||
|
}
|
||||||
|
if (!newgroup) {
|
||||||
|
for (tmprrecp = zptr->z_rr;
|
||||||
|
tmprrecp->r_grpnext;
|
||||||
|
tmprrecp = tmprrecp->r_grpnext)
|
||||||
|
;
|
||||||
|
tmprrecp->r_grpnext = rrecp;
|
||||||
|
rrecp->r_grpnext = NULL;
|
||||||
|
done = 1;
|
||||||
|
cp += dlen;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
if ((n = dn_expand(answer, eom, cp, primary,
|
||||||
|
sizeof primary)) < 0)
|
||||||
|
return (n);
|
||||||
|
cp += n;
|
||||||
|
/*
|
||||||
|
* We don't have to bounds check here because the
|
||||||
|
* next use of 'cp' is in dn_expand().
|
||||||
|
*/
|
||||||
|
cp1 = (char *)soardata;
|
||||||
|
strcpy(cp1, primary);
|
||||||
|
cp1 += strlen(cp1) + 1;
|
||||||
|
if ((n = dn_expand(answer, eom, cp, mailaddr,
|
||||||
|
sizeof mailaddr)) < 0)
|
||||||
|
return (n);
|
||||||
|
cp += n;
|
||||||
|
strcpy(cp1, mailaddr);
|
||||||
|
cp1 += strlen(cp1) + 1;
|
||||||
|
if (cp + 5*INT32SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
memcpy(cp1, cp, 5*INT32SZ);
|
||||||
|
cp += 5*INT32SZ;
|
||||||
|
cp1 += 5*INT32SZ;
|
||||||
|
rdatasize = (int)((u_char *)cp1 - soardata);
|
||||||
|
zptr = calloc(1, sizeof(struct zonegrp));
|
||||||
|
if (zptr == NULL)
|
||||||
|
return (-1);
|
||||||
|
if (zgrp_start == NULL)
|
||||||
|
zgrp_start = zptr;
|
||||||
|
else
|
||||||
|
prevzptr->z_next = zptr;
|
||||||
|
zptr->z_rr = rrecp;
|
||||||
|
rrecp->r_grpnext = NULL;
|
||||||
|
strcpy(zptr->z_origin, zname);
|
||||||
|
zptr->z_class = class;
|
||||||
|
memcpy(zptr->z_soardata, soardata, rdatasize);
|
||||||
|
/* fallthrough to process NS and A records */
|
||||||
|
}
|
||||||
|
} else if (qtype == T_NS) {
|
||||||
|
if (rcode == NOERROR && ancount > 0) {
|
||||||
|
strcpy(zname, dname);
|
||||||
|
for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
|
||||||
|
if (strcasecmp(zname, zptr->z_origin) == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (zptr == NULL)
|
||||||
|
/* should not happen */
|
||||||
|
return (-1);
|
||||||
|
if (nscount > 0) {
|
||||||
|
/*
|
||||||
|
* answer and authority sections contain
|
||||||
|
* the same information, skip answer section
|
||||||
|
*/
|
||||||
|
for (j = 0; j < ancount; j++) {
|
||||||
|
n = dn_skipname(cp, eom);
|
||||||
|
if (n < 0)
|
||||||
|
return (-1);
|
||||||
|
n += 2*INT16SZ + INT32SZ;
|
||||||
|
if (cp + n + INT16SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
cp += n;
|
||||||
|
GETSHORT(dlen, cp);
|
||||||
|
cp += dlen;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
nscount = ancount;
|
||||||
|
/* fallthrough to process NS and A records */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "cannot determine nameservers for %s:\
|
||||||
|
ans=%d, auth=%d, add=%d, rcode=%d\n",
|
||||||
|
dname, ancount, nscount, arcount, hp->rcode);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
} else if (qtype == T_A) {
|
||||||
|
if (rcode == NOERROR && ancount > 0) {
|
||||||
|
arcount = ancount;
|
||||||
|
ancount = nscount = 0;
|
||||||
|
/* fallthrough to process A records */
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "cannot determine address for %s:\
|
||||||
|
ans=%d, auth=%d, add=%d, rcode=%d\n",
|
||||||
|
dname, ancount, nscount, arcount, hp->rcode);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* process NS records for the zone */
|
||||||
|
j = 0;
|
||||||
|
for (i = 0; i < nscount; i++) {
|
||||||
|
if ((n = dn_expand(answer, eom, cp, name,
|
||||||
|
sizeof name)) < 0)
|
||||||
|
return (n);
|
||||||
|
cp += n;
|
||||||
|
if (cp + 3 * INT16SZ + INT32SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
GETSHORT(type, cp);
|
||||||
|
GETSHORT(class, cp);
|
||||||
|
GETLONG(ttl, cp);
|
||||||
|
GETSHORT(dlen, cp);
|
||||||
|
if (cp + dlen > eom)
|
||||||
|
return (-1);
|
||||||
|
if (strcasecmp(name, zname) == 0 &&
|
||||||
|
type == T_NS && class == qclass) {
|
||||||
|
if ((n = dn_expand(answer, eom, cp,
|
||||||
|
name, sizeof name)) < 0)
|
||||||
|
return (n);
|
||||||
|
target = zptr->z_ns[j++].nsname;
|
||||||
|
strcpy(target, name);
|
||||||
|
}
|
||||||
|
cp += dlen;
|
||||||
|
}
|
||||||
|
if (zptr->z_nscount == 0)
|
||||||
|
zptr->z_nscount = j;
|
||||||
|
/* get addresses for the nameservers */
|
||||||
|
for (i = 0; i < arcount; i++) {
|
||||||
|
if ((n = dn_expand(answer, eom, cp, name,
|
||||||
|
sizeof name)) < 0)
|
||||||
|
return (n);
|
||||||
|
cp += n;
|
||||||
|
if (cp + 3 * INT16SZ + INT32SZ > eom)
|
||||||
|
return (-1);
|
||||||
|
GETSHORT(type, cp);
|
||||||
|
GETSHORT(class, cp);
|
||||||
|
GETLONG(ttl, cp);
|
||||||
|
GETSHORT(dlen, cp);
|
||||||
|
if (cp + dlen > eom)
|
||||||
|
return (-1);
|
||||||
|
if (type == T_A && dlen == INT32SZ && class == qclass) {
|
||||||
|
for (j = 0; j < zptr->z_nscount; j++)
|
||||||
|
if (strcasecmp(name, zptr->z_ns[j].nsname) == 0) {
|
||||||
|
memcpy(&zptr->z_ns[j].nsaddr1.s_addr, cp,
|
||||||
|
INT32SZ);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cp += dlen;
|
||||||
|
}
|
||||||
|
if (zptr->z_nscount == 0) {
|
||||||
|
dname = zname;
|
||||||
|
qtype = T_NS;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
done = 1;
|
||||||
|
for (k = 0; k < zptr->z_nscount; k++)
|
||||||
|
if (zptr->z_ns[k].nsaddr1.s_addr == 0) {
|
||||||
|
done = 0;
|
||||||
|
dname = zptr->z_ns[k].nsname;
|
||||||
|
qtype = T_A;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* while */
|
||||||
|
}
|
||||||
|
|
||||||
|
_res.options |= RES_DEBUG;
|
||||||
|
for (zptr = zgrp_start; zptr; zptr = zptr->z_next) {
|
||||||
|
|
||||||
|
/* append zone section */
|
||||||
|
rrecp = res_mkupdrec(ns_s_zn, zptr->z_origin,
|
||||||
|
zptr->z_class, ns_t_soa, 0);
|
||||||
|
if (rrecp == NULL) {
|
||||||
|
fprintf(stderr, "saverrec error\n");
|
||||||
|
fflush(stderr);
|
||||||
|
return (-1);
|
||||||
|
}
|
||||||
|
rrecp->r_grpnext = zptr->z_rr;
|
||||||
|
zptr->z_rr = rrecp;
|
||||||
|
|
||||||
|
n = res_mkupdate(zptr->z_rr, packet, sizeof packet);
|
||||||
|
if (n < 0) {
|
||||||
|
fprintf(stderr, "res_mkupdate error\n");
|
||||||
|
fflush(stderr);
|
||||||
|
return (-1);
|
||||||
|
} else
|
||||||
|
fprintf(stdout, "res_mkupdate: packet size = %d\n", n);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Override the list of NS records from res_init() with
|
||||||
|
* the authoritative nameservers for the zone being updated.
|
||||||
|
* Sort primary to be the first in the list of nameservers.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < zptr->z_nscount; i++) {
|
||||||
|
if (strcasecmp(zptr->z_ns[i].nsname,
|
||||||
|
zptr->z_soardata) == 0) {
|
||||||
|
struct in_addr tmpaddr;
|
||||||
|
|
||||||
|
if (i != 0) {
|
||||||
|
strcpy(zptr->z_ns[i].nsname,
|
||||||
|
zptr->z_ns[0].nsname);
|
||||||
|
strcpy(zptr->z_ns[0].nsname,
|
||||||
|
zptr->z_soardata);
|
||||||
|
tmpaddr = zptr->z_ns[i].nsaddr1;
|
||||||
|
zptr->z_ns[i].nsaddr1 =
|
||||||
|
zptr->z_ns[0].nsaddr1;
|
||||||
|
zptr->z_ns[0].nsaddr1 = tmpaddr;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < MAXNS; i++) {
|
||||||
|
_res.nsaddr_list[i].sin_addr = zptr->z_ns[i].nsaddr1;
|
||||||
|
_res.nsaddr_list[i].sin_family = AF_INET;
|
||||||
|
_res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
|
||||||
|
}
|
||||||
|
_res.nscount = (zptr->z_nscount < MAXNS) ?
|
||||||
|
zptr->z_nscount : MAXNS;
|
||||||
|
n = res_send(packet, n, answer, sizeof(answer));
|
||||||
|
if (n < 0) {
|
||||||
|
fprintf(stderr, "res_send: send error, n=%d\n", n);
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
numzones++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* free malloc'ed memory */
|
||||||
|
while(zgrp_start) {
|
||||||
|
zptr = zgrp_start;
|
||||||
|
zgrp_start = zgrp_start->z_next;
|
||||||
|
res_freeupdrec(zptr->z_rr); /* Zone section we allocated. */
|
||||||
|
free((char *)zptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (numzones);
|
||||||
|
}
|
97
StdLib/BsdSocketLib/send.c
Normal file
97
StdLib/BsdSocketLib/send.c
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the send API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send data using a network connection.
|
||||||
|
|
||||||
|
The ::send routine queues data to the network for transmission.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] buffer Address of a buffer containing the data to send.
|
||||||
|
|
||||||
|
@param [in] length Length of the buffer in bytes.
|
||||||
|
|
||||||
|
@param [in] flags Message control flags
|
||||||
|
|
||||||
|
@returns ::send returns the number of data bytes that were
|
||||||
|
sent and -1 when an error occurs. In the case of
|
||||||
|
an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
send (
|
||||||
|
int s,
|
||||||
|
CONST void * buffer,
|
||||||
|
size_t length,
|
||||||
|
int flags
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ssize_t LengthInBytes;
|
||||||
|
CONST UINT8 * pData;
|
||||||
|
struct __filedes * pDescriptor;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
LengthInBytes = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s,
|
||||||
|
&pDescriptor,
|
||||||
|
&errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Send the data using the socket
|
||||||
|
//
|
||||||
|
pData = buffer;
|
||||||
|
do {
|
||||||
|
errno = 0;
|
||||||
|
Status = pSocketProtocol->pfnSend ( pSocketProtocol,
|
||||||
|
flags,
|
||||||
|
length,
|
||||||
|
pData,
|
||||||
|
(size_t *)&LengthInBytes,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
&errno );
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
LengthInBytes = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Account for the data sent
|
||||||
|
//
|
||||||
|
pData += LengthInBytes;
|
||||||
|
length -= LengthInBytes;
|
||||||
|
// TODO: Add non-blocking check
|
||||||
|
} while (( 0 != length ) && ( EFI_NOT_READY == Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the number of data bytes sent, -1 for errors
|
||||||
|
//
|
||||||
|
return (INT32)LengthInBytes;
|
||||||
|
}
|
103
StdLib/BsdSocketLib/sendto.c
Normal file
103
StdLib/BsdSocketLib/sendto.c
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the sendto API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send data using a network connection.
|
||||||
|
|
||||||
|
The ::send routine queues data to the network for transmission.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] buffer Address of a buffer containing the data to send.
|
||||||
|
|
||||||
|
@param [in] length Length of the buffer in bytes.
|
||||||
|
|
||||||
|
@param [in] flags Message control flags
|
||||||
|
|
||||||
|
@param [in] to Remote system address
|
||||||
|
|
||||||
|
@param [in] tolen Length of remote system address structure
|
||||||
|
|
||||||
|
@returns ::send returns the number of data bytes that were
|
||||||
|
sent and -1 when an error occurs. In the case of
|
||||||
|
an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
sendto (
|
||||||
|
int s,
|
||||||
|
const void * buffer,
|
||||||
|
size_t length,
|
||||||
|
int flags,
|
||||||
|
const struct sockaddr * to,
|
||||||
|
socklen_t tolen
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ssize_t LengthInBytes;
|
||||||
|
CONST UINT8 * pData;
|
||||||
|
struct __filedes * pDescriptor;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
LengthInBytes = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s,
|
||||||
|
&pDescriptor,
|
||||||
|
&errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Send the data using the socket
|
||||||
|
//
|
||||||
|
pData = buffer;
|
||||||
|
do {
|
||||||
|
errno = 0;
|
||||||
|
Status = pSocketProtocol->pfnSend ( pSocketProtocol,
|
||||||
|
flags,
|
||||||
|
length,
|
||||||
|
pData,
|
||||||
|
(size_t *)&LengthInBytes,
|
||||||
|
to,
|
||||||
|
tolen,
|
||||||
|
&errno );
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
LengthInBytes = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Account for the data sent
|
||||||
|
//
|
||||||
|
pData += LengthInBytes;
|
||||||
|
length -= LengthInBytes;
|
||||||
|
// TODO: Add non-blocking check
|
||||||
|
} while (( 0 != length ) && ( EFI_NOT_READY == Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the number of data bytes sent, -1 for errors
|
||||||
|
//
|
||||||
|
return (INT32)LengthInBytes;
|
||||||
|
}
|
117
StdLib/BsdSocketLib/sethostname.c
Normal file
117
StdLib/BsdSocketLib/sethostname.c
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software must
|
||||||
|
* display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by Intel Corporation and its
|
||||||
|
* contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of Intel Corporation or its contributors may be used to
|
||||||
|
* endorse or promote products derived from this software without specific
|
||||||
|
* prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION 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 INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <Uefi.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Module Name:
|
||||||
|
|
||||||
|
sethostname.c
|
||||||
|
|
||||||
|
Abstract:
|
||||||
|
|
||||||
|
Map FreeBSD sethostname call to EFI Interface
|
||||||
|
|
||||||
|
|
||||||
|
Revision History
|
||||||
|
|
||||||
|
--*/
|
||||||
|
|
||||||
|
int
|
||||||
|
sethostname(
|
||||||
|
const char * name,
|
||||||
|
size_t namelen
|
||||||
|
)
|
||||||
|
/*++
|
||||||
|
|
||||||
|
Routine Description:
|
||||||
|
|
||||||
|
Set the hostname for this system.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
name - Pointer to hostname.
|
||||||
|
namelen - Length of name
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
|
||||||
|
0 on success, -1 if not set
|
||||||
|
|
||||||
|
--*/
|
||||||
|
{
|
||||||
|
int SetStatus;
|
||||||
|
char * pName;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Allocate a new buffer for name since the input value
|
||||||
|
// does not need to be zero terminated
|
||||||
|
//
|
||||||
|
pName = malloc ( namelen + 1 );
|
||||||
|
if ( NULL == pName ) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
SetStatus = -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//
|
||||||
|
// Create a zero terminated string for name
|
||||||
|
//
|
||||||
|
memcpy ( pName, name, namelen );
|
||||||
|
pName [ namelen ] = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set the environment variable
|
||||||
|
//
|
||||||
|
SetStatus = setenv ("HOSTNAME", pName, TRUE);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free the temporary buffer
|
||||||
|
//
|
||||||
|
free ( pName );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the results
|
||||||
|
//
|
||||||
|
return SetStatus;
|
||||||
|
}
|
65
StdLib/BsdSocketLib/setsockopt.c
Normal file
65
StdLib/BsdSocketLib/setsockopt.c
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the setsockopt API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the socket options
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
@param [in] level Option protocol level
|
||||||
|
@param [in] option_name Name of the option
|
||||||
|
@param [in] option_value Buffer containing the option value
|
||||||
|
@param [in] option_len Length of the value in bytes
|
||||||
|
|
||||||
|
@retval Zero (0) upon success
|
||||||
|
@retval Minus one (-1) upon failure, errno set with additional error information
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
setsockopt (
|
||||||
|
IN int s,
|
||||||
|
IN int level,
|
||||||
|
IN int option_name,
|
||||||
|
IN CONST void * option_value,
|
||||||
|
IN socklen_t option_len
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int OptionStatus;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Set the socket option
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnOptionSet ( pSocketProtocol,
|
||||||
|
level,
|
||||||
|
option_name,
|
||||||
|
option_value,
|
||||||
|
option_len,
|
||||||
|
&errno );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation stauts
|
||||||
|
//
|
||||||
|
OptionStatus = ( 0 == errno ) ? 0 : -1;
|
||||||
|
return OptionStatus;
|
||||||
|
}
|
72
StdLib/BsdSocketLib/shutdown.c
Normal file
72
StdLib/BsdSocketLib/shutdown.c
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the shutdown API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the socket receive and transmit operations
|
||||||
|
|
||||||
|
The ::shutdown routine stops socket receive and transmit operations.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] how Which operations to shutdown
|
||||||
|
|
||||||
|
@returns ::shutdown returns the zero (0) if successful or -1 when an
|
||||||
|
error occurs. In the latter case, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
shutdown (
|
||||||
|
int s,
|
||||||
|
int how
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int RetVal;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
RetVal = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the context for this socket
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslFdToSocketProtocol ( s, NULL, &errno );
|
||||||
|
if ( NULL != pSocketProtocol ) {
|
||||||
|
//
|
||||||
|
// Receive the data from the socket
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnShutdown ( pSocketProtocol,
|
||||||
|
how,
|
||||||
|
&errno );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Success
|
||||||
|
//
|
||||||
|
RetVal = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation status
|
||||||
|
//
|
||||||
|
return RetVal;
|
||||||
|
}
|
286
StdLib/BsdSocketLib/socket.c
Normal file
286
StdLib/BsdSocketLib/socket.c
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the socket API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
const struct fileops SocketOperations = {
|
||||||
|
BslSocketClose, // close
|
||||||
|
BslSocketRead, // read
|
||||||
|
BslSocketWrite, // write
|
||||||
|
|
||||||
|
//
|
||||||
|
// Not supported
|
||||||
|
//
|
||||||
|
fnullop_fcntl, // fcntl
|
||||||
|
BslSocketPoll, // poll
|
||||||
|
fnullop_flush, // flush
|
||||||
|
|
||||||
|
fbadop_stat, // stat
|
||||||
|
fbadop_ioctl, // ioctl
|
||||||
|
fbadop_delete, // delete
|
||||||
|
fbadop_rmdir, // rmdir
|
||||||
|
fbadop_mkdir, // mkdir
|
||||||
|
fbadop_rename, // rename
|
||||||
|
|
||||||
|
NULL // lseek
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Translate from the socket file descriptor to the socket protocol.
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] ppDescriptor Address to receive the descriptor structure
|
||||||
|
address for the file
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@returns A pointer to the socket protocol structure or NULL if
|
||||||
|
an invalid file descriptor was passed in.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_SOCKET_PROTOCOL *
|
||||||
|
BslFdToSocketProtocol (
|
||||||
|
int s,
|
||||||
|
struct __filedes ** ppDescriptor,
|
||||||
|
int * pErrno
|
||||||
|
)
|
||||||
|
{
|
||||||
|
struct __filedes * pDescriptor;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
pSocketProtocol = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate the file descriptor
|
||||||
|
//
|
||||||
|
if ( !ValidateFD ( s, TRUE )) {
|
||||||
|
//
|
||||||
|
// Bad file descriptor
|
||||||
|
//
|
||||||
|
*pErrno = EBADF;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//
|
||||||
|
// Get the descriptor for the file
|
||||||
|
//
|
||||||
|
pDescriptor = &gMD->fdarray [ s ];
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate that the descriptor is associated with sockets
|
||||||
|
//
|
||||||
|
pSocketProtocol = BslValidateSocketFd ( pDescriptor, pErrno );
|
||||||
|
if (( NULL != ppDescriptor ) && ( NULL != pSocketProtocol )) {
|
||||||
|
*ppDescriptor = pDescriptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the socket protocol
|
||||||
|
//
|
||||||
|
return pSocketProtocol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Build a file descriptor for a socket.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Socket protocol structure address
|
||||||
|
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@returns The file descriptor for the socket or -1 if an error occurs.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
BslSocketProtocolToFd (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
)
|
||||||
|
{
|
||||||
|
int FileDescriptor;
|
||||||
|
struct __filedes * pDescriptor;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
FileDescriptor = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate a file descriptor
|
||||||
|
//
|
||||||
|
FileDescriptor = FindFreeFD ( VALID_CLOSED );
|
||||||
|
if( FileDescriptor < 0 ) {
|
||||||
|
//
|
||||||
|
// All available FDs are in use
|
||||||
|
//
|
||||||
|
errno = EMFILE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//
|
||||||
|
// Initialize the file descriptor
|
||||||
|
//
|
||||||
|
pDescriptor = &gMD->fdarray [ FileDescriptor ];
|
||||||
|
pDescriptor->f_offset = 0;
|
||||||
|
pDescriptor->f_flag = 0;
|
||||||
|
pDescriptor->f_iflags = DTYPE_SOCKET;
|
||||||
|
pDescriptor->MyFD = (UINT16)FileDescriptor;
|
||||||
|
pDescriptor->Oflags = 0;
|
||||||
|
pDescriptor->Omode = S_ACC_READ | S_ACC_WRITE;
|
||||||
|
pDescriptor->RefCount = 1;
|
||||||
|
FILE_SET_MATURE ( pDescriptor );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Socket specific file descriptor initialization
|
||||||
|
//
|
||||||
|
pDescriptor->devdata = pSocketProtocol;
|
||||||
|
pDescriptor->f_ops = &SocketOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the socket's file descriptor
|
||||||
|
//
|
||||||
|
return FileDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates an endpoint for network communication.
|
||||||
|
|
||||||
|
The ::Socket routine initializes the communication endpoint by providing
|
||||||
|
the support for the socket library function ::socket. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
|
||||||
|
documentation for the socket routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] domain Select the family of protocols for the client or server
|
||||||
|
application.
|
||||||
|
|
||||||
|
@param [in] type Specifies how to make the network connection. The following values
|
||||||
|
are supported:
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
SOCK_STREAM - Connect to TCP, provides a byte stream
|
||||||
|
that is manipluated by read, recv, send and write.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
|
||||||
|
that is manipulated by read, recv, send and write.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
SOCK_DGRAM - Connect to UDP, provides a datagram service that is
|
||||||
|
manipulated by recvfrom and sendto.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
@param [in] protocol Specifies the lower layer protocol to use. The following
|
||||||
|
values are supported:
|
||||||
|
<ul>
|
||||||
|
<li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
|
||||||
|
<li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
@returns This routine returns a file descriptor for the socket.
|
||||||
|
|
||||||
|
**/
|
||||||
|
INT32
|
||||||
|
socket (
|
||||||
|
IN INT32 domain,
|
||||||
|
IN INT32 type,
|
||||||
|
IN INT32 protocol
|
||||||
|
)
|
||||||
|
{
|
||||||
|
INT32 FileDescriptor;
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
FileDescriptor = -1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the socket protocol
|
||||||
|
//
|
||||||
|
errno = EslServiceGetProtocol ( &pSocketProtocol );
|
||||||
|
if ( 0 == errno ) {
|
||||||
|
//
|
||||||
|
// Initialize the socket
|
||||||
|
//
|
||||||
|
Status = pSocketProtocol->pfnSocket ( pSocketProtocol,
|
||||||
|
domain,
|
||||||
|
type,
|
||||||
|
protocol,
|
||||||
|
&errno );
|
||||||
|
if ( !EFI_ERROR ( Status ))
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Build the file descriptor for the socket
|
||||||
|
//
|
||||||
|
FileDescriptor = BslSocketProtocolToFd ( pSocketProtocol,
|
||||||
|
&errno );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the socket's file descriptor
|
||||||
|
//
|
||||||
|
return FileDescriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Validate the socket's file descriptor
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor for the file
|
||||||
|
|
||||||
|
@param [in] pErrno Address of the errno variable
|
||||||
|
|
||||||
|
@returns A pointer to the socket protocol structure or NULL if
|
||||||
|
an invalid file descriptor was passed in.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_SOCKET_PROTOCOL *
|
||||||
|
BslValidateSocketFd (
|
||||||
|
struct __filedes * pDescriptor,
|
||||||
|
int * pErrno
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_SOCKET_PROTOCOL * pSocketProtocol;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume failure
|
||||||
|
//
|
||||||
|
*pErrno = ENOTSOCK;
|
||||||
|
pSocketProtocol = NULL;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Validate that the descriptor is associated with sockets
|
||||||
|
//
|
||||||
|
if ( DTYPE_SOCKET == ( pDescriptor->f_iflags & DTYPE_MASK )) {
|
||||||
|
//
|
||||||
|
// Locate the socket protocol
|
||||||
|
//
|
||||||
|
pSocketProtocol = pDescriptor->devdata;
|
||||||
|
*pErrno = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the socket protocol
|
||||||
|
//
|
||||||
|
return pSocketProtocol;
|
||||||
|
}
|
51
StdLib/BsdSocketLib/write.c
Normal file
51
StdLib/BsdSocketLib/write.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the write API.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <SocketInternals.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Write support routine for sockets
|
||||||
|
|
||||||
|
@param [in] pDescriptor Descriptor address for the file
|
||||||
|
@param [in] pOffset File offset
|
||||||
|
@param [in] LengthInBytes Number of bytes to write
|
||||||
|
@param [in] pBuffer Address of the data
|
||||||
|
|
||||||
|
@returns The number of bytes written or -1 if an error occurs.
|
||||||
|
|
||||||
|
**/
|
||||||
|
ssize_t
|
||||||
|
BslSocketWrite (
|
||||||
|
struct __filedes *pDescriptor,
|
||||||
|
off_t * pOffset,
|
||||||
|
size_t LengthInBytes,
|
||||||
|
const void * pBuffer
|
||||||
|
)
|
||||||
|
{
|
||||||
|
ssize_t BytesWritten;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Send the data using the socket
|
||||||
|
//
|
||||||
|
BytesWritten = send ( pDescriptor->MyFD,
|
||||||
|
pBuffer,
|
||||||
|
LengthInBytes,
|
||||||
|
0 );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the number of bytes written
|
||||||
|
//
|
||||||
|
return BytesWritten;
|
||||||
|
}
|
4
StdLib/Efi/etc/host.conf
Normal file
4
StdLib/Efi/etc/host.conf
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Order to perform name searches
|
||||||
|
dns, nis
|
||||||
|
hosts
|
||||||
|
|
9
StdLib/Efi/etc/hosts
Normal file
9
StdLib/Efi/etc/hosts
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# IPv4 hosts
|
||||||
|
127.0.0.1 localhost
|
||||||
|
|
||||||
|
# IPv6 hosts
|
||||||
|
::1 localhost ip6-localhost ip6-loopback
|
||||||
|
fe00::0 ip6-localnet
|
||||||
|
ff00::0 ip6-mcastprefix
|
||||||
|
ff02::1 ip6-allnodes
|
||||||
|
ff02::2 ip6-allrouters
|
3
StdLib/Efi/etc/networks
Normal file
3
StdLib/Efi/etc/networks
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# symbolic names for networks, see networks(5) for more information
|
||||||
|
link-local 169.254.0.0
|
||||||
|
loopback 127.0.0.1
|
59
StdLib/Efi/etc/protocols
Normal file
59
StdLib/Efi/etc/protocols
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# Internet (IP) protocols
|
||||||
|
#
|
||||||
|
# Updated from http://www.iana.org/assignments/protocol-numbers and other
|
||||||
|
# sources.
|
||||||
|
# New protocols will be added on request if they have been officially
|
||||||
|
# assigned by IANA and are not historical.
|
||||||
|
# If you need a huge list of used numbers please install the nmap package.
|
||||||
|
|
||||||
|
ip 0 IP # internet protocol, pseudo protocol number
|
||||||
|
#hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883]
|
||||||
|
icmp 1 ICMP # internet control message protocol
|
||||||
|
igmp 2 IGMP # Internet Group Management
|
||||||
|
ggp 3 GGP # gateway-gateway protocol
|
||||||
|
ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
|
||||||
|
st 5 ST # ST datagram mode
|
||||||
|
tcp 6 TCP # transmission control protocol
|
||||||
|
egp 8 EGP # exterior gateway protocol
|
||||||
|
igp 9 IGP # any private interior gateway (Cisco)
|
||||||
|
pup 12 PUP # PARC universal packet protocol
|
||||||
|
udp 17 UDP # user datagram protocol
|
||||||
|
hmp 20 HMP # host monitoring protocol
|
||||||
|
xns-idp 22 XNS-IDP # Xerox NS IDP
|
||||||
|
rdp 27 RDP # "reliable datagram" protocol
|
||||||
|
iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4 [RFC905]
|
||||||
|
xtp 36 XTP # Xpress Transfer Protocol
|
||||||
|
ddp 37 DDP # Datagram Delivery Protocol
|
||||||
|
idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport
|
||||||
|
ipv6 41 IPv6 # Internet Protocol, version 6
|
||||||
|
ipv6-route 43 IPv6-Route # Routing Header for IPv6
|
||||||
|
ipv6-frag 44 IPv6-Frag # Fragment Header for IPv6
|
||||||
|
idrp 45 IDRP # Inter-Domain Routing Protocol
|
||||||
|
rsvp 46 RSVP # Reservation Protocol
|
||||||
|
gre 47 GRE # General Routing Encapsulation
|
||||||
|
esp 50 IPSEC-ESP # Encap Security Payload [RFC2406]
|
||||||
|
ah 51 IPSEC-AH # Authentication Header [RFC2402]
|
||||||
|
skip 57 SKIP # SKIP
|
||||||
|
ipv6-icmp 58 IPv6-ICMP # ICMP for IPv6
|
||||||
|
ipv6-nonxt 59 IPv6-NoNxt # No Next Header for IPv6
|
||||||
|
ipv6-opts 60 IPv6-Opts # Destination Options for IPv6
|
||||||
|
rspf 73 RSPF CPHB # Radio Shortest Path First (officially CPHB)
|
||||||
|
vmtp 81 VMTP # Versatile Message Transport
|
||||||
|
eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco)
|
||||||
|
ospf 89 OSPFIGP # Open Shortest Path First IGP
|
||||||
|
ax.25 93 AX.25 # AX.25 frames
|
||||||
|
ipip 94 IPIP # IP-within-IP Encapsulation Protocol
|
||||||
|
etherip 97 ETHERIP # Ethernet-within-IP Encapsulation [RFC3378]
|
||||||
|
encap 98 ENCAP # Yet Another IP encapsulation [RFC1241]
|
||||||
|
# 99 # any private encryption scheme
|
||||||
|
pim 103 PIM # Protocol Independent Multicast
|
||||||
|
ipcomp 108 IPCOMP # IP Payload Compression Protocol
|
||||||
|
vrrp 112 VRRP # Virtual Router Redundancy Protocol
|
||||||
|
l2tp 115 L2TP # Layer Two Tunneling Protocol [RFC2661]
|
||||||
|
isis 124 ISIS # IS-IS over IPv4
|
||||||
|
sctp 132 SCTP # Stream Control Transmission Protocol
|
||||||
|
fc 133 FC # Fibre Channel
|
||||||
|
udplite 136 UDPLite # UDP-Lite
|
||||||
|
mpls-in-ip 137 MPLS-in-IP # MPLS-in-IP [RFC4023]
|
||||||
|
manet 138 # MANET Protocols
|
||||||
|
hip 139 HIP # Host Identity Protocol
|
19
StdLib/Efi/etc/resolv.conf
Normal file
19
StdLib/Efi/etc/resolv.conf
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#
|
||||||
|
# Domain name
|
||||||
|
#
|
||||||
|
domain intel.com
|
||||||
|
|
||||||
|
;
|
||||||
|
; Name Servers
|
||||||
|
;
|
||||||
|
nameserver 206.63.63.61
|
||||||
|
nameserver 216.251.100.1
|
||||||
|
|
||||||
|
; nameserver 10.248.2.1
|
||||||
|
; nameserver 10.22.224.204
|
||||||
|
|
||||||
|
#
|
||||||
|
# Enable debugging
|
||||||
|
#
|
||||||
|
#options debug
|
||||||
|
|
576
StdLib/Efi/etc/services
Normal file
576
StdLib/Efi/etc/services
Normal file
@ -0,0 +1,576 @@
|
|||||||
|
# Network services, Internet style
|
||||||
|
#
|
||||||
|
# Note that it is presently the policy of IANA to assign a single well-known
|
||||||
|
# port number for both TCP and UDP; hence, officially ports have two entries
|
||||||
|
# even if the protocol doesn't support UDP operations.
|
||||||
|
#
|
||||||
|
# Updated from http://www.iana.org/assignments/port-numbers and other
|
||||||
|
# sources like http://www.freebsd.org/cgi/cvsweb.cgi/src/etc/services .
|
||||||
|
# New ports will be added on request if they have been officially assigned
|
||||||
|
# by IANA and used in the real-world or are needed by a debian package.
|
||||||
|
# If you need a huge list of used numbers please install the nmap package.
|
||||||
|
|
||||||
|
tcpmux 1/tcp # TCP port service multiplexer
|
||||||
|
echo 7/tcp
|
||||||
|
echo 7/udp
|
||||||
|
discard 9/tcp sink null
|
||||||
|
discard 9/udp sink null
|
||||||
|
systat 11/tcp users
|
||||||
|
daytime 13/tcp
|
||||||
|
daytime 13/udp
|
||||||
|
netstat 15/tcp
|
||||||
|
qotd 17/tcp quote
|
||||||
|
msp 18/tcp # message send protocol
|
||||||
|
msp 18/udp
|
||||||
|
chargen 19/tcp ttytst source
|
||||||
|
chargen 19/udp ttytst source
|
||||||
|
ftp-data 20/tcp
|
||||||
|
ftp 21/tcp
|
||||||
|
fsp 21/udp fspd
|
||||||
|
ssh 22/tcp # SSH Remote Login Protocol
|
||||||
|
ssh 22/udp
|
||||||
|
telnet 23/tcp
|
||||||
|
smtp 25/tcp mail
|
||||||
|
time 37/tcp timserver
|
||||||
|
time 37/udp timserver
|
||||||
|
rlp 39/udp resource # resource location
|
||||||
|
nameserver 42/tcp name # IEN 116
|
||||||
|
whois 43/tcp nicname
|
||||||
|
tacacs 49/tcp # Login Host Protocol (TACACS)
|
||||||
|
tacacs 49/udp
|
||||||
|
re-mail-ck 50/tcp # Remote Mail Checking Protocol
|
||||||
|
re-mail-ck 50/udp
|
||||||
|
domain 53/tcp # name-domain server
|
||||||
|
domain 53/udp
|
||||||
|
mtp 57/tcp # deprecated
|
||||||
|
tacacs-ds 65/tcp # TACACS-Database Service
|
||||||
|
tacacs-ds 65/udp
|
||||||
|
bootps 67/tcp # BOOTP server
|
||||||
|
bootps 67/udp
|
||||||
|
bootpc 68/tcp # BOOTP client
|
||||||
|
bootpc 68/udp
|
||||||
|
tftp 69/udp
|
||||||
|
gopher 70/tcp # Internet Gopher
|
||||||
|
gopher 70/udp
|
||||||
|
rje 77/tcp netrjs
|
||||||
|
finger 79/tcp
|
||||||
|
www 80/tcp http # WorldWideWeb HTTP
|
||||||
|
www 80/udp # HyperText Transfer Protocol
|
||||||
|
link 87/tcp ttylink
|
||||||
|
kerberos 88/tcp kerberos5 krb5 kerberos-sec # Kerberos v5
|
||||||
|
kerberos 88/udp kerberos5 krb5 kerberos-sec # Kerberos v5
|
||||||
|
supdup 95/tcp
|
||||||
|
hostnames 101/tcp hostname # usually from sri-nic
|
||||||
|
iso-tsap 102/tcp tsap # part of ISODE
|
||||||
|
acr-nema 104/tcp dicom # Digital Imag. & Comm. 300
|
||||||
|
acr-nema 104/udp dicom # Digital Imag. & Comm. 300
|
||||||
|
csnet-ns 105/tcp cso-ns # also used by CSO name server
|
||||||
|
csnet-ns 105/udp cso-ns
|
||||||
|
rtelnet 107/tcp # Remote Telnet
|
||||||
|
rtelnet 107/udp
|
||||||
|
pop2 109/tcp postoffice pop-2 # POP version 2
|
||||||
|
pop2 109/udp pop-2
|
||||||
|
pop3 110/tcp pop-3 # POP version 3
|
||||||
|
pop3 110/udp pop-3
|
||||||
|
sunrpc 111/tcp portmapper # RPC 4.0 portmapper
|
||||||
|
sunrpc 111/udp portmapper
|
||||||
|
auth 113/tcp authentication tap ident
|
||||||
|
sftp 115/tcp
|
||||||
|
uucp-path 117/tcp
|
||||||
|
nntp 119/tcp readnews untp # USENET News Transfer Protocol
|
||||||
|
ntp 123/tcp
|
||||||
|
ntp 123/udp # Network Time Protocol
|
||||||
|
pwdgen 129/tcp # PWDGEN service
|
||||||
|
pwdgen 129/udp # PWDGEN service
|
||||||
|
loc-srv 135/tcp epmap # Location Service
|
||||||
|
loc-srv 135/udp epmap
|
||||||
|
netbios-ns 137/tcp # NETBIOS Name Service
|
||||||
|
netbios-ns 137/udp
|
||||||
|
netbios-dgm 138/tcp # NETBIOS Datagram Service
|
||||||
|
netbios-dgm 138/udp
|
||||||
|
netbios-ssn 139/tcp # NETBIOS session service
|
||||||
|
netbios-ssn 139/udp
|
||||||
|
imap2 143/tcp imap # Interim Mail Access P 2 and 4
|
||||||
|
imap2 143/udp imap
|
||||||
|
snmp 161/tcp # Simple Net Mgmt Protocol
|
||||||
|
snmp 161/udp # Simple Net Mgmt Protocol
|
||||||
|
snmp-trap 162/tcp snmptrap # Traps for SNMP
|
||||||
|
snmp-trap 162/udp snmptrap # Traps for SNMP
|
||||||
|
cmip-man 163/tcp # ISO mgmt over IP (CMOT)
|
||||||
|
cmip-man 163/udp
|
||||||
|
cmip-agent 164/tcp
|
||||||
|
cmip-agent 164/udp
|
||||||
|
mailq 174/tcp # Mailer transport queue for Zmailer
|
||||||
|
mailq 174/udp # Mailer transport queue for Zmailer
|
||||||
|
xdmcp 177/tcp # X Display Mgr. Control Proto
|
||||||
|
xdmcp 177/udp
|
||||||
|
nextstep 178/tcp NeXTStep NextStep # NeXTStep window
|
||||||
|
nextstep 178/udp NeXTStep NextStep # server
|
||||||
|
bgp 179/tcp # Border Gateway Protocol
|
||||||
|
bgp 179/udp
|
||||||
|
prospero 191/tcp # Cliff Neuman's Prospero
|
||||||
|
prospero 191/udp
|
||||||
|
irc 194/tcp # Internet Relay Chat
|
||||||
|
irc 194/udp
|
||||||
|
smux 199/tcp # SNMP Unix Multiplexer
|
||||||
|
smux 199/udp
|
||||||
|
at-rtmp 201/tcp # AppleTalk routing
|
||||||
|
at-rtmp 201/udp
|
||||||
|
at-nbp 202/tcp # AppleTalk name binding
|
||||||
|
at-nbp 202/udp
|
||||||
|
at-echo 204/tcp # AppleTalk echo
|
||||||
|
at-echo 204/udp
|
||||||
|
at-zis 206/tcp # AppleTalk zone information
|
||||||
|
at-zis 206/udp
|
||||||
|
qmtp 209/tcp # Quick Mail Transfer Protocol
|
||||||
|
qmtp 209/udp # Quick Mail Transfer Protocol
|
||||||
|
z3950 210/tcp wais # NISO Z39.50 database
|
||||||
|
z3950 210/udp wais
|
||||||
|
ipx 213/tcp # IPX
|
||||||
|
ipx 213/udp
|
||||||
|
imap3 220/tcp # Interactive Mail Access
|
||||||
|
imap3 220/udp # Protocol v3
|
||||||
|
pawserv 345/tcp # Perf Analysis Workbench
|
||||||
|
pawserv 345/udp
|
||||||
|
zserv 346/tcp # Zebra server
|
||||||
|
zserv 346/udp
|
||||||
|
fatserv 347/tcp # Fatmen Server
|
||||||
|
fatserv 347/udp
|
||||||
|
rpc2portmap 369/tcp
|
||||||
|
rpc2portmap 369/udp # Coda portmapper
|
||||||
|
codaauth2 370/tcp
|
||||||
|
codaauth2 370/udp # Coda authentication server
|
||||||
|
clearcase 371/tcp Clearcase
|
||||||
|
clearcase 371/udp Clearcase
|
||||||
|
ulistserv 372/tcp # UNIX Listserv
|
||||||
|
ulistserv 372/udp
|
||||||
|
ldap 389/tcp # Lightweight Directory Access Protocol
|
||||||
|
ldap 389/udp
|
||||||
|
imsp 406/tcp # Interactive Mail Support Protocol
|
||||||
|
imsp 406/udp
|
||||||
|
https 443/tcp # http protocol over TLS/SSL
|
||||||
|
https 443/udp
|
||||||
|
snpp 444/tcp # Simple Network Paging Protocol
|
||||||
|
snpp 444/udp
|
||||||
|
microsoft-ds 445/tcp # Microsoft Naked CIFS
|
||||||
|
microsoft-ds 445/udp
|
||||||
|
kpasswd 464/tcp
|
||||||
|
kpasswd 464/udp
|
||||||
|
saft 487/tcp # Simple Asynchronous File Transfer
|
||||||
|
saft 487/udp
|
||||||
|
isakmp 500/tcp # IPsec - Internet Security Association
|
||||||
|
isakmp 500/udp # and Key Management Protocol
|
||||||
|
rtsp 554/tcp # Real Time Stream Control Protocol
|
||||||
|
rtsp 554/udp # Real Time Stream Control Protocol
|
||||||
|
nqs 607/tcp # Network Queuing system
|
||||||
|
nqs 607/udp
|
||||||
|
npmp-local 610/tcp dqs313_qmaster # npmp-local / DQS
|
||||||
|
npmp-local 610/udp dqs313_qmaster
|
||||||
|
npmp-gui 611/tcp dqs313_execd # npmp-gui / DQS
|
||||||
|
npmp-gui 611/udp dqs313_execd
|
||||||
|
hmmp-ind 612/tcp dqs313_intercell # HMMP Indication / DQS
|
||||||
|
hmmp-ind 612/udp dqs313_intercell
|
||||||
|
qmqp 628/tcp
|
||||||
|
qmqp 628/udp
|
||||||
|
ipp 631/tcp # Internet Printing Protocol
|
||||||
|
ipp 631/udp
|
||||||
|
#
|
||||||
|
# UNIX specific services
|
||||||
|
#
|
||||||
|
exec 512/tcp
|
||||||
|
biff 512/udp comsat
|
||||||
|
login 513/tcp
|
||||||
|
who 513/udp whod
|
||||||
|
shell 514/tcp cmd # no passwords used
|
||||||
|
syslog 514/udp
|
||||||
|
printer 515/tcp spooler # line printer spooler
|
||||||
|
talk 517/udp
|
||||||
|
ntalk 518/udp
|
||||||
|
route 520/udp router routed # RIP
|
||||||
|
timed 525/udp timeserver
|
||||||
|
tempo 526/tcp newdate
|
||||||
|
courier 530/tcp rpc
|
||||||
|
conference 531/tcp chat
|
||||||
|
netnews 532/tcp readnews
|
||||||
|
netwall 533/udp # for emergency broadcasts
|
||||||
|
gdomap 538/tcp # GNUstep distributed objects
|
||||||
|
gdomap 538/udp
|
||||||
|
uucp 540/tcp uucpd # uucp daemon
|
||||||
|
klogin 543/tcp # Kerberized `rlogin' (v5)
|
||||||
|
kshell 544/tcp krcmd # Kerberized `rsh' (v5)
|
||||||
|
afpovertcp 548/tcp # AFP over TCP
|
||||||
|
afpovertcp 548/udp
|
||||||
|
remotefs 556/tcp rfs_server rfs # Brunhoff remote filesystem
|
||||||
|
nntps 563/tcp snntp # NNTP over SSL
|
||||||
|
nntps 563/udp snntp
|
||||||
|
submission 587/tcp # Submission [RFC4409]
|
||||||
|
submission 587/udp
|
||||||
|
ldaps 636/tcp # LDAP over SSL
|
||||||
|
ldaps 636/udp
|
||||||
|
tinc 655/tcp # tinc control port
|
||||||
|
tinc 655/udp
|
||||||
|
silc 706/tcp
|
||||||
|
silc 706/udp
|
||||||
|
kerberos-adm 749/tcp # Kerberos `kadmin' (v5)
|
||||||
|
#
|
||||||
|
webster 765/tcp # Network dictionary
|
||||||
|
webster 765/udp
|
||||||
|
rsync 873/tcp
|
||||||
|
rsync 873/udp
|
||||||
|
ftps-data 989/tcp # FTP over SSL (data)
|
||||||
|
ftps 990/tcp
|
||||||
|
telnets 992/tcp # Telnet over SSL
|
||||||
|
telnets 992/udp
|
||||||
|
imaps 993/tcp # IMAP over SSL
|
||||||
|
imaps 993/udp
|
||||||
|
ircs 994/tcp # IRC over SSL
|
||||||
|
ircs 994/udp
|
||||||
|
pop3s 995/tcp # POP-3 over SSL
|
||||||
|
pop3s 995/udp
|
||||||
|
#
|
||||||
|
# From ``Assigned Numbers'':
|
||||||
|
#
|
||||||
|
#> The Registered Ports are not controlled by the IANA and on most systems
|
||||||
|
#> can be used by ordinary user processes or programs executed by ordinary
|
||||||
|
#> users.
|
||||||
|
#
|
||||||
|
#> Ports are used in the TCP [45,106] to name the ends of logical
|
||||||
|
#> connections which carry long term conversations. For the purpose of
|
||||||
|
#> providing services to unknown callers, a service contact port is
|
||||||
|
#> defined. This list specifies the port used by the server process as its
|
||||||
|
#> contact port. While the IANA can not control uses of these ports it
|
||||||
|
#> does register or list uses of these ports as a convienence to the
|
||||||
|
#> community.
|
||||||
|
#
|
||||||
|
socks 1080/tcp # socks proxy server
|
||||||
|
socks 1080/udp
|
||||||
|
proofd 1093/tcp
|
||||||
|
proofd 1093/udp
|
||||||
|
rootd 1094/tcp
|
||||||
|
rootd 1094/udp
|
||||||
|
openvpn 1194/tcp
|
||||||
|
openvpn 1194/udp
|
||||||
|
rmiregistry 1099/tcp # Java RMI Registry
|
||||||
|
rmiregistry 1099/udp
|
||||||
|
kazaa 1214/tcp
|
||||||
|
kazaa 1214/udp
|
||||||
|
nessus 1241/tcp # Nessus vulnerability
|
||||||
|
nessus 1241/udp # assessment scanner
|
||||||
|
lotusnote 1352/tcp lotusnotes # Lotus Note
|
||||||
|
lotusnote 1352/udp lotusnotes
|
||||||
|
ms-sql-s 1433/tcp # Microsoft SQL Server
|
||||||
|
ms-sql-s 1433/udp
|
||||||
|
ms-sql-m 1434/tcp # Microsoft SQL Monitor
|
||||||
|
ms-sql-m 1434/udp
|
||||||
|
ingreslock 1524/tcp
|
||||||
|
ingreslock 1524/udp
|
||||||
|
prospero-np 1525/tcp # Prospero non-privileged
|
||||||
|
prospero-np 1525/udp
|
||||||
|
datametrics 1645/tcp old-radius
|
||||||
|
datametrics 1645/udp old-radius
|
||||||
|
sa-msg-port 1646/tcp old-radacct
|
||||||
|
sa-msg-port 1646/udp old-radacct
|
||||||
|
kermit 1649/tcp
|
||||||
|
kermit 1649/udp
|
||||||
|
l2f 1701/tcp l2tp
|
||||||
|
l2f 1701/udp l2tp
|
||||||
|
radius 1812/tcp
|
||||||
|
radius 1812/udp
|
||||||
|
radius-acct 1813/tcp radacct # Radius Accounting
|
||||||
|
radius-acct 1813/udp radacct
|
||||||
|
msnp 1863/tcp # MSN Messenger
|
||||||
|
msnp 1863/udp
|
||||||
|
unix-status 1957/tcp # remstats unix-status server
|
||||||
|
log-server 1958/tcp # remstats log server
|
||||||
|
remoteping 1959/tcp # remstats remoteping server
|
||||||
|
cisco-sccp 2000/tcp sieve # Cisco SCCP
|
||||||
|
cisco-sccp 2000/udp
|
||||||
|
search 2010/tcp ndtp
|
||||||
|
pipe_server 2010/tcp
|
||||||
|
nfs 2049/tcp # Network File System
|
||||||
|
nfs 2049/udp # Network File System
|
||||||
|
gnunet 2086/tcp
|
||||||
|
gnunet 2086/udp
|
||||||
|
rtcm-sc104 2101/tcp # RTCM SC-104 IANA 1/29/99
|
||||||
|
rtcm-sc104 2101/udp
|
||||||
|
gsigatekeeper 2119/tcp
|
||||||
|
gsigatekeeper 2119/udp
|
||||||
|
gris 2135/tcp # Grid Resource Information Server
|
||||||
|
gris 2135/udp # Grid Resource Information Server
|
||||||
|
cvspserver 2401/tcp # CVS client/server operations
|
||||||
|
cvspserver 2401/udp
|
||||||
|
venus 2430/tcp # codacon port
|
||||||
|
venus 2430/udp # Venus callback/wbc interface
|
||||||
|
venus-se 2431/tcp # tcp side effects
|
||||||
|
venus-se 2431/udp # udp sftp side effect
|
||||||
|
codasrv 2432/tcp # not used
|
||||||
|
codasrv 2432/udp # server port
|
||||||
|
codasrv-se 2433/tcp # tcp side effects
|
||||||
|
codasrv-se 2433/udp # udp sftp side effect
|
||||||
|
mon 2583/tcp # MON traps
|
||||||
|
mon 2583/udp
|
||||||
|
dict 2628/tcp # Dictionary server
|
||||||
|
dict 2628/udp
|
||||||
|
gsiftp 2811/tcp
|
||||||
|
gsiftp 2811/udp
|
||||||
|
gpsd 2947/tcp
|
||||||
|
gpsd 2947/udp
|
||||||
|
gds_db 3050/tcp # InterBase server
|
||||||
|
gds_db 3050/udp
|
||||||
|
icpv2 3130/tcp icp # Internet Cache Protocol
|
||||||
|
icpv2 3130/udp icp
|
||||||
|
mysql 3306/tcp
|
||||||
|
mysql 3306/udp
|
||||||
|
nut 3493/tcp # Network UPS Tools
|
||||||
|
nut 3493/udp
|
||||||
|
distcc 3632/tcp # distributed compiler
|
||||||
|
distcc 3632/udp
|
||||||
|
daap 3689/tcp # Digital Audio Access Protocol
|
||||||
|
daap 3689/udp
|
||||||
|
svn 3690/tcp subversion # Subversion protocol
|
||||||
|
svn 3690/udp subversion
|
||||||
|
suucp 4031/tcp # UUCP over SSL
|
||||||
|
suucp 4031/udp # UUCP over SSL
|
||||||
|
sysrqd 4094/tcp # sysrq daemon
|
||||||
|
sysrqd 4094/udp # sysrq daemon
|
||||||
|
remctl 4373/tcp # Remote Authenticated Command Service
|
||||||
|
remctl 4373/udp # Remote Authenticated Command Service
|
||||||
|
iax 4569/tcp # Inter-Asterisk eXchange
|
||||||
|
iax 4569/udp
|
||||||
|
radmin-port 4899/tcp # RAdmin Port
|
||||||
|
radmin-port 4899/udp
|
||||||
|
rfe 5002/udp # Radio Free Ethernet
|
||||||
|
rfe 5002/tcp
|
||||||
|
mmcc 5050/tcp # multimedia conference control tool (Yahoo IM)
|
||||||
|
mmcc 5050/udp
|
||||||
|
sip 5060/tcp # Session Initiation Protocol
|
||||||
|
sip 5060/udp
|
||||||
|
sip-tls 5061/tcp
|
||||||
|
sip-tls 5061/udp
|
||||||
|
aol 5190/tcp # AIM
|
||||||
|
aol 5190/udp
|
||||||
|
xmpp-client 5222/tcp jabber-client # Jabber Client Connection
|
||||||
|
xmpp-client 5222/udp jabber-client
|
||||||
|
xmpp-server 5269/tcp jabber-server # Jabber Server Connection
|
||||||
|
xmpp-server 5269/udp jabber-server
|
||||||
|
cfengine 5308/tcp
|
||||||
|
cfengine 5308/udp
|
||||||
|
mdns 5353/tcp # Multicast DNS
|
||||||
|
mdns 5353/udp # Multicast DNS
|
||||||
|
postgresql 5432/tcp postgres # PostgreSQL Database
|
||||||
|
postgresql 5432/udp postgres
|
||||||
|
freeciv 5556/tcp rptp # Freeciv gameplay
|
||||||
|
freeciv 5556/udp
|
||||||
|
amqp 5672/tcp
|
||||||
|
amqp 5672/udp
|
||||||
|
amqp 5672/sctp
|
||||||
|
ggz 5688/tcp # GGZ Gaming Zone
|
||||||
|
ggz 5688/udp # GGZ Gaming Zone
|
||||||
|
x11 6000/tcp x11-0 # X Window System
|
||||||
|
x11 6000/udp x11-0
|
||||||
|
x11-1 6001/tcp
|
||||||
|
x11-1 6001/udp
|
||||||
|
x11-2 6002/tcp
|
||||||
|
x11-2 6002/udp
|
||||||
|
x11-3 6003/tcp
|
||||||
|
x11-3 6003/udp
|
||||||
|
x11-4 6004/tcp
|
||||||
|
x11-4 6004/udp
|
||||||
|
x11-5 6005/tcp
|
||||||
|
x11-5 6005/udp
|
||||||
|
x11-6 6006/tcp
|
||||||
|
x11-6 6006/udp
|
||||||
|
x11-7 6007/tcp
|
||||||
|
x11-7 6007/udp
|
||||||
|
gnutella-svc 6346/tcp # gnutella
|
||||||
|
gnutella-svc 6346/udp
|
||||||
|
gnutella-rtr 6347/tcp # gnutella
|
||||||
|
gnutella-rtr 6347/udp
|
||||||
|
sge_qmaster 6444/tcp # Grid Engine Qmaster Service
|
||||||
|
sge_qmaster 6444/udp # Grid Engine Qmaster Service
|
||||||
|
sge_execd 6445/tcp # Grid Engine Execution Service
|
||||||
|
sge_execd 6445/udp # Grid Engine Execution Service
|
||||||
|
afs3-fileserver 7000/tcp bbs # file server itself
|
||||||
|
afs3-fileserver 7000/udp bbs
|
||||||
|
afs3-callback 7001/tcp # callbacks to cache managers
|
||||||
|
afs3-callback 7001/udp
|
||||||
|
afs3-prserver 7002/tcp # users & groups database
|
||||||
|
afs3-prserver 7002/udp
|
||||||
|
afs3-vlserver 7003/tcp # volume location database
|
||||||
|
afs3-vlserver 7003/udp
|
||||||
|
afs3-kaserver 7004/tcp # AFS/Kerberos authentication
|
||||||
|
afs3-kaserver 7004/udp
|
||||||
|
afs3-volser 7005/tcp # volume managment server
|
||||||
|
afs3-volser 7005/udp
|
||||||
|
afs3-errors 7006/tcp # error interpretation service
|
||||||
|
afs3-errors 7006/udp
|
||||||
|
afs3-bos 7007/tcp # basic overseer process
|
||||||
|
afs3-bos 7007/udp
|
||||||
|
afs3-update 7008/tcp # server-to-server updater
|
||||||
|
afs3-update 7008/udp
|
||||||
|
afs3-rmtsys 7009/tcp # remote cache manager service
|
||||||
|
afs3-rmtsys 7009/udp
|
||||||
|
font-service 7100/tcp xfs # X Font Service
|
||||||
|
font-service 7100/udp xfs
|
||||||
|
http-alt 8080/tcp webcache # WWW caching service
|
||||||
|
http-alt 8080/udp # WWW caching service
|
||||||
|
bacula-dir 9101/tcp # Bacula Director
|
||||||
|
bacula-dir 9101/udp
|
||||||
|
bacula-fd 9102/tcp # Bacula File Daemon
|
||||||
|
bacula-fd 9102/udp
|
||||||
|
bacula-sd 9103/tcp # Bacula Storage Daemon
|
||||||
|
bacula-sd 9103/udp
|
||||||
|
xmms2 9667/tcp # Cross-platform Music Multiplexing System
|
||||||
|
xmms2 9667/udp # Cross-platform Music Multiplexing System
|
||||||
|
amanda 10080/tcp # amanda backup services
|
||||||
|
amanda 10080/udp
|
||||||
|
hkp 11371/tcp # OpenPGP HTTP Keyserver
|
||||||
|
hkp 11371/udp # OpenPGP HTTP Keyserver
|
||||||
|
bprd 13720/tcp # VERITAS NetBackup
|
||||||
|
bprd 13720/udp
|
||||||
|
bpdbm 13721/tcp # VERITAS NetBackup
|
||||||
|
bpdbm 13721/udp
|
||||||
|
bpjava-msvc 13722/tcp # BP Java MSVC Protocol
|
||||||
|
bpjava-msvc 13722/udp
|
||||||
|
vnetd 13724/tcp # Veritas Network Utility
|
||||||
|
vnetd 13724/udp
|
||||||
|
bpcd 13782/tcp # VERITAS NetBackup
|
||||||
|
bpcd 13782/udp
|
||||||
|
vopied 13783/tcp # VERITAS NetBackup
|
||||||
|
vopied 13783/udp
|
||||||
|
wnn6 22273/tcp # wnn6
|
||||||
|
wnn6 22273/udp
|
||||||
|
|
||||||
|
#
|
||||||
|
# Datagram Delivery Protocol services
|
||||||
|
#
|
||||||
|
rtmp 1/ddp # Routing Table Maintenance Protocol
|
||||||
|
nbp 2/ddp # Name Binding Protocol
|
||||||
|
echo 4/ddp # AppleTalk Echo Protocol
|
||||||
|
zip 6/ddp # Zone Information Protocol
|
||||||
|
|
||||||
|
#=========================================================================
|
||||||
|
# The remaining port numbers are not as allocated by IANA.
|
||||||
|
#=========================================================================
|
||||||
|
|
||||||
|
# Kerberos (Project Athena/MIT) services
|
||||||
|
# Note that these are for Kerberos v4, and are unofficial. Sites running
|
||||||
|
# v4 should uncomment these and comment out the v5 entries above.
|
||||||
|
#
|
||||||
|
kerberos4 750/udp kerberos-iv kdc # Kerberos (server)
|
||||||
|
kerberos4 750/tcp kerberos-iv kdc
|
||||||
|
kerberos_master 751/udp # Kerberos authentication
|
||||||
|
kerberos_master 751/tcp
|
||||||
|
passwd_server 752/udp # Kerberos passwd server
|
||||||
|
krb_prop 754/tcp krb5_prop hprop # Kerberos slave propagation
|
||||||
|
krbupdate 760/tcp kreg # Kerberos registration
|
||||||
|
swat 901/tcp # swat
|
||||||
|
kpop 1109/tcp # Pop with Kerberos
|
||||||
|
knetd 2053/tcp # Kerberos de-multiplexor
|
||||||
|
zephyr-srv 2102/udp # Zephyr server
|
||||||
|
zephyr-clt 2103/udp # Zephyr serv-hm connection
|
||||||
|
zephyr-hm 2104/udp # Zephyr hostmanager
|
||||||
|
eklogin 2105/tcp # Kerberos encrypted rlogin
|
||||||
|
# Hmmm. Are we using Kv4 or Kv5 now? Worrying.
|
||||||
|
# The following is probably Kerberos v5 --- ajt@debian.org (11/02/2000)
|
||||||
|
kx 2111/tcp # X over Kerberos
|
||||||
|
iprop 2121/tcp # incremental propagation
|
||||||
|
#
|
||||||
|
# Unofficial but necessary (for NetBSD) services
|
||||||
|
#
|
||||||
|
supfilesrv 871/tcp # SUP server
|
||||||
|
supfiledbg 1127/tcp # SUP debugging
|
||||||
|
|
||||||
|
#
|
||||||
|
# Services added for the Debian GNU/Linux distribution
|
||||||
|
#
|
||||||
|
linuxconf 98/tcp # LinuxConf
|
||||||
|
poppassd 106/tcp # Eudora
|
||||||
|
poppassd 106/udp
|
||||||
|
ssmtp 465/tcp smtps # SMTP over SSL
|
||||||
|
moira_db 775/tcp # Moira database
|
||||||
|
moira_update 777/tcp # Moira update protocol
|
||||||
|
moira_ureg 779/udp # Moira user registration
|
||||||
|
spamd 783/tcp # spamassassin daemon
|
||||||
|
omirr 808/tcp omirrd # online mirror
|
||||||
|
omirr 808/udp omirrd
|
||||||
|
customs 1001/tcp # pmake customs server
|
||||||
|
customs 1001/udp
|
||||||
|
skkserv 1178/tcp # skk jisho server port
|
||||||
|
predict 1210/udp # predict -- satellite tracking
|
||||||
|
rmtcfg 1236/tcp # Gracilis Packeten remote config server
|
||||||
|
wipld 1300/tcp # Wipl network monitor
|
||||||
|
xtel 1313/tcp # french minitel
|
||||||
|
xtelw 1314/tcp # french minitel
|
||||||
|
support 1529/tcp # GNATS
|
||||||
|
cfinger 2003/tcp # GNU Finger
|
||||||
|
frox 2121/tcp # frox: caching ftp proxy
|
||||||
|
ninstall 2150/tcp # ninstall service
|
||||||
|
ninstall 2150/udp
|
||||||
|
zebrasrv 2600/tcp # zebra service
|
||||||
|
zebra 2601/tcp # zebra vty
|
||||||
|
ripd 2602/tcp # ripd vty (zebra)
|
||||||
|
ripngd 2603/tcp # ripngd vty (zebra)
|
||||||
|
ospfd 2604/tcp # ospfd vty (zebra)
|
||||||
|
bgpd 2605/tcp # bgpd vty (zebra)
|
||||||
|
ospf6d 2606/tcp # ospf6d vty (zebra)
|
||||||
|
ospfapi 2607/tcp # OSPF-API
|
||||||
|
isisd 2608/tcp # ISISd vty (zebra)
|
||||||
|
afbackup 2988/tcp # Afbackup system
|
||||||
|
afbackup 2988/udp
|
||||||
|
afmbackup 2989/tcp # Afmbackup system
|
||||||
|
afmbackup 2989/udp
|
||||||
|
xtell 4224/tcp # xtell server
|
||||||
|
fax 4557/tcp # FAX transmission service (old)
|
||||||
|
hylafax 4559/tcp # HylaFAX client-server protocol (new)
|
||||||
|
distmp3 4600/tcp # distmp3host daemon
|
||||||
|
munin 4949/tcp lrrd # Munin
|
||||||
|
enbd-cstatd 5051/tcp # ENBD client statd
|
||||||
|
enbd-sstatd 5052/tcp # ENBD server statd
|
||||||
|
pcrd 5151/tcp # PCR-1000 Daemon
|
||||||
|
noclog 5354/tcp # noclogd with TCP (nocol)
|
||||||
|
noclog 5354/udp # noclogd with UDP (nocol)
|
||||||
|
hostmon 5355/tcp # hostmon uses TCP (nocol)
|
||||||
|
hostmon 5355/udp # hostmon uses UDP (nocol)
|
||||||
|
rplay 5555/udp # RPlay audio service
|
||||||
|
nsca 5667/tcp # Nagios Agent - NSCA
|
||||||
|
mrtd 5674/tcp # MRT Routing Daemon
|
||||||
|
bgpsim 5675/tcp # MRT Routing Simulator
|
||||||
|
canna 5680/tcp # cannaserver
|
||||||
|
sane-port 6566/tcp sane saned # SANE network scanner daemon
|
||||||
|
ircd 6667/tcp # Internet Relay Chat
|
||||||
|
zope-ftp 8021/tcp # zope management by ftp
|
||||||
|
tproxy 8081/tcp # Transparent Proxy
|
||||||
|
omniorb 8088/tcp # OmniORB
|
||||||
|
omniorb 8088/udp
|
||||||
|
clc-build-daemon 8990/tcp # Common lisp build daemon
|
||||||
|
xinetd 9098/tcp
|
||||||
|
mandelspawn 9359/udp mandelbrot # network mandelbrot
|
||||||
|
git 9418/tcp # Git Version Control System
|
||||||
|
zope 9673/tcp # zope server
|
||||||
|
webmin 10000/tcp
|
||||||
|
kamanda 10081/tcp # amanda backup services (Kerberos)
|
||||||
|
kamanda 10081/udp
|
||||||
|
amandaidx 10082/tcp # amanda backup services
|
||||||
|
amidxtape 10083/tcp # amanda backup services
|
||||||
|
smsqp 11201/tcp # Alamin SMS gateway
|
||||||
|
smsqp 11201/udp
|
||||||
|
xpilot 15345/tcp # XPilot Contact Port
|
||||||
|
xpilot 15345/udp
|
||||||
|
sgi-cmsd 17001/udp # Cluster membership services daemon
|
||||||
|
sgi-crsd 17002/udp
|
||||||
|
sgi-gcd 17003/udp # SGI Group membership daemon
|
||||||
|
sgi-cad 17004/tcp # Cluster Admin daemon
|
||||||
|
isdnlog 20011/tcp # isdn logging system
|
||||||
|
isdnlog 20011/udp
|
||||||
|
vboxd 20012/tcp # voice box system
|
||||||
|
vboxd 20012/udp
|
||||||
|
binkp 24554/tcp # binkp fidonet protocol
|
||||||
|
asp 27374/tcp # Address Search Protocol
|
||||||
|
asp 27374/udp
|
||||||
|
csync2 30865/tcp # cluster synchronization tool
|
||||||
|
dircproxy 57000/tcp # Detachable IRC Proxy
|
||||||
|
tfido 60177/tcp # fidonet EMSI over telnet
|
||||||
|
fido 60179/tcp # fidonet EMSI over TCP
|
||||||
|
|
||||||
|
# Local services
|
56
StdLib/EfiSocketLib/EfiSocketLib.inf
Normal file
56
StdLib/EfiSocketLib/EfiSocketLib.inf
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#/** @file
|
||||||
|
# Component description file for the EFI socket library.
|
||||||
|
#
|
||||||
|
# This module implements the socket layer.
|
||||||
|
# Copyright (c) 2011, Intel Corporation
|
||||||
|
#
|
||||||
|
# All rights reserved. This program and the accompanying materials
|
||||||
|
# are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
# which accompanies this distribution. The full text of the license may be found at
|
||||||
|
# http://opensource.org/licenses/bsd-license.php
|
||||||
|
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
#
|
||||||
|
#**/
|
||||||
|
|
||||||
|
[Defines]
|
||||||
|
INF_VERSION = 0x00010005
|
||||||
|
BASE_NAME = EfiSocketLib
|
||||||
|
FILE_GUID = C33E0B7C-9D0F-41df-BDFD-08F5E4C39EE8
|
||||||
|
MODULE_TYPE = BASE
|
||||||
|
VERSION_STRING = 1.0
|
||||||
|
LIBRARY_CLASS = EfiSocketLib
|
||||||
|
CONSTRUCTOR = EslConstructor
|
||||||
|
DESTRUCTOR = EslDestructor
|
||||||
|
|
||||||
|
#
|
||||||
|
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
|
||||||
|
#
|
||||||
|
|
||||||
|
[Sources.common]
|
||||||
|
Init.c
|
||||||
|
Service.c
|
||||||
|
Socket.c
|
||||||
|
Tcp4.c
|
||||||
|
Udp4.c
|
||||||
|
UseEfiSocketLib.c
|
||||||
|
|
||||||
|
[Packages]
|
||||||
|
MdePkg/MdePkg.dec
|
||||||
|
MdeModulePkg/MdeModulePkg.dec
|
||||||
|
StdLib/StdLib.dec
|
||||||
|
# SocketPkg/SocketPkg.dec
|
||||||
|
|
||||||
|
[LibraryClasses]
|
||||||
|
BaseMemoryLib
|
||||||
|
DebugLib
|
||||||
|
UefiBootServicesTableLib
|
||||||
|
UefiLib
|
||||||
|
|
||||||
|
[Protocols]
|
||||||
|
gEfiTcp4ProtocolGuid
|
||||||
|
gEfiTcp4ServiceBindingProtocolGuid
|
||||||
|
gEfiUdp4ProtocolGuid
|
||||||
|
gEfiUdp4ServiceBindingProtocolGuid
|
||||||
|
gEfiSocketProtocolGuid
|
||||||
|
gEfiSocketServiceBindingProtocolGuid
|
87
StdLib/EfiSocketLib/Init.c
Normal file
87
StdLib/EfiSocketLib/Init.c
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the constructor and destructor for the EFI socket library
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
EFI Socket Library Constructor
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The initialization was successful
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslConstructor (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume success
|
||||||
|
//
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call the image dependent constructor if available
|
||||||
|
//
|
||||||
|
if ( NULL != mpfnEslConstructor ) {
|
||||||
|
Status = mpfnEslConstructor ( );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the constructor status
|
||||||
|
//
|
||||||
|
DBG_EXIT_STATUS ( Status );
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
EFI Socket Library Destructor
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The shutdown was successful
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslDestructor (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume success
|
||||||
|
//
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Call the image dependent destructor if available
|
||||||
|
//
|
||||||
|
if ( NULL != mpfnEslDestructor ) {
|
||||||
|
Status = mpfnEslDestructor ( );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the constructor status
|
||||||
|
//
|
||||||
|
DBG_EXIT_STATUS ( Status );
|
||||||
|
return Status;
|
||||||
|
}
|
529
StdLib/EfiSocketLib/Service.c
Normal file
529
StdLib/EfiSocketLib/Service.c
Normal file
@ -0,0 +1,529 @@
|
|||||||
|
/** @file
|
||||||
|
Connect to and disconnect from the various network layers
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include "Socket.h"
|
||||||
|
|
||||||
|
EFI_TCP4_PROTOCOL * mpEfiTcpClose4 [ 1024 ];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to the network service bindings
|
||||||
|
|
||||||
|
Walk the network service protocols on the controller handle and
|
||||||
|
locate any that are not in use. Create service structures to
|
||||||
|
manage the service binding for the socket driver.
|
||||||
|
|
||||||
|
@param [in] BindingHandle Handle for protocol binding.
|
||||||
|
@param [in] Controller Handle of device to work with.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS This driver is added to Controller.
|
||||||
|
@retval other This driver does not support this device.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceConnect (
|
||||||
|
IN EFI_HANDLE BindingHandle,
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
{
|
||||||
|
BOOLEAN bInUse;
|
||||||
|
UINTN LengthInBytes;
|
||||||
|
CONST DT_SOCKET_BINDING * pEnd;
|
||||||
|
VOID * pJunk;
|
||||||
|
VOID * pInterface;
|
||||||
|
DT_SERVICE * pService;
|
||||||
|
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_TPL TplPrevious;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume the list is empty
|
||||||
|
//
|
||||||
|
Status = EFI_UNSUPPORTED;
|
||||||
|
bInUse = FALSE;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Walk the list of network connection points
|
||||||
|
//
|
||||||
|
pSocketBinding = &cEslSocketBinding[0];
|
||||||
|
pEnd = &pSocketBinding[ cEslSocketBindingEntries ];
|
||||||
|
while ( pEnd > pSocketBinding ) {
|
||||||
|
//
|
||||||
|
// Determine if the controller supports the network protocol
|
||||||
|
//
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
pSocketBinding->pNetworkBinding,
|
||||||
|
&pInterface,
|
||||||
|
BindingHandle,
|
||||||
|
Controller,
|
||||||
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Determine if the socket layer is already connected
|
||||||
|
//
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
(EFI_GUID *)pSocketBinding->pTagGuid,
|
||||||
|
&pJunk,
|
||||||
|
BindingHandle,
|
||||||
|
Controller,
|
||||||
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
|
);
|
||||||
|
if ( EFI_UNSUPPORTED == Status ) {
|
||||||
|
//
|
||||||
|
// Allocate a service structure since the tag is not present
|
||||||
|
//
|
||||||
|
LengthInBytes = sizeof ( *pService );
|
||||||
|
Status = gBS->AllocatePool (
|
||||||
|
EfiRuntimeServicesData,
|
||||||
|
LengthInBytes,
|
||||||
|
(VOID **) &pService
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"0x%08x: Allocate pService, %d bytes\r\n",
|
||||||
|
pService,
|
||||||
|
LengthInBytes ));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set the structure signature and service binding
|
||||||
|
//
|
||||||
|
ZeroMem ( pService, LengthInBytes );
|
||||||
|
pService->Signature = SERVICE_SIGNATURE;
|
||||||
|
pService->pSocketBinding = pSocketBinding;
|
||||||
|
pService->Controller = Controller;
|
||||||
|
pService->pInterface = pInterface;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Mark the controller in use
|
||||||
|
//
|
||||||
|
if ( !bInUse ) {
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
|
&Controller,
|
||||||
|
&gEfiCallerIdGuid,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||||
|
"Installed: gEfiCallerIdGuid on 0x%08x\r\n",
|
||||||
|
Controller ));
|
||||||
|
bInUse = TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ( EFI_INVALID_PARAMETER == Status ) {
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// Mark the network service protocol in use
|
||||||
|
//
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
|
&Controller,
|
||||||
|
pSocketBinding->pTagGuid,
|
||||||
|
pService,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||||
|
"Installed: %s TagGuid on 0x%08x\r\n",
|
||||||
|
pSocketBinding->pName,
|
||||||
|
Controller ));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Synchronize with the socket layer
|
||||||
|
//
|
||||||
|
RAISE_TPL ( TplPrevious, TPL_SOCKETS );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize the service
|
||||||
|
//
|
||||||
|
Status = pSocketBinding->pfnInitialize ( pService );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release the socket layer synchronization
|
||||||
|
//
|
||||||
|
RESTORE_TPL ( TplPrevious );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Determine if the initialization was successful
|
||||||
|
//
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"ERROR - Failed to initialize service %s on 0x%08x, Status: %r\r\n",
|
||||||
|
pSocketBinding->pName,
|
||||||
|
Controller,
|
||||||
|
Status ));
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free the network service binding if necessary
|
||||||
|
//
|
||||||
|
gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
Controller,
|
||||||
|
pSocketBinding->pTagGuid,
|
||||||
|
pService,
|
||||||
|
NULL );
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||||
|
"Removed: %s TagGuid from 0x%08x\r\n",
|
||||||
|
pSocketBinding->pName,
|
||||||
|
Controller ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"ERROR - Failed to install %s TagGuid on 0x%08x, Status: %r\r\n",
|
||||||
|
pSocketBinding->pName,
|
||||||
|
Controller,
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
//
|
||||||
|
// The controller is no longer in use
|
||||||
|
//
|
||||||
|
if ( bInUse ) {
|
||||||
|
gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
Controller,
|
||||||
|
&gEfiCallerIdGuid,
|
||||||
|
NULL,
|
||||||
|
NULL );
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||||
|
"Removed: gEfiCallerIdGuid from 0x%08x\r\n",
|
||||||
|
Controller ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_INIT,
|
||||||
|
"ERROR - Failed to install gEfiCallerIdGuid on 0x%08x, Status: %r\r\n",
|
||||||
|
Controller,
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release the service if necessary
|
||||||
|
//
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
gBS->FreePool ( pService );
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"0x%08x: Free pService, %d bytes\r\n",
|
||||||
|
pService,
|
||||||
|
sizeof ( *pService )));
|
||||||
|
pService = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_INIT,
|
||||||
|
"ERROR - Failed service allocation, Status: %r\r\n",
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set the next network protocol
|
||||||
|
//
|
||||||
|
pSocketBinding += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Display the driver start status
|
||||||
|
//
|
||||||
|
DBG_EXIT_STATUS ( Status );
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the network connections to this controller by removing
|
||||||
|
NetworkInterfaceIdentifier protocol and closing the DevicePath
|
||||||
|
and PciIo protocols on Controller.
|
||||||
|
|
||||||
|
@param [in] BindingHandle Handle for protocol binding.
|
||||||
|
@param [in] Controller Handle of device to stop driver on.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS This driver is removed Controller.
|
||||||
|
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
|
||||||
|
@retval other This driver was not removed from this device.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceDisconnect (
|
||||||
|
IN EFI_HANDLE BindingHandle,
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
)
|
||||||
|
{
|
||||||
|
CONST DT_SOCKET_BINDING * pEnd;
|
||||||
|
DT_SERVICE * pService;
|
||||||
|
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
EFI_TPL TplPrevious;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Walk the list of network connection points in reverse order
|
||||||
|
//
|
||||||
|
pEnd = &cEslSocketBinding[0];
|
||||||
|
pSocketBinding = &pEnd[ cEslSocketBindingEntries ];
|
||||||
|
while ( pEnd < pSocketBinding ) {
|
||||||
|
//
|
||||||
|
// Set the next network protocol
|
||||||
|
//
|
||||||
|
pSocketBinding -= 1;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Determine if the driver connected
|
||||||
|
//
|
||||||
|
Status = gBS->OpenProtocol (
|
||||||
|
Controller,
|
||||||
|
(EFI_GUID *)pSocketBinding->pTagGuid,
|
||||||
|
(VOID **)&pService,
|
||||||
|
BindingHandle,
|
||||||
|
Controller,
|
||||||
|
EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
|
||||||
|
//
|
||||||
|
// Synchronize with the socket layer
|
||||||
|
//
|
||||||
|
RAISE_TPL ( TplPrevious, TPL_SOCKETS );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Shutdown the service
|
||||||
|
//
|
||||||
|
pSocketBinding->pfnShutdown ( pService );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Release the socket layer synchronization
|
||||||
|
//
|
||||||
|
RESTORE_TPL ( TplPrevious );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Break the driver connection
|
||||||
|
//
|
||||||
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
Controller,
|
||||||
|
pSocketBinding->pTagGuid,
|
||||||
|
pService,
|
||||||
|
NULL );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"Removed: %s TagGuid from 0x%08x\r\n",
|
||||||
|
pSocketBinding->pName,
|
||||||
|
Controller ));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"ERROR - Failed to removed %s TagGuid from 0x%08x, Status: %r\r\n",
|
||||||
|
pSocketBinding->pName,
|
||||||
|
Controller,
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Free the service structure
|
||||||
|
//
|
||||||
|
Status = gBS->FreePool ( pService );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"0x%08x: Free pService, %d bytes\r\n",
|
||||||
|
pService,
|
||||||
|
sizeof ( *pService )));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"ERROR - Failed to free pService 0x%08x, Status: %r\r\n",
|
||||||
|
pService,
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
pService = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// The controller is no longer in use
|
||||||
|
//
|
||||||
|
gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
Controller,
|
||||||
|
&gEfiCallerIdGuid,
|
||||||
|
NULL,
|
||||||
|
NULL );
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||||
|
"Removed: gEfiCallerIdGuid from 0x%08x\r\n",
|
||||||
|
Controller ));
|
||||||
|
|
||||||
|
//
|
||||||
|
// The driver is disconnected from the network controller
|
||||||
|
//
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Display the driver start status
|
||||||
|
//
|
||||||
|
DBG_EXIT_STATUS ( Status );
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Install the socket service
|
||||||
|
|
||||||
|
@param [in] pImageHandle Address of the image handle
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Service installed successfully
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceInstall (
|
||||||
|
IN EFI_HANDLE * pImageHandle
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Install the socket service binding protocol
|
||||||
|
//
|
||||||
|
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||||
|
pImageHandle,
|
||||||
|
&gEfiSocketServiceBindingProtocolGuid,
|
||||||
|
&mEslLayer.ServiceBinding,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT | DEBUG_INFO,
|
||||||
|
"Installed: gEfiSocketServiceBindingProtocolGuid on 0x%08x\r\n",
|
||||||
|
*pImageHandle ));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"ERROR - InstallMultipleProtocolInterfaces failed, Status: %r\r\n",
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation status
|
||||||
|
//
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the service layer
|
||||||
|
|
||||||
|
@param [in] ImageHandle Handle for the image.
|
||||||
|
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EFIAPI
|
||||||
|
EslServiceLoad (
|
||||||
|
IN EFI_HANDLE ImageHandle
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DT_LAYER * pLayer;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Save the image handle
|
||||||
|
//
|
||||||
|
pLayer = &mEslLayer;
|
||||||
|
pLayer->Signature = LAYER_SIGNATURE;
|
||||||
|
pLayer->ImageHandle = ImageHandle;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize the TCP4 close
|
||||||
|
//
|
||||||
|
pLayer->TcpCloseMax4 = DIM ( mpEfiTcpClose4 );
|
||||||
|
pLayer->ppTcpClose4 = mpEfiTcpClose4;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Connect the service binding protocol to the image handle
|
||||||
|
//
|
||||||
|
pLayer->ServiceBinding.CreateChild = EslSocketCreateChild;
|
||||||
|
pLayer->ServiceBinding.DestroyChild = EslSocketDestroyChild;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Uninstall the socket service
|
||||||
|
|
||||||
|
@param [in] ImageHandle Handle for the image.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Service installed successfully
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceUninstall (
|
||||||
|
IN EFI_HANDLE ImageHandle
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Install the socket service binding protocol
|
||||||
|
//
|
||||||
|
Status = gBS->UninstallMultipleProtocolInterfaces (
|
||||||
|
ImageHandle,
|
||||||
|
&gEfiSocketServiceBindingProtocolGuid,
|
||||||
|
&mEslLayer.ServiceBinding,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
DEBUG (( DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"Removed: gEfiSocketServiceBindingProtocolGuid from 0x%08x\r\n",
|
||||||
|
ImageHandle ));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_POOL | DEBUG_INIT,
|
||||||
|
"ERROR - Failed to remove gEfiSocketServiceBindingProtocolGuid from 0x%08x, Status: %r\r\n",
|
||||||
|
ImageHandle,
|
||||||
|
Status ));
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation status
|
||||||
|
//
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the service layer
|
||||||
|
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EFIAPI
|
||||||
|
EslServiceUnload (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
DT_LAYER * pLayer;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Undo the work by ServiceLoad
|
||||||
|
//
|
||||||
|
pLayer = &mEslLayer;
|
||||||
|
pLayer->ImageHandle = NULL;
|
||||||
|
pLayer->ServiceBinding.CreateChild = NULL;
|
||||||
|
pLayer->ServiceBinding.DestroyChild = NULL;
|
||||||
|
}
|
3091
StdLib/EfiSocketLib/Socket.c
Normal file
3091
StdLib/EfiSocketLib/Socket.c
Normal file
File diff suppressed because it is too large
Load Diff
1337
StdLib/EfiSocketLib/Socket.h
Normal file
1337
StdLib/EfiSocketLib/Socket.h
Normal file
File diff suppressed because it is too large
Load Diff
3415
StdLib/EfiSocketLib/Tcp4.c
Normal file
3415
StdLib/EfiSocketLib/Tcp4.c
Normal file
File diff suppressed because it is too large
Load Diff
2408
StdLib/EfiSocketLib/Udp4.c
Normal file
2408
StdLib/EfiSocketLib/Udp4.c
Normal file
File diff suppressed because it is too large
Load Diff
242
StdLib/EfiSocketLib/UseEfiSocketLib.c
Normal file
242
StdLib/EfiSocketLib/UseEfiSocketLib.c
Normal file
@ -0,0 +1,242 @@
|
|||||||
|
/** @file
|
||||||
|
Implement the connection to the EFI socket library
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
|
||||||
|
CONST EFI_GUID mEslRawServiceGuid = {
|
||||||
|
0xc31bf4a5, 0x2c7, 0x49d2, { 0xa5, 0x58, 0xfe, 0x62, 0x6f, 0x7e, 0xd4, 0x77 }
|
||||||
|
};
|
||||||
|
|
||||||
|
CONST EFI_GUID mEslTcp4ServiceGuid = {
|
||||||
|
0xffc659c2, 0x4ef2, 0x4532, { 0xb8, 0x75, 0xcd, 0x9a, 0xa4, 0x27, 0x4c, 0xde }
|
||||||
|
};
|
||||||
|
|
||||||
|
CONST EFI_GUID mEslUdp4ServiceGuid = {
|
||||||
|
0x44e03a55, 0x8d97, 0x4511, { 0xbf, 0xef, 0xa, 0x8b, 0xc6, 0x2c, 0x25, 0xae }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to the EFI socket library
|
||||||
|
|
||||||
|
@param [in] ppSocketProtocol Address to receive the socket protocol address
|
||||||
|
|
||||||
|
@retval 0 Successfully returned the socket protocol
|
||||||
|
@retval other Value for errno
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
EslServiceGetProtocol (
|
||||||
|
IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
|
||||||
|
)
|
||||||
|
{
|
||||||
|
EFI_HANDLE ChildHandle;
|
||||||
|
DT_SOCKET * pSocket;
|
||||||
|
int RetVal;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume success
|
||||||
|
//
|
||||||
|
RetVal = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Locate the socket protocol
|
||||||
|
//
|
||||||
|
ChildHandle = NULL;
|
||||||
|
Status = EslSocketAllocate ( &ChildHandle,
|
||||||
|
DEBUG_SOCKET,
|
||||||
|
&pSocket );
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
*ppSocketProtocol = &pSocket->SocketProtocol;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//
|
||||||
|
// No resources
|
||||||
|
//
|
||||||
|
RetVal = ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the operation status
|
||||||
|
//
|
||||||
|
DBG_EXIT_DEC ( RetVal );
|
||||||
|
return RetVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to the network layer
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Successfully connected to the network layer
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslServiceNetworkConnect (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN HandleCount;
|
||||||
|
EFI_HANDLE * pHandles;
|
||||||
|
UINTN Index;
|
||||||
|
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||||
|
CONST DT_SOCKET_BINDING * pEnd;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialize the socket layer
|
||||||
|
//
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
EslServiceLoad ( gImageHandle );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Connect the network devices
|
||||||
|
//
|
||||||
|
pSocketBinding = &cEslSocketBinding [0];
|
||||||
|
pEnd = &pSocketBinding [ cEslSocketBindingEntries ];
|
||||||
|
while ( pEnd > pSocketBinding ) {
|
||||||
|
//
|
||||||
|
// Attempt to locate the network adapters
|
||||||
|
//
|
||||||
|
HandleCount = 0;
|
||||||
|
pHandles = NULL;
|
||||||
|
Status = gBS->LocateHandleBuffer ( ByProtocol,
|
||||||
|
pSocketBinding->pNetworkBinding,
|
||||||
|
NULL,
|
||||||
|
&HandleCount,
|
||||||
|
&pHandles );
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( NULL != pHandles ) {
|
||||||
|
//
|
||||||
|
// Attempt to connect to this network adapter
|
||||||
|
//
|
||||||
|
for ( Index = 0; HandleCount > Index; Index++ ) {
|
||||||
|
Status = EslServiceConnect ( gImageHandle,
|
||||||
|
pHandles [ Index ]);
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Done with the handles
|
||||||
|
//
|
||||||
|
gBS->FreePool ( pHandles );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set the next network protocol
|
||||||
|
//
|
||||||
|
pSocketBinding += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the network connection status
|
||||||
|
//
|
||||||
|
DBG_EXIT_STATUS ( Status );
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Disconnect from the network layer
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Successfully disconnected from the network layer
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslServiceNetworkDisconnect (
|
||||||
|
VOID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
UINTN HandleCount;
|
||||||
|
EFI_HANDLE * pHandles;
|
||||||
|
UINTN Index;
|
||||||
|
CONST DT_SOCKET_BINDING * pSocketBinding;
|
||||||
|
CONST DT_SOCKET_BINDING * pEnd;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
DBG_ENTER ( );
|
||||||
|
|
||||||
|
//
|
||||||
|
// Assume success
|
||||||
|
//
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Disconnect the network devices
|
||||||
|
//
|
||||||
|
pSocketBinding = &cEslSocketBinding [0];
|
||||||
|
pEnd = &pSocketBinding [ cEslSocketBindingEntries ];
|
||||||
|
while ( pEnd > pSocketBinding ) {
|
||||||
|
//
|
||||||
|
// Attempt to locate the network adapters
|
||||||
|
//
|
||||||
|
HandleCount = 0;
|
||||||
|
pHandles = NULL;
|
||||||
|
Status = gBS->LocateHandleBuffer ( ByProtocol,
|
||||||
|
pSocketBinding->pNetworkBinding,
|
||||||
|
NULL,
|
||||||
|
&HandleCount,
|
||||||
|
&pHandles );
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( NULL != pHandles ) {
|
||||||
|
//
|
||||||
|
// Attempt to disconnect from this network adapter
|
||||||
|
//
|
||||||
|
for ( Index = 0; HandleCount > Index; Index++ ) {
|
||||||
|
Status = EslServiceDisconnect ( gImageHandle,
|
||||||
|
pHandles [ Index ]);
|
||||||
|
if ( EFI_ERROR ( Status )) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Done with the handles
|
||||||
|
//
|
||||||
|
gBS->FreePool ( pHandles );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Set the next network protocol
|
||||||
|
//
|
||||||
|
pSocketBinding += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Finish the disconnect operation
|
||||||
|
//
|
||||||
|
if ( !EFI_ERROR ( Status )) {
|
||||||
|
EslServiceUnload ( );
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Return the network connection status
|
||||||
|
//
|
||||||
|
DBG_EXIT_STATUS ( Status );
|
||||||
|
return Status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PFN_ESL_xSTRUCTOR mpfnEslConstructor = EslServiceNetworkConnect;
|
||||||
|
PFN_ESL_xSTRUCTOR mpfnEslDestructor = EslServiceNetworkDisconnect;
|
679
StdLib/Include/Efi/EfiSocketLib.h
Normal file
679
StdLib/Include/Efi/EfiSocketLib.h
Normal file
@ -0,0 +1,679 @@
|
|||||||
|
/** @file
|
||||||
|
Definitions for the EFI Socket layer library.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef _EFI_SOCKET_LIB_H_
|
||||||
|
#define _EFI_SOCKET_LIB_H_
|
||||||
|
|
||||||
|
#include <Uefi.h>
|
||||||
|
|
||||||
|
#include <Library/BaseMemoryLib.h>
|
||||||
|
#include <Library/DebugLib.h>
|
||||||
|
#include <Library/UefiBootServicesTableLib.h>
|
||||||
|
#include <Library/UefiLib.h>
|
||||||
|
|
||||||
|
#include <Protocol/EfiSocket.h>
|
||||||
|
#include <Protocol/ServiceBinding.h>
|
||||||
|
#include <Protocol/Tcp4.h>
|
||||||
|
#include <Protocol/Udp4.h>
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Constants
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#define DEBUG_TPL 0x40000000 ///< Display TPL change messages
|
||||||
|
|
||||||
|
#define TPL_SOCKETS TPL_CALLBACK ///< TPL for routine synchronization
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Macros
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
|
||||||
|
#define DBG_ENTER() DEBUG (( DEBUG_INFO, "Entering " __FUNCTION__ "\n" )) ///< Display routine entry
|
||||||
|
#define DBG_EXIT() DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ "\n" )) ///< Display routine exit
|
||||||
|
#define DBG_EXIT_DEC(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %d\n", Status )) ///< Display routine exit with decimal value
|
||||||
|
#define DBG_EXIT_HEX(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: 0x%08x\n", Status )) ///< Display routine exit with hex value
|
||||||
|
#define DBG_EXIT_STATUS(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", Status: %r\n", Status )) ///< Display routine exit with status value
|
||||||
|
#define DBG_EXIT_TF(Status) DEBUG (( DEBUG_INFO, "Exiting " __FUNCTION__ ", returning %s\n", (FALSE == Status) ? L"FALSE" : L"TRUE" )) ///< Display routine with TRUE/FALSE value
|
||||||
|
#else // _MSC_VER
|
||||||
|
#define DBG_ENTER()
|
||||||
|
#define DBG_EXIT()
|
||||||
|
#define DBG_EXIT_DEC(Status)
|
||||||
|
#define DBG_EXIT_HEX(Status)
|
||||||
|
#define DBG_EXIT_STATUS(Status)
|
||||||
|
#define DBG_EXIT_TF(Status)
|
||||||
|
#endif // _MSC_VER
|
||||||
|
|
||||||
|
#define DIM(x) ( sizeof ( x ) / sizeof ( x[0] )) ///< Compute the number of entries in an array
|
||||||
|
|
||||||
|
/**
|
||||||
|
Verify new TPL value
|
||||||
|
|
||||||
|
This macro which is enabled when debug is enabled verifies that
|
||||||
|
the new TPL value is >= the current TPL value.
|
||||||
|
**/
|
||||||
|
#ifdef VERIFY_TPL
|
||||||
|
#undef VERIFY_TPL
|
||||||
|
#endif // VERIFY_TPL
|
||||||
|
|
||||||
|
#if !defined(MDEPKG_NDEBUG)
|
||||||
|
|
||||||
|
#define VERIFY_TPL(tpl) \
|
||||||
|
{ \
|
||||||
|
EFI_TPL PreviousTpl; \
|
||||||
|
\
|
||||||
|
PreviousTpl = gBS->RaiseTPL ( TPL_HIGH_LEVEL ); \
|
||||||
|
gBS->RestoreTPL ( PreviousTpl ); \
|
||||||
|
if ( PreviousTpl > tpl ) { \
|
||||||
|
DEBUG (( DEBUG_ERROR | DEBUG_TPL, \
|
||||||
|
"Current TPL: %d, New TPL: %d\r\n", \
|
||||||
|
PreviousTpl, tpl )); \
|
||||||
|
ASSERT ( PreviousTpl <= tpl ); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // MDEPKG_NDEBUG
|
||||||
|
|
||||||
|
#define VERIFY_TPL(tpl)
|
||||||
|
|
||||||
|
#endif // MDEPKG_NDEBUG
|
||||||
|
|
||||||
|
#define RAISE_TPL(PreviousTpl, tpl) \
|
||||||
|
VERIFY_TPL ( tpl ); \
|
||||||
|
PreviousTpl = gBS->RaiseTPL ( tpl ); \
|
||||||
|
DEBUG (( DEBUG_TPL | DEBUG_TPL, \
|
||||||
|
"%d: TPL\r\n", \
|
||||||
|
tpl ))
|
||||||
|
|
||||||
|
#define RESTORE_TPL(tpl) \
|
||||||
|
gBS->RestoreTPL ( tpl ); \
|
||||||
|
DEBUG (( DEBUG_TPL | DEBUG_TPL, \
|
||||||
|
"%d: TPL\r\n", \
|
||||||
|
tpl ))
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Data Types
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef struct _DT_SERVICE DT_SERVICE; ///< Forward delcaration
|
||||||
|
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_SB_INITIALIZE) (
|
||||||
|
DT_SERVICE * pService
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef
|
||||||
|
VOID
|
||||||
|
(* PFN_SB_SHUTDOWN) (
|
||||||
|
DT_SERVICE * pService
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Protocol binding and installation control structure
|
||||||
|
|
||||||
|
The driver uses this structure to simplify the driver binding processing.
|
||||||
|
**/
|
||||||
|
typedef struct {
|
||||||
|
CHAR16 * pName; ///< Protocol name
|
||||||
|
EFI_GUID * pNetworkBinding; ///< Network service binding protocol for socket support
|
||||||
|
CONST EFI_GUID * pTagGuid; ///< Tag to mark protocol in use
|
||||||
|
PFN_SB_INITIALIZE pfnInitialize;///< Routine to initialize the service
|
||||||
|
PFN_SB_SHUTDOWN pfnShutdown; ///< Routine to shutdown the service
|
||||||
|
} DT_SOCKET_BINDING;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// GUIDs
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern CONST EFI_GUID mEslRawServiceGuid;
|
||||||
|
extern CONST EFI_GUID mEslTcp4ServiceGuid;
|
||||||
|
extern CONST EFI_GUID mEslUdp4ServiceGuid;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Data
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern CONST DT_SOCKET_BINDING cEslSocketBinding [];
|
||||||
|
extern CONST UINTN cEslSocketBindingEntries;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Service Support Routines
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to the network service bindings
|
||||||
|
|
||||||
|
Walk the network service protocols on the controller handle and
|
||||||
|
locate any that are not in use. Create service structures to
|
||||||
|
manage the service binding for the socket driver.
|
||||||
|
|
||||||
|
@param [in] BindingHandle Handle for protocol binding.
|
||||||
|
@param [in] Controller Handle of device to work with.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS This driver is added to Controller.
|
||||||
|
@retval other This driver does not support this device.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceConnect (
|
||||||
|
IN EFI_HANDLE BindingHandle,
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the network connections to this controller by removing
|
||||||
|
NetworkInterfaceIdentifier protocol and closing the DevicePath
|
||||||
|
and PciIo protocols on Controller.
|
||||||
|
|
||||||
|
@param [in] BindingHandle Handle for protocol binding.
|
||||||
|
@param [in] Controller Handle of device to stop driver on.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS This driver is removed Controller.
|
||||||
|
@retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
|
||||||
|
@retval other This driver was not removed from this device.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceDisconnect (
|
||||||
|
IN EFI_HANDLE BindingHandle,
|
||||||
|
IN EFI_HANDLE Controller
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Install the socket service
|
||||||
|
|
||||||
|
@param [in] pImageHandle Address of the image handle
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Service installed successfully
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceInstall (
|
||||||
|
IN EFI_HANDLE * pImageHandle
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize the service layer
|
||||||
|
|
||||||
|
@param [in] ImageHandle Handle for the image.
|
||||||
|
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EFIAPI
|
||||||
|
EslServiceLoad (
|
||||||
|
IN EFI_HANDLE ImageHandle
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Uninstall the socket service
|
||||||
|
|
||||||
|
@param [in] ImageHandle Handle for the image.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Service installed successfully
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslServiceUninstall (
|
||||||
|
IN EFI_HANDLE ImageHandle
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the service layer
|
||||||
|
|
||||||
|
**/
|
||||||
|
VOID
|
||||||
|
EFIAPI
|
||||||
|
EslServiceUnload (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Socket Service Binding Protocol Routines
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Creates a child handle and installs a protocol.
|
||||||
|
|
||||||
|
The CreateChild() function installs a protocol on ChildHandle.
|
||||||
|
If pChildHandle is a pointer to NULL, then a new handle is created and returned in pChildHandle.
|
||||||
|
If pChildHandle is not a pointer to NULL, then the protocol installs on the existing pChildHandle.
|
||||||
|
|
||||||
|
@param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
|
||||||
|
@param [in] pChildHandle Pointer to the handle of the child to create. If it is NULL,
|
||||||
|
then a new handle is created. If it is a pointer to an existing UEFI handle,
|
||||||
|
then the protocol is added to the existing UEFI handle.
|
||||||
|
|
||||||
|
@retval EFI_SUCCES The protocol was added to ChildHandle.
|
||||||
|
@retval EFI_INVALID_PARAMETER ChildHandle is NULL.
|
||||||
|
@retval EFI_OUT_OF_RESOURCES There are not enough resources availabe to create
|
||||||
|
the child
|
||||||
|
@retval other The child handle was not created
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslSocketCreateChild (
|
||||||
|
IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
|
||||||
|
IN OUT EFI_HANDLE * pChildHandle
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Destroys a child handle with a protocol installed on it.
|
||||||
|
|
||||||
|
The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
|
||||||
|
that was installed by CreateChild() from ChildHandle. If the removed protocol is the
|
||||||
|
last protocol on ChildHandle, then ChildHandle is destroyed.
|
||||||
|
|
||||||
|
@param [in] pThis Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
|
||||||
|
@param [in] ChildHandle Handle of the child to destroy
|
||||||
|
|
||||||
|
@retval EFI_SUCCES The protocol was removed from ChildHandle.
|
||||||
|
@retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
|
||||||
|
@retval EFI_INVALID_PARAMETER Child handle is not a valid UEFI Handle.
|
||||||
|
@retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
|
||||||
|
because its services are being used.
|
||||||
|
@retval other The child handle was not destroyed
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EFIAPI
|
||||||
|
EslSocketDestroyChild (
|
||||||
|
IN EFI_SERVICE_BINDING_PROTOCOL * pThis,
|
||||||
|
IN EFI_HANDLE ChildHandle
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Socket Protocol Routines
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Bind a name to a socket.
|
||||||
|
|
||||||
|
The ::SocketBind routine connects a name to a socket on the local machine. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
|
||||||
|
documentation for the bind routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] pSockAddr Address of a sockaddr structure that contains the
|
||||||
|
connection point on the local machine. An IPv4 address
|
||||||
|
of INADDR_ANY specifies that the connection is made to
|
||||||
|
all of the network stacks on the platform. Specifying a
|
||||||
|
specific IPv4 address restricts the connection to the
|
||||||
|
network stack supporting that address. Specifying zero
|
||||||
|
for the port causes the network layer to assign a port
|
||||||
|
number from the dynamic range. Specifying a specific
|
||||||
|
port number causes the network layer to use that port.
|
||||||
|
|
||||||
|
@param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully created
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketBind (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN const struct sockaddr * pSockAddr,
|
||||||
|
IN socklen_t SockAddrLength,
|
||||||
|
OUT int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Determine if the socket is closed
|
||||||
|
|
||||||
|
Reverses the operations of the ::SocketAllocate() routine.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Socket successfully closed
|
||||||
|
@retval EFI_NOT_READY Close still in progress
|
||||||
|
@retval EFI_ALREADY Close operation already in progress
|
||||||
|
@retval Other Failed to close the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketClosePoll (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Start the close operation on the socket
|
||||||
|
|
||||||
|
Start closing the socket by closing all of the ports. Upon
|
||||||
|
completion, the ::SocketPoll() routine finishes closing the
|
||||||
|
socket.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [in] bCloseNow Boolean to control close behavior
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Socket successfully closed
|
||||||
|
@retval EFI_NOT_READY Close still in progress
|
||||||
|
@retval EFI_ALREADY Close operation already in progress
|
||||||
|
@retval Other Failed to close the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketCloseStart (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN BOOLEAN bCloseNow,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to a remote system via the network.
|
||||||
|
|
||||||
|
The ::SocketConnect routine attempts to establish a connection to a
|
||||||
|
socket on the local or remote system using the specified address.
|
||||||
|
The POSIX
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">connect</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
There are three states associated with a connection:
|
||||||
|
<ul>
|
||||||
|
<li>Not connected</li>
|
||||||
|
<li>Connection in progress</li>
|
||||||
|
<li>Connected</li>
|
||||||
|
</ul>
|
||||||
|
In the "Not connected" state, calls to ::connect start the connection
|
||||||
|
processing and update the state to "Connection in progress". During
|
||||||
|
the "Connection in progress" state, connect polls for connection completion
|
||||||
|
and moves the state to "Connected" after the connection is established.
|
||||||
|
Note that these states are only visible when the file descriptor is marked
|
||||||
|
with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
|
||||||
|
completes and may be used by poll or select as an indicator to call
|
||||||
|
connect again.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] pSockAddr Network address of the remote system.
|
||||||
|
|
||||||
|
@param [in] SockAddrLength Length in bytes of the network address.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The connection was successfully established.
|
||||||
|
@retval EFI_NOT_READY The connection is in progress, call this routine again.
|
||||||
|
@retval Others The connection attempt failed.
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketConnect (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN const struct sockaddr * pSockAddr,
|
||||||
|
IN socklen_t SockAddrLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the local address.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [out] pAddress Network address to receive the local system address
|
||||||
|
|
||||||
|
@param [in,out] pAddressLength Length of the local network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Local address successfully returned
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketGetLocalAddress (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
OUT struct sockaddr * pAddress,
|
||||||
|
IN OUT socklen_t * pAddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the peer address.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [out] pAddress Network address to receive the remote system address
|
||||||
|
|
||||||
|
@param [in,out] pAddressLength Length of the remote network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Remote address successfully returned
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketGetPeerAddress (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
OUT struct sockaddr * pAddress,
|
||||||
|
IN OUT socklen_t * pAddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Establish the known port to listen for network connections.
|
||||||
|
|
||||||
|
The ::SocketListen routine places the port into a state that enables connection
|
||||||
|
attempts. Connections are placed into FIFO order in a queue to be serviced
|
||||||
|
by the application. The application calls the ::SocketAccept routine to remove
|
||||||
|
the next connection from the queue and get the associated socket. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
|
||||||
|
documentation for the bind routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Backlog Backlog specifies the maximum FIFO depth for
|
||||||
|
the connections waiting for the application
|
||||||
|
to call accept. Connection attempts received
|
||||||
|
while the queue is full are refused.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully created
|
||||||
|
@retval Other - Failed to enable the socket for listen
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketListen (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN INT32 Backlog,
|
||||||
|
OUT int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the socket options
|
||||||
|
|
||||||
|
Retrieve the socket options one at a time by name. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [in] level Option protocol level
|
||||||
|
@param [in] option_name Name of the option
|
||||||
|
@param [out] option_value Buffer to receive the option value
|
||||||
|
@param [in,out] option_len Length of the buffer in bytes,
|
||||||
|
upon return length of the option value in bytes
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketOptionGet (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int level,
|
||||||
|
IN int option_name,
|
||||||
|
OUT void * __restrict option_value,
|
||||||
|
IN OUT socklen_t * __restrict option_len,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the socket options
|
||||||
|
|
||||||
|
Adjust the socket options one at a time by name. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [in] level Option protocol level
|
||||||
|
@param [in] option_name Name of the option
|
||||||
|
@param [in] option_value Buffer containing the option value
|
||||||
|
@param [in] option_len Length of the buffer in bytes
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketOptionSet (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int level,
|
||||||
|
IN int option_name,
|
||||||
|
IN CONST void * option_value,
|
||||||
|
IN socklen_t option_len,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Poll a socket for pending activity.
|
||||||
|
|
||||||
|
The SocketPoll routine checks a socket for pending activity associated
|
||||||
|
with the event mask. Activity is returned in the detected event buffer.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Events Events of interest for this socket
|
||||||
|
|
||||||
|
@param [in] pEvents Address to receive the detected events
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully polled
|
||||||
|
@retval EFI_INVALID_PARAMETER - When pEvents is NULL
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketPoll (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN short Events,
|
||||||
|
IN short * pEvents,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Receive data from a network connection.
|
||||||
|
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Flags Message control flags
|
||||||
|
|
||||||
|
@param [in] BufferLength Length of the the buffer
|
||||||
|
|
||||||
|
@param [in] pBuffer Address of a buffer to receive the data.
|
||||||
|
|
||||||
|
@param [in] pDataLength Number of received data bytes in the buffer.
|
||||||
|
|
||||||
|
@param [out] pAddress Network address to receive the remote system address
|
||||||
|
|
||||||
|
@param [in,out] pAddressLength Length of the remote network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketReceive (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN INT32 Flags,
|
||||||
|
IN size_t BufferLength,
|
||||||
|
IN UINT8 * pBuffer,
|
||||||
|
OUT size_t * pDataLength,
|
||||||
|
OUT struct sockaddr * pAddress,
|
||||||
|
IN OUT socklen_t * pAddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the socket receive and transmit operations
|
||||||
|
|
||||||
|
The SocketShutdown routine stops the socket receive and transmit
|
||||||
|
operations.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] How Which operations to stop
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket operations successfully shutdown
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketShutdown (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int How,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send data using a network connection.
|
||||||
|
|
||||||
|
The SocketTransmit routine queues the data for transmission to the
|
||||||
|
remote network connection.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Flags Message control flags
|
||||||
|
|
||||||
|
@param [in] BufferLength Length of the the buffer
|
||||||
|
|
||||||
|
@param [in] pBuffer Address of a buffer containing the data to send
|
||||||
|
|
||||||
|
@param [in] pDataLength Address to receive the number of data bytes sent
|
||||||
|
|
||||||
|
@param [in] pAddress Network address of the remote system address
|
||||||
|
|
||||||
|
@param [in] AddressLength Length of the remote network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
EFI_STATUS
|
||||||
|
EslSocketTransmit (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int Flags,
|
||||||
|
IN size_t BufferLength,
|
||||||
|
IN CONST UINT8 * pBuffer,
|
||||||
|
OUT size_t * pDataLength,
|
||||||
|
IN const struct sockaddr * pAddress,
|
||||||
|
IN socklen_t AddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif // _EFI_SOCKET_LIB_H_
|
@ -1,3 +1,14 @@
|
|||||||
#include <x86/limits.h>
|
#include <x86/limits.h>
|
||||||
|
|
||||||
#define __POINTER_BIT 32
|
#define __POINTER_BIT 32
|
||||||
|
#define __LONG_BIT 32
|
||||||
|
|
||||||
|
/** minimum value for an object of type long int **/
|
||||||
|
#define __LONG_MIN (-2147483647L - 1L) // -(2^31 - 1)
|
||||||
|
|
||||||
|
/** maximum value for an object of type long int **/
|
||||||
|
#define __LONG_MAX +2147483647L // 2^31 - 1
|
||||||
|
|
||||||
|
/** maximum value for an object of type unsigned long int **/
|
||||||
|
#define __ULONG_MAX 0xffffffff // 2^32 - 1
|
||||||
|
|
||||||
|
606
StdLib/Include/Protocol/EfiSocket.h
Normal file
606
StdLib/Include/Protocol/EfiSocket.h
Normal file
@ -0,0 +1,606 @@
|
|||||||
|
/** @file
|
||||||
|
Definitions for the EFI Socket protocol.
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation
|
||||||
|
All rights reserved. This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef _EFI_SOCKET_H_
|
||||||
|
#define _EFI_SOCKET_H_
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <Uefi.h>
|
||||||
|
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
#include <sys/poll.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Data Types
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
typedef struct _EFI_SOCKET_PROTOCOL EFI_SOCKET_PROTOCOL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructor/Destructor
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The operation was successful
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_ESL_xSTRUCTOR) (
|
||||||
|
VOID
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Data
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
extern PFN_ESL_xSTRUCTOR mpfnEslConstructor;
|
||||||
|
extern PFN_ESL_xSTRUCTOR mpfnEslDestructor;
|
||||||
|
|
||||||
|
extern EFI_GUID gEfiSocketProtocolGuid;
|
||||||
|
extern EFI_GUID gEfiSocketServiceBindingProtocolGuid;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Socket API
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Accept a network connection.
|
||||||
|
|
||||||
|
The SocketAccept routine waits for a network connection to the socket.
|
||||||
|
It is able to return the remote network address to the caller if
|
||||||
|
requested.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] pSockAddr Address of a buffer to receive the remote
|
||||||
|
network address.
|
||||||
|
|
||||||
|
@param [in, out] pSockAddrLength Length in bytes of the address buffer.
|
||||||
|
On output specifies the length of the
|
||||||
|
remote network address.
|
||||||
|
|
||||||
|
@param [out] ppSocketProtocol Address of a buffer to receive the socket protocol
|
||||||
|
instance associated with the new socket.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS New connection successfully created
|
||||||
|
@retval EFI_NOT_READY No connection is available
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_ACCEPT) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN struct sockaddr * pSockAddr,
|
||||||
|
IN OUT socklen_t * pSockAddrLength,
|
||||||
|
IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Bind a name to a socket.
|
||||||
|
|
||||||
|
The ::SocketBind routine connects a name to a socket on the local machine. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html">POSIX</a>
|
||||||
|
documentation for the bind routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] pSockAddr Address of a sockaddr structure that contains the
|
||||||
|
connection point on the local machine. An IPv4 address
|
||||||
|
of INADDR_ANY specifies that the connection is made to
|
||||||
|
all of the network stacks on the platform. Specifying a
|
||||||
|
specific IPv4 address restricts the connection to the
|
||||||
|
network stack supporting that address. Specifying zero
|
||||||
|
for the port causes the network layer to assign a port
|
||||||
|
number from the dynamic range. Specifying a specific
|
||||||
|
port number causes the network layer to use that port.
|
||||||
|
|
||||||
|
@param [in] SockAddrLen Specifies the length in bytes of the sockaddr structure.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully created
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_BIND) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN const struct sockaddr * pSockAddr,
|
||||||
|
IN socklen_t SockAddrLength,
|
||||||
|
OUT int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Determine if the socket is closed
|
||||||
|
|
||||||
|
Reverses the operations of the ::SocketAllocate() routine.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Socket successfully closed
|
||||||
|
@retval EFI_NOT_READY Close still in progress
|
||||||
|
@retval EFI_ALREADY Close operation already in progress
|
||||||
|
@retval Other Failed to close the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_CLOSE_POLL) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Start the close operation on the socket
|
||||||
|
|
||||||
|
Start closing the socket by closing all of the ports. Upon
|
||||||
|
completion, the ::pfnClosePoll() routine finishes closing the
|
||||||
|
socket.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [in] bCloseNow Boolean to control close behavior
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS Socket successfully closed
|
||||||
|
@retval EFI_NOT_READY Close still in progress
|
||||||
|
@retval EFI_ALREADY Close operation already in progress
|
||||||
|
@retval Other Failed to close the socket
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_CLOSE_START) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN BOOLEAN bCloseNow,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to a remote system via the network.
|
||||||
|
|
||||||
|
The ::Connect routine attempts to establish a connection to a
|
||||||
|
socket on the local or remote system using the specified address.
|
||||||
|
The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
There are three states associated with a connection:
|
||||||
|
<ul>
|
||||||
|
<li>Not connected</li>
|
||||||
|
<li>Connection in progress</li>
|
||||||
|
<li>Connected</li>
|
||||||
|
</ul>
|
||||||
|
In the "Not connected" state, calls to ::connect start the connection
|
||||||
|
processing and update the state to "Connection in progress". During
|
||||||
|
the "Connection in progress" state, connect polls for connection completion
|
||||||
|
and moves the state to "Connected" after the connection is established.
|
||||||
|
Note that these states are only visible when the file descriptor is marked
|
||||||
|
with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
|
||||||
|
completes and may be used by poll or select as an indicator to call
|
||||||
|
connect again.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] pSockAddr Network address of the remote system.
|
||||||
|
|
||||||
|
@param [in] SockAddrLength Length in bytes of the network address.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS The connection was successfully established.
|
||||||
|
@retval EFI_NOT_READY The connection is in progress, call this routine again.
|
||||||
|
@retval Others The connection attempt failed.
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_CONNECT) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN const struct sockaddr * pSockAddr,
|
||||||
|
IN socklen_t SockAddrLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the local address.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [out] pAddress Network address to receive the local system address
|
||||||
|
|
||||||
|
@param [in,out] pAddressLength Length of the local network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Local address successfully returned
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_GET_LOCAL) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
OUT struct sockaddr * pAddress,
|
||||||
|
IN OUT socklen_t * pAddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the peer address.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [out] pAddress Network address to receive the remote system address
|
||||||
|
|
||||||
|
@param [in,out] pAddressLength Length of the remote network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Remote address successfully returned
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_GET_PEER) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
OUT struct sockaddr * pAddress,
|
||||||
|
IN OUT socklen_t * pAddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Establish the known port to listen for network connections.
|
||||||
|
|
||||||
|
The ::SocketAisten routine places the port into a state that enables connection
|
||||||
|
attempts. Connections are placed into FIFO order in a queue to be serviced
|
||||||
|
by the application. The application calls the ::SocketAccept routine to remove
|
||||||
|
the next connection from the queue and get the associated socket. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html">POSIX</a>
|
||||||
|
documentation for the bind routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Backlog Backlog specifies the maximum FIFO depth for
|
||||||
|
the connections waiting for the application
|
||||||
|
to call accept. Connection attempts received
|
||||||
|
while the queue is full are refused.
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully created
|
||||||
|
@retval Other - Failed to enable the socket for listen
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_LISTEN) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN INT32 Backlog,
|
||||||
|
OUT int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get the socket options
|
||||||
|
|
||||||
|
Retrieve the socket options one at a time by name. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/getsockopt.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [in] level Option protocol level
|
||||||
|
@param [in] OptionName Name of the option
|
||||||
|
@param [out] pOptionValue Buffer to receive the option value
|
||||||
|
@param [in,out] pOptionLength Length of the buffer in bytes,
|
||||||
|
upon return length of the option value in bytes
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_OPTION_GET) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int level,
|
||||||
|
IN int OptionName,
|
||||||
|
OUT void * __restrict pOptionValue,
|
||||||
|
IN OUT socklen_t * __restrict pOptionLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the socket options
|
||||||
|
|
||||||
|
Adjust the socket options one at a time by name. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/setsockopt.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
@param [in] level Option protocol level
|
||||||
|
@param [in] OptionName Name of the option
|
||||||
|
@param [in] pOptionValue Buffer containing the option value
|
||||||
|
@param [in] OptionLength Length of the buffer in bytes
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_OPTION_SET) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int level,
|
||||||
|
IN int OptionName,
|
||||||
|
IN CONST void * pOptionValue,
|
||||||
|
IN socklen_t OptionLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Poll a socket for pending activity.
|
||||||
|
|
||||||
|
The SocketPoll routine checks a socket for pending activity associated
|
||||||
|
with the event mask. Activity is returned in the detected event buffer.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Events Events of interest for this socket
|
||||||
|
|
||||||
|
@param [in] pEvents Address to receive the detected events
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully polled
|
||||||
|
@retval EFI_INVALID_PARAMETER - When pEvents is NULL
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_POLL) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN short Events,
|
||||||
|
IN short * pEvents,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Receive data from a network connection.
|
||||||
|
|
||||||
|
The ::recv routine waits for receive data from a remote network
|
||||||
|
connection. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html">POSIX</a>
|
||||||
|
documentation is available online.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Flags Message control flags
|
||||||
|
|
||||||
|
@param [in] BufferLength Length of the the buffer
|
||||||
|
|
||||||
|
@param [in] pBuffer Address of a buffer to receive the data.
|
||||||
|
|
||||||
|
@param [in] pDataLength Number of received data bytes in the buffer.
|
||||||
|
|
||||||
|
@param [out] pAddress Network address to receive the remote system address
|
||||||
|
|
||||||
|
@param [in,out] pAddressLength Length of the remote network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully received
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_RECEIVE) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int Flags,
|
||||||
|
IN size_t BufferLength,
|
||||||
|
IN UINT8 * pBuffer,
|
||||||
|
OUT size_t * pDataLength,
|
||||||
|
OUT struct sockaddr * pAddress,
|
||||||
|
IN OUT socklen_t * pAddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Send data using a network connection.
|
||||||
|
|
||||||
|
The SocketTransmit routine queues the data for transmission to the
|
||||||
|
remote network connection.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] Flags Message control flags
|
||||||
|
|
||||||
|
@param [in] BufferLength Length of the the buffer
|
||||||
|
|
||||||
|
@param [in] pBuffer Address of a buffer containing the data to send
|
||||||
|
|
||||||
|
@param [in] pDataLength Address to receive the number of data bytes sent
|
||||||
|
|
||||||
|
@param [in] pAddress Network address of the remote system address
|
||||||
|
|
||||||
|
@param [in] AddressLength Length of the remote network address structure
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket data successfully queued for transmission
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_SEND) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int Flags,
|
||||||
|
IN size_t BufferLength,
|
||||||
|
IN CONST UINT8 * pBuffer,
|
||||||
|
OUT size_t * pDataLength,
|
||||||
|
IN const struct sockaddr * pAddress,
|
||||||
|
IN socklen_t AddressLength,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Shutdown the socket receive and transmit operations
|
||||||
|
|
||||||
|
The SocketShutdown routine stops the socket receive and transmit
|
||||||
|
operations.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] How Which operations to stop
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket operations successfully shutdown
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(* PFN_SHUTDOWN) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int How,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Initialize an endpoint for network communication.
|
||||||
|
|
||||||
|
The ::Socket routine initializes the communication endpoint by providing
|
||||||
|
the support for the socket library function ::socket. The
|
||||||
|
<a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html">POSIX</a>
|
||||||
|
documentation for the socket routine is available online for reference.
|
||||||
|
|
||||||
|
@param [in] pSocketProtocol Address of the socket protocol structure.
|
||||||
|
|
||||||
|
@param [in] domain Select the family of protocols for the client or server
|
||||||
|
application.
|
||||||
|
|
||||||
|
@param [in] type Specifies how to make the network connection. The following values
|
||||||
|
are supported:
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
SOCK_STREAM - Connect to TCP, provides a byte stream
|
||||||
|
that is manipluated by read, recv, send and write.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
SOCK_SEQPACKET - Connect to TCP, provides sequenced packet stream
|
||||||
|
that is manipulated by read, recv, send and write.
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
SOCK_DGRAM - Connect to UDP, provides a datagram service that is
|
||||||
|
manipulated by recvfrom and sendto.
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
@param [in] protocol Specifies the lower layer protocol to use. The following
|
||||||
|
values are supported:
|
||||||
|
<ul>
|
||||||
|
<li>IPPROTO_TCP</li> - This value must be combined with SOCK_STREAM.</li>
|
||||||
|
<li>IPPROTO_UDP</li> - This value must be combined with SOCK_DGRAM.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
@param [out] pErrno Address to receive the errno value upon completion.
|
||||||
|
|
||||||
|
@retval EFI_SUCCESS - Socket successfully created
|
||||||
|
@retval EFI_INVALID_PARAMETER - Invalid domain value, errno = EAFNOSUPPORT
|
||||||
|
@retval EFI_INVALID_PARAMETER - Invalid type value, errno = EINVAL
|
||||||
|
@retval EFI_INVALID_PARAMETER - Invalid protocol value, errno = EINVAL
|
||||||
|
|
||||||
|
**/
|
||||||
|
typedef
|
||||||
|
EFI_STATUS
|
||||||
|
(*PFN_SOCKET) (
|
||||||
|
IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
|
||||||
|
IN int domain,
|
||||||
|
IN int type,
|
||||||
|
IN int protocol,
|
||||||
|
IN int * pErrno
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Socket Protocol
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Socket protocol declaration
|
||||||
|
**/
|
||||||
|
typedef struct _EFI_SOCKET_PROTOCOL {
|
||||||
|
EFI_HANDLE SocketHandle; ///< Handle for the socket
|
||||||
|
PFN_ACCEPT pfnAccept; ///< Accept a network connection
|
||||||
|
PFN_BIND pfnBind; ///< Bind a local address to the socket
|
||||||
|
PFN_CLOSE_POLL pfnClosePoll; ///< Determine if the socket is closed
|
||||||
|
PFN_CLOSE_START pfnCloseStart; ///< Start the close operation
|
||||||
|
PFN_CONNECT pfnConnect; ///< Connect to a remote system
|
||||||
|
PFN_GET_LOCAL pfnGetLocal; ///< Get local address
|
||||||
|
PFN_GET_PEER pfnGetPeer; ///< Get peer address
|
||||||
|
PFN_LISTEN pfnListen; ///< Enable connection attempts on known port
|
||||||
|
PFN_POLL pfnPoll; ///< Poll for socket activity
|
||||||
|
PFN_OPTION_GET pfnOptionGet; ///< Get socket options
|
||||||
|
PFN_OPTION_SET pfnOptionSet; ///< Set socket options
|
||||||
|
PFN_RECEIVE pfnReceive; ///< Receive data from a socket
|
||||||
|
PFN_SEND pfnSend; ///< Transmit data using the socket
|
||||||
|
PFN_SHUTDOWN pfnShutdown; ///< Shutdown receive and transmit operations
|
||||||
|
PFN_SOCKET pfnSocket; ///< Initialize the socket
|
||||||
|
} GCC_EFI_SOCKET_PROTOCOL;
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// Non-blocking routines
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
Non blocking version of accept.
|
||||||
|
|
||||||
|
See ::accept
|
||||||
|
|
||||||
|
@param [in] s Socket file descriptor returned from ::socket.
|
||||||
|
|
||||||
|
@param [in] address Address of a buffer to receive the remote network address.
|
||||||
|
|
||||||
|
@param [in, out] address_len Address of a buffer containing the Length in bytes
|
||||||
|
of the remote network address buffer. Upon return,
|
||||||
|
contains the length of the remote network address.
|
||||||
|
|
||||||
|
@returns This routine returns zero if successful and -1 when an error occurs.
|
||||||
|
In the case of an error, errno contains more details.
|
||||||
|
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
AcceptNB (
|
||||||
|
int s,
|
||||||
|
struct sockaddr * address,
|
||||||
|
socklen_t * address_len
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Connect to the socket driver
|
||||||
|
|
||||||
|
@param [in] ppSocketProtocol Address to receive the socket protocol address
|
||||||
|
|
||||||
|
@retval 0 Successfully returned the socket protocol
|
||||||
|
@retval other Value for errno
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
EslServiceGetProtocol (
|
||||||
|
IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
|
||||||
|
);
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif // _EFI_SOCKET_H_
|
@ -1,3 +1,25 @@
|
|||||||
#include <x86/limits.h>
|
#include <x86/limits.h>
|
||||||
|
|
||||||
#define __POINTER_BIT 64
|
#define __POINTER_BIT 64
|
||||||
|
|
||||||
|
#if defined(__GNUC__)
|
||||||
|
#define __LONG_BIT 64
|
||||||
|
/** minimum value for an object of type long int **/
|
||||||
|
#define __LONG_MIN (-9223372036854775807L - 1L) // -(2^63 - 1)
|
||||||
|
|
||||||
|
/** maximum value for an object of type long int **/
|
||||||
|
#define __LONG_MAX +9223372036854775807L // 2^63 - 1
|
||||||
|
|
||||||
|
/** maximum value for an object of type unsigned long int **/
|
||||||
|
#define __ULONG_MAX 0xFFFFFFFFFFFFFFFFUL // 2^64 - 1
|
||||||
|
#else
|
||||||
|
#define __LONG_BIT 32
|
||||||
|
/** minimum value for an object of type long int **/
|
||||||
|
#define __LONG_MIN (-2147483647L - 1L) // -(2^31 - 1)
|
||||||
|
|
||||||
|
/** maximum value for an object of type long int **/
|
||||||
|
#define __LONG_MAX +2147483647L // 2^31 - 1
|
||||||
|
|
||||||
|
/** maximum value for an object of type unsigned long int **/
|
||||||
|
#define __ULONG_MAX 0xffffffff // 2^32 - 1
|
||||||
|
#endif
|
||||||
|
109
StdLib/Include/arpa/ftp.h
Normal file
109
StdLib/Include/arpa/ftp.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)ftp.h 8.1 (Berkeley) 6/2/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ARPA_FTP_H_
|
||||||
|
#define _ARPA_FTP_H_
|
||||||
|
|
||||||
|
/* Definitions for FTP; see RFC-765. */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reply codes.
|
||||||
|
*/
|
||||||
|
#define PRELIM 1 /* positive preliminary */
|
||||||
|
#define COMPLETE 2 /* positive completion */
|
||||||
|
#define CONTINUE 3 /* positive intermediate */
|
||||||
|
#define TRANSIENT 4 /* transient negative completion */
|
||||||
|
#define ERROR 5 /* permanent negative completion */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Type codes
|
||||||
|
*/
|
||||||
|
#define TYPE_A 1 /* ASCII */
|
||||||
|
#define TYPE_E 2 /* EBCDIC */
|
||||||
|
#define TYPE_I 3 /* image */
|
||||||
|
#define TYPE_L 4 /* local byte size */
|
||||||
|
|
||||||
|
#ifdef FTP_NAMES
|
||||||
|
char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Form codes
|
||||||
|
*/
|
||||||
|
#define FORM_N 1 /* non-print */
|
||||||
|
#define FORM_T 2 /* telnet format effectors */
|
||||||
|
#define FORM_C 3 /* carriage control (ASA) */
|
||||||
|
#ifdef FTP_NAMES
|
||||||
|
char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure codes
|
||||||
|
*/
|
||||||
|
#define STRU_F 1 /* file (no record structure) */
|
||||||
|
#define STRU_R 2 /* record structure */
|
||||||
|
#define STRU_P 3 /* page structure */
|
||||||
|
#ifdef FTP_NAMES
|
||||||
|
char *strunames[] = {"0", "File", "Record", "Page" };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Mode types
|
||||||
|
*/
|
||||||
|
#define MODE_S 1 /* stream */
|
||||||
|
#define MODE_B 2 /* block */
|
||||||
|
#define MODE_C 3 /* compressed */
|
||||||
|
#ifdef FTP_NAMES
|
||||||
|
char *modenames[] = {"0", "Stream", "Block", "Compressed" };
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Record Tokens
|
||||||
|
*/
|
||||||
|
#define REC_ESC '\377' /* Record-mode Escape */
|
||||||
|
#define REC_EOR '\001' /* Record-mode End-of-Record */
|
||||||
|
#define REC_EOF '\002' /* Record-mode End-of-File */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Block Header
|
||||||
|
*/
|
||||||
|
#define BLK_EOR 0x80 /* Block is End-of-Record */
|
||||||
|
#define BLK_EOF 0x40 /* Block is End-of-File */
|
||||||
|
#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */
|
||||||
|
#define BLK_RESTART 0x10 /* Block is Restart Marker */
|
||||||
|
|
||||||
|
#define BLK_BYTECOUNT 2 /* Bytes in this block */
|
||||||
|
|
||||||
|
#endif /* !_FTP_H_ */
|
@ -126,6 +126,10 @@ struct _ns_flagdata { int mask, shift; };
|
|||||||
extern struct _ns_flagdata _ns_flagdata[];
|
extern struct _ns_flagdata _ns_flagdata[];
|
||||||
|
|
||||||
/* Accessor macros - this is part of the public interface. */
|
/* Accessor macros - this is part of the public interface. */
|
||||||
|
#define ns_msg_getflag(handle, flag) ( \
|
||||||
|
((handle)._flags & _ns_flagdata[flag].mask) \
|
||||||
|
>> _ns_flagdata[flag].shift \
|
||||||
|
)
|
||||||
|
|
||||||
#define ns_msg_id(handle) ((handle)._id + 0)
|
#define ns_msg_id(handle) ((handle)._id + 0)
|
||||||
#define ns_msg_base(handle) ((handle)._msg + 0)
|
#define ns_msg_base(handle) ((handle)._msg + 0)
|
||||||
@ -217,6 +221,28 @@ typedef enum __ns_update_operation {
|
|||||||
ns_uop_max = 2
|
ns_uop_max = 2
|
||||||
} ns_update_operation;
|
} ns_update_operation;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This RR-like structure is particular to UPDATE.
|
||||||
|
*/
|
||||||
|
struct _ns_updrec {
|
||||||
|
struct _ns_updrec *r_prev; /* prev record */
|
||||||
|
struct _ns_updrec *r_next; /* next record */
|
||||||
|
u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */
|
||||||
|
char * r_dname; /* owner of the RR */
|
||||||
|
u_int16_t r_class; /* class number */
|
||||||
|
u_int16_t r_type; /* type number */
|
||||||
|
u_int32_t r_ttl; /* time to live */
|
||||||
|
u_char * r_data; /* rdata fields as text string */
|
||||||
|
u_int16_t r_size; /* size of r_data field */
|
||||||
|
int r_opcode; /* type of operation */
|
||||||
|
/* following fields for private use by the resolver/server routines */
|
||||||
|
struct _ns_updrec *r_grpnext; /* next record when grouped */
|
||||||
|
struct databuf *r_dp; /* databuf to process */
|
||||||
|
struct databuf *r_deldp; /* databuf's deleted/overwritten */
|
||||||
|
u_int16_t r_zone; /* zone number on server */
|
||||||
|
};
|
||||||
|
typedef struct _ns_updrec ns_updrec;
|
||||||
|
|
||||||
/*%
|
/*%
|
||||||
* This structure is used for TSIG authenticated messages
|
* This structure is used for TSIG authenticated messages
|
||||||
*/
|
*/
|
||||||
@ -456,25 +482,24 @@ typedef enum __ns_cert_types {
|
|||||||
#define NS_PUT16(s, cp) do { \
|
#define NS_PUT16(s, cp) do { \
|
||||||
uint32_t t_s = (uint32_t)(s); \
|
uint32_t t_s = (uint32_t)(s); \
|
||||||
u_char *t_cp = (u_char *)(cp); \
|
u_char *t_cp = (u_char *)(cp); \
|
||||||
*t_cp++ = t_s >> 8; \
|
*t_cp++ = (u_char)( t_s >> 8 ); \
|
||||||
*t_cp = t_s; \
|
*t_cp = (u_char)( t_s ); \
|
||||||
(cp) += NS_INT16SZ; \
|
(cp) += NS_INT16SZ; \
|
||||||
} while (/*CONSTCOND*/0)
|
} while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
#define NS_PUT32(l, cp) do { \
|
#define NS_PUT32(l, cp) do { \
|
||||||
uint32_t t_l = (uint32_t)(l); \
|
uint32_t t_l = (uint32_t)(l); \
|
||||||
u_char *t_cp = (u_char *)(cp); \
|
u_char *t_cp = (u_char *)(cp); \
|
||||||
*t_cp++ = t_l >> 24; \
|
*t_cp++ = (u_char)( t_l >> 24 ); \
|
||||||
*t_cp++ = t_l >> 16; \
|
*t_cp++ = (u_char)( t_l >> 16 ); \
|
||||||
*t_cp++ = t_l >> 8; \
|
*t_cp++ = (u_char)( t_l >> 8 ); \
|
||||||
*t_cp = t_l; \
|
*t_cp = (u_char)( t_l ); \
|
||||||
(cp) += NS_INT32SZ; \
|
(cp) += NS_INT32SZ; \
|
||||||
} while (/*CONSTCOND*/0)
|
} while (/*CONSTCOND*/0)
|
||||||
|
|
||||||
/*%
|
/*%
|
||||||
* ANSI C identifier hiding for bind's lib/nameser.
|
* ANSI C identifier hiding for bind's lib/nameser.
|
||||||
*/
|
*/
|
||||||
#define ns_msg_getflag __ns_msg_getflag
|
|
||||||
#define ns_get16 __ns_get16
|
#define ns_get16 __ns_get16
|
||||||
#define ns_get32 __ns_get32
|
#define ns_get32 __ns_get32
|
||||||
#define ns_put16 __ns_put16
|
#define ns_put16 __ns_put16
|
||||||
@ -511,7 +536,6 @@ typedef enum __ns_cert_types {
|
|||||||
#define ns_samename __ns_samename
|
#define ns_samename __ns_samename
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
int ns_msg_getflag(ns_msg, int);
|
|
||||||
uint16_t ns_get16(const u_char *);
|
uint16_t ns_get16(const u_char *);
|
||||||
uint32_t ns_get32(const u_char *);
|
uint32_t ns_get32(const u_char *);
|
||||||
void ns_put16(uint16_t, u_char *);
|
void ns_put16(uint16_t, u_char *);
|
||||||
|
340
StdLib/Include/arpa/telnet.h
Normal file
340
StdLib/Include/arpa/telnet.h
Normal file
@ -0,0 +1,340 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1983, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)telnet.h 8.2 (Berkeley) 12/15/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ARPA_TELNET_H_
|
||||||
|
#define _ARPA_TELNET_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definitions for the TELNET protocol.
|
||||||
|
*/
|
||||||
|
#define IAC 255 /* interpret as command: */
|
||||||
|
#define DONT 254 /* you are not to use option */
|
||||||
|
#define DO 253 /* please, you use option */
|
||||||
|
#define WONT 252 /* I won't use option */
|
||||||
|
#define WILL 251 /* I will use option */
|
||||||
|
#define SB 250 /* interpret as subnegotiation */
|
||||||
|
#define GA 249 /* you may reverse the line */
|
||||||
|
#define EL 248 /* erase the current line */
|
||||||
|
#define EC 247 /* erase the current character */
|
||||||
|
#define AYT 246 /* are you there */
|
||||||
|
#define AO 245 /* abort output--but let prog finish */
|
||||||
|
#define IP 244 /* interrupt process--permanently */
|
||||||
|
#define BREAK 243 /* break */
|
||||||
|
#define DM 242 /* data mark--for connect. cleaning */
|
||||||
|
#define NOP 241 /* nop */
|
||||||
|
#define SE 240 /* end sub negotiation */
|
||||||
|
#define EOR 239 /* end of record (transparent mode) */
|
||||||
|
#define ABORT 238 /* Abort process */
|
||||||
|
#define SUSP 237 /* Suspend process */
|
||||||
|
#define xEOF 236 /* End of file: EOF is already used... */
|
||||||
|
|
||||||
|
#define SYNCH 242 /* for telfunc calls */
|
||||||
|
|
||||||
|
#ifdef TELCMDS
|
||||||
|
char *telcmds[] = {
|
||||||
|
"EOF", "SUSP", "ABORT", "EOR",
|
||||||
|
"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
|
||||||
|
"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
extern char *telcmds[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TELCMD_FIRST xEOF
|
||||||
|
#define TELCMD_LAST IAC
|
||||||
|
#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \
|
||||||
|
(unsigned int)(x) >= TELCMD_FIRST)
|
||||||
|
#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
|
||||||
|
|
||||||
|
/* telnet options */
|
||||||
|
#define TELOPT_BINARY 0 /* 8-bit data path */
|
||||||
|
#define TELOPT_ECHO 1 /* echo */
|
||||||
|
#define TELOPT_RCP 2 /* prepare to reconnect */
|
||||||
|
#define TELOPT_SGA 3 /* suppress go ahead */
|
||||||
|
#define TELOPT_NAMS 4 /* approximate message size */
|
||||||
|
#define TELOPT_STATUS 5 /* give status */
|
||||||
|
#define TELOPT_TM 6 /* timing mark */
|
||||||
|
#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
|
||||||
|
#define TELOPT_NAOL 8 /* negotiate about output line width */
|
||||||
|
#define TELOPT_NAOP 9 /* negotiate about output page size */
|
||||||
|
#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
|
||||||
|
#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
|
||||||
|
#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
|
||||||
|
#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
|
||||||
|
#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
|
||||||
|
#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
|
||||||
|
#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
|
||||||
|
#define TELOPT_XASCII 17 /* extended ascic character set */
|
||||||
|
#define TELOPT_LOGOUT 18 /* force logout */
|
||||||
|
#define TELOPT_BM 19 /* byte macro */
|
||||||
|
#define TELOPT_DET 20 /* data entry terminal */
|
||||||
|
#define TELOPT_SUPDUP 21 /* supdup protocol */
|
||||||
|
#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
|
||||||
|
#define TELOPT_SNDLOC 23 /* send location */
|
||||||
|
#define TELOPT_TTYPE 24 /* terminal type */
|
||||||
|
#define TELOPT_EOR 25 /* end or record */
|
||||||
|
#define TELOPT_TUID 26 /* TACACS user identification */
|
||||||
|
#define TELOPT_OUTMRK 27 /* output marking */
|
||||||
|
#define TELOPT_TTYLOC 28 /* terminal location number */
|
||||||
|
#define TELOPT_3270REGIME 29 /* 3270 regime */
|
||||||
|
#define TELOPT_X3PAD 30 /* X.3 PAD */
|
||||||
|
#define TELOPT_NAWS 31 /* window size */
|
||||||
|
#define TELOPT_TSPEED 32 /* terminal speed */
|
||||||
|
#define TELOPT_LFLOW 33 /* remote flow control */
|
||||||
|
#define TELOPT_LINEMODE 34 /* Linemode option */
|
||||||
|
#define TELOPT_XDISPLOC 35 /* X Display Location */
|
||||||
|
#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
|
||||||
|
#define TELOPT_AUTHENTICATION 37/* Authenticate */
|
||||||
|
#define TELOPT_ENCRYPT 38 /* Encryption option */
|
||||||
|
#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
|
||||||
|
#define TELOPT_EXOPL 255 /* extended-options-list */
|
||||||
|
|
||||||
|
|
||||||
|
#define NTELOPTS (1+TELOPT_NEW_ENVIRON)
|
||||||
|
#ifdef TELOPTS
|
||||||
|
char *telopts[NTELOPTS+1] = {
|
||||||
|
"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
|
||||||
|
"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
|
||||||
|
"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
|
||||||
|
"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
|
||||||
|
"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
|
||||||
|
"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
|
||||||
|
"TACACS UID", "OUTPUT MARKING", "TTYLOC",
|
||||||
|
"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
|
||||||
|
"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
|
||||||
|
"ENCRYPT", "NEW-ENVIRON",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#define TELOPT_FIRST TELOPT_BINARY
|
||||||
|
#define TELOPT_LAST TELOPT_NEW_ENVIRON
|
||||||
|
#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST)
|
||||||
|
#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* sub-option qualifiers */
|
||||||
|
#define TELQUAL_IS 0 /* option is... */
|
||||||
|
#define TELQUAL_SEND 1 /* send option */
|
||||||
|
#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
|
||||||
|
#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */
|
||||||
|
#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */
|
||||||
|
|
||||||
|
#define LFLOW_OFF 0 /* Disable remote flow control */
|
||||||
|
#define LFLOW_ON 1 /* Enable remote flow control */
|
||||||
|
#define LFLOW_RESTART_ANY 2 /* Restart output on any char */
|
||||||
|
#define LFLOW_RESTART_XON 3 /* Restart output only on XON */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LINEMODE suboptions
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define LM_MODE 1
|
||||||
|
#define LM_FORWARDMASK 2
|
||||||
|
#define LM_SLC 3
|
||||||
|
|
||||||
|
#define MODE_EDIT 0x01
|
||||||
|
#define MODE_TRAPSIG 0x02
|
||||||
|
#define MODE_ACK 0x04
|
||||||
|
#define MODE_SOFT_TAB 0x08
|
||||||
|
#define MODE_LIT_ECHO 0x10
|
||||||
|
|
||||||
|
#define MODE_MASK 0x1f
|
||||||
|
|
||||||
|
/* Not part of protocol, but needed to simplify things... */
|
||||||
|
#define MODE_FLOW 0x0100
|
||||||
|
#define MODE_ECHO 0x0200
|
||||||
|
#define MODE_INBIN 0x0400
|
||||||
|
#define MODE_OUTBIN 0x0800
|
||||||
|
#define MODE_FORCE 0x1000
|
||||||
|
|
||||||
|
#define SLC_SYNCH 1
|
||||||
|
#define SLC_BRK 2
|
||||||
|
#define SLC_IP 3
|
||||||
|
#define SLC_AO 4
|
||||||
|
#define SLC_AYT 5
|
||||||
|
#define SLC_EOR 6
|
||||||
|
#define SLC_ABORT 7
|
||||||
|
#define SLC_EOF 8
|
||||||
|
#define SLC_SUSP 9
|
||||||
|
#define SLC_EC 10
|
||||||
|
#define SLC_EL 11
|
||||||
|
#define SLC_EW 12
|
||||||
|
#define SLC_RP 13
|
||||||
|
#define SLC_LNEXT 14
|
||||||
|
#define SLC_XON 15
|
||||||
|
#define SLC_XOFF 16
|
||||||
|
#define SLC_FORW1 17
|
||||||
|
#define SLC_FORW2 18
|
||||||
|
#define SLC_MCL 19
|
||||||
|
#define SLC_MCR 20
|
||||||
|
#define SLC_MCWL 21
|
||||||
|
#define SLC_MCWR 22
|
||||||
|
#define SLC_MCBOL 23
|
||||||
|
#define SLC_MCEOL 24
|
||||||
|
#define SLC_INSRT 25
|
||||||
|
#define SLC_OVER 26
|
||||||
|
#define SLC_ECR 27
|
||||||
|
#define SLC_EWR 28
|
||||||
|
#define SLC_EBOL 29
|
||||||
|
#define SLC_EEOL 30
|
||||||
|
|
||||||
|
#define NSLC 30
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For backwards compatability, we define SLC_NAMES to be the
|
||||||
|
* list of names if SLC_NAMES is not defined.
|
||||||
|
*/
|
||||||
|
#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
|
||||||
|
"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
|
||||||
|
"LNEXT", "XON", "XOFF", "FORW1", "FORW2", \
|
||||||
|
"MCL", "MCR", "MCWL", "MCWR", "MCBOL", \
|
||||||
|
"MCEOL", "INSRT", "OVER", "ECR", "EWR", \
|
||||||
|
"EBOL", "EEOL", \
|
||||||
|
0
|
||||||
|
|
||||||
|
#ifdef SLC_NAMES
|
||||||
|
char *slc_names[] = {
|
||||||
|
SLC_NAMELIST
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
extern char *slc_names[];
|
||||||
|
#define SLC_NAMES SLC_NAMELIST
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC)
|
||||||
|
#define SLC_NAME(x) slc_names[x]
|
||||||
|
|
||||||
|
#define SLC_NOSUPPORT 0
|
||||||
|
#define SLC_CANTCHANGE 1
|
||||||
|
#define SLC_VARIABLE 2
|
||||||
|
#define SLC_DEFAULT 3
|
||||||
|
#define SLC_LEVELBITS 0x03
|
||||||
|
|
||||||
|
#define SLC_FUNC 0
|
||||||
|
#define SLC_FLAGS 1
|
||||||
|
#define SLC_VALUE 2
|
||||||
|
|
||||||
|
#define SLC_ACK 0x80
|
||||||
|
#define SLC_FLUSHIN 0x40
|
||||||
|
#define SLC_FLUSHOUT 0x20
|
||||||
|
|
||||||
|
#define OLD_ENV_VAR 1
|
||||||
|
#define OLD_ENV_VALUE 0
|
||||||
|
#define NEW_ENV_VAR 0
|
||||||
|
#define NEW_ENV_VALUE 1
|
||||||
|
#define ENV_ESC 2
|
||||||
|
#define ENV_USERVAR 3
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AUTHENTICATION suboptions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Who is authenticating who ...
|
||||||
|
*/
|
||||||
|
#define AUTH_WHO_CLIENT 0 /* Client authenticating server */
|
||||||
|
#define AUTH_WHO_SERVER 1 /* Server authenticating client */
|
||||||
|
#define AUTH_WHO_MASK 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* amount of authentication done
|
||||||
|
*/
|
||||||
|
#define AUTH_HOW_ONE_WAY 0
|
||||||
|
#define AUTH_HOW_MUTUAL 2
|
||||||
|
#define AUTH_HOW_MASK 2
|
||||||
|
|
||||||
|
#define AUTHTYPE_NULL 0
|
||||||
|
#define AUTHTYPE_KERBEROS_V4 1
|
||||||
|
#define AUTHTYPE_KERBEROS_V5 2
|
||||||
|
#define AUTHTYPE_SPX 3
|
||||||
|
#define AUTHTYPE_MINK 4
|
||||||
|
#define AUTHTYPE_CNT 5
|
||||||
|
|
||||||
|
#define AUTHTYPE_TEST 99
|
||||||
|
|
||||||
|
#ifdef AUTH_NAMES
|
||||||
|
char *authtype_names[] = {
|
||||||
|
"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
extern char *authtype_names[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT)
|
||||||
|
#define AUTHTYPE_NAME(x) authtype_names[x]
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ENCRYPTion suboptions
|
||||||
|
*/
|
||||||
|
#define ENCRYPT_IS 0 /* I pick encryption type ... */
|
||||||
|
#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
|
||||||
|
#define ENCRYPT_REPLY 2 /* Initial setup response */
|
||||||
|
#define ENCRYPT_START 3 /* Am starting to send encrypted */
|
||||||
|
#define ENCRYPT_END 4 /* Am ending encrypted */
|
||||||
|
#define ENCRYPT_REQSTART 5 /* Request you start encrypting */
|
||||||
|
#define ENCRYPT_REQEND 6 /* Request you end encrypting */
|
||||||
|
#define ENCRYPT_ENC_KEYID 7
|
||||||
|
#define ENCRYPT_DEC_KEYID 8
|
||||||
|
#define ENCRYPT_CNT 9
|
||||||
|
|
||||||
|
#define ENCTYPE_ANY 0
|
||||||
|
#define ENCTYPE_DES_CFB64 1
|
||||||
|
#define ENCTYPE_DES_OFB64 2
|
||||||
|
#define ENCTYPE_CNT 3
|
||||||
|
|
||||||
|
#ifdef ENCRYPT_NAMES
|
||||||
|
char *encrypt_names[] = {
|
||||||
|
"IS", "SUPPORT", "REPLY", "START", "END",
|
||||||
|
"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
char *enctype_names[] = {
|
||||||
|
"ANY", "DES_CFB64", "DES_OFB64",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
#else
|
||||||
|
extern char *encrypt_names[];
|
||||||
|
extern char *enctype_names[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT)
|
||||||
|
#define ENCRYPT_NAME(x) encrypt_names[x]
|
||||||
|
|
||||||
|
#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
|
||||||
|
#define ENCTYPE_NAME(x) enctype_names[x]
|
||||||
|
|
||||||
|
#endif /* !_TELNET_H_ */
|
25
StdLib/Include/err.h
Normal file
25
StdLib/Include/err.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/** @file error and warning output messages
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
|
This program and the accompanying materials
|
||||||
|
are licensed and made available under the terms and conditions of the BSD License
|
||||||
|
which accompanies this distribution. The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
**/
|
||||||
|
|
||||||
|
#ifndef _ERR_H_
|
||||||
|
#define _ERR_H_
|
||||||
|
|
||||||
|
//
|
||||||
|
// Error and Warning outputs
|
||||||
|
//
|
||||||
|
|
||||||
|
void errx (int eval, const char *fmt, ...);
|
||||||
|
void err (int eval, const char *fmt, ...);
|
||||||
|
void warnx(const char *fmt, ...);
|
||||||
|
void warn (const char *fmt, ...);
|
||||||
|
|
||||||
|
#endif
|
@ -34,6 +34,8 @@ extern RETURN_STATUS EFIerrno;
|
|||||||
|
|
||||||
// Define error number in terms of the ENUM in <sys/errno.h>
|
// Define error number in terms of the ENUM in <sys/errno.h>
|
||||||
|
|
||||||
|
#define ERESTART -1 /* restart syscall */
|
||||||
|
|
||||||
#define EMINERRORVAL __EMINERRORVAL /* The lowest valid error value */
|
#define EMINERRORVAL __EMINERRORVAL /* The lowest valid error value */
|
||||||
|
|
||||||
#define EPERM __EPERM /* 1 Operation not permitted */
|
#define EPERM __EPERM /* 1 Operation not permitted */
|
||||||
|
109
StdLib/Include/glob.h
Normal file
109
StdLib/Include/glob.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
/* $NetBSD: glob.h,v 1.24 2008/09/13 17:05:07 christos Exp $ */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* This code is derived from software contributed to Berkeley by
|
||||||
|
* Guido van Rossum.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)glob.h 8.1 (Berkeley) 6/2/93
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GLOB_H_
|
||||||
|
#define _GLOB_H_
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <sys/featuretest.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#ifndef __gl_size_t
|
||||||
|
#define __gl_size_t size_t
|
||||||
|
#endif
|
||||||
|
#ifndef __gl_stat_t
|
||||||
|
#define __gl_stat_t struct stat
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
__gl_size_t gl_pathc; /* Count of total paths so far. */
|
||||||
|
__gl_size_t gl_matchc; /* Count of paths matching pattern. */
|
||||||
|
__gl_size_t gl_offs; /* Reserved at beginning of gl_pathv. */
|
||||||
|
int gl_flags; /* Copy of flags parameter to glob. */
|
||||||
|
char **gl_pathv; /* List of paths matching pattern. */
|
||||||
|
/* Copy of errfunc parameter to glob. */
|
||||||
|
int (*gl_errfunc)(const char *, int);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Alternate filesystem access methods for glob; replacement
|
||||||
|
* versions of closedir(3), readdir(3), opendir(3), stat(2)
|
||||||
|
* and lstat(2).
|
||||||
|
*/
|
||||||
|
void (*gl_closedir)(void *);
|
||||||
|
struct dirent *(*gl_readdir)(void *);
|
||||||
|
void *(*gl_opendir)(const char *);
|
||||||
|
int (*gl_lstat)(const char *, __gl_stat_t *);
|
||||||
|
int (*gl_stat)(const char *, __gl_stat_t *);
|
||||||
|
} glob_t;
|
||||||
|
|
||||||
|
#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
|
||||||
|
#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
|
||||||
|
#define GLOB_ERR 0x0004 /* Return on error. */
|
||||||
|
#define GLOB_MARK 0x0008 /* Append / to matching directories. */
|
||||||
|
#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
|
||||||
|
#define GLOB_NOSORT 0x0020 /* Don't sort. */
|
||||||
|
#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */
|
||||||
|
|
||||||
|
#define GLOB_NOSPACE (-1) /* Malloc call failed. */
|
||||||
|
#define GLOB_ABORTED (-2) /* Unignored error. */
|
||||||
|
#define GLOB_NOMATCH (-3) /* No match, and GLOB_NOCHECK was not set. */
|
||||||
|
#define GLOB_NOSYS (-4) /* Implementation does not support function. */
|
||||||
|
|
||||||
|
#if defined(_NETBSD_SOURCE) || defined(HAVE_NBTOOL_CONFIG_H)
|
||||||
|
#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
|
||||||
|
#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
|
||||||
|
#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
|
||||||
|
#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
|
||||||
|
#define GLOB_LIMIT 0x0400 /* Limit memory used by matches to ARG_MAX */
|
||||||
|
#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
|
||||||
|
/* GLOB_NOESCAPE 0x1000 above */
|
||||||
|
#define GLOB_PERIOD 0x2000 /* Allow metachars to match leading periods. */
|
||||||
|
#define GLOB_NO_DOTDIRS 0x4000 /* Make . and .. vanish from wildcards. */
|
||||||
|
#define GLOB_QUOTE 0 /* source compatibility */
|
||||||
|
|
||||||
|
#define GLOB_ABEND GLOB_ABORTED /* source compatibility */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
#ifndef __LIBC12_SOURCE__
|
||||||
|
int glob(const char * __restrict, int,
|
||||||
|
int (*)(const char *, int), glob_t * __restrict) __RENAME(__glob30);
|
||||||
|
void globfree(glob_t *) __RENAME(__globfree30);
|
||||||
|
#endif
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* !_GLOB_H_ */
|
14
StdLib/Include/libgen.h
Normal file
14
StdLib/Include/libgen.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/** @file
|
||||||
|
|
||||||
|
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
|
||||||
|
This program and the accompanying materials are licensed and made available under
|
||||||
|
the terms and conditions of the BSD License that accompanies this distribution.
|
||||||
|
The full text of the license may be found at
|
||||||
|
http://opensource.org/licenses/bsd-license.php.
|
||||||
|
|
||||||
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
char *dirname(char *path);
|
227
StdLib/Include/net/if.h
Normal file
227
StdLib/Include/net/if.h
Normal file
@ -0,0 +1,227 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1982, 1986, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)if.h 8.1 (Berkeley) 6/10/93
|
||||||
|
* $Id: if.h,v 1.1.1.1 2006/05/30 06:12:41 hhzhou Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NET_IF_H_
|
||||||
|
#define _NET_IF_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* <net/if.h> does not depend on <sys/time.h> on most other systems. This
|
||||||
|
* helps userland compatability. (struct timeval ifi_lastchange)
|
||||||
|
*/
|
||||||
|
#ifndef KERNEL
|
||||||
|
#include <sys/time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure describing information about an interface
|
||||||
|
* which may be of interest to management entities.
|
||||||
|
*/
|
||||||
|
struct if_data {
|
||||||
|
/* generic interface information */
|
||||||
|
u_char ifi_type; /* ethernet, tokenring, etc */
|
||||||
|
u_char ifi_physical; /* e.g., AUI, Thinnet, 10base-T, etc */
|
||||||
|
u_char ifi_addrlen; /* media address length */
|
||||||
|
u_char ifi_hdrlen; /* media header length */
|
||||||
|
u_char ifi_recvquota; /* polling quota for receive intrs */
|
||||||
|
u_char ifi_xmitquota; /* polling quota for xmit intrs */
|
||||||
|
u_long ifi_mtu; /* maximum transmission unit */
|
||||||
|
u_long ifi_metric; /* routing metric (external only) */
|
||||||
|
u_long ifi_baudrate; /* linespeed */
|
||||||
|
/* volatile statistics */
|
||||||
|
u_long ifi_ipackets; /* packets received on interface */
|
||||||
|
u_long ifi_ierrors; /* input errors on interface */
|
||||||
|
u_long ifi_opackets; /* packets sent on interface */
|
||||||
|
u_long ifi_oerrors; /* output errors on interface */
|
||||||
|
u_long ifi_collisions; /* collisions on csma interfaces */
|
||||||
|
u_long ifi_ibytes; /* total number of octets received */
|
||||||
|
u_long ifi_obytes; /* total number of octets sent */
|
||||||
|
u_long ifi_imcasts; /* packets received via multicast */
|
||||||
|
u_long ifi_omcasts; /* packets sent via multicast */
|
||||||
|
u_long ifi_iqdrops; /* dropped on input, this interface */
|
||||||
|
u_long ifi_noproto; /* destined for unsupported protocol */
|
||||||
|
u_long ifi_recvtiming; /* usec spent receiving when timing */
|
||||||
|
u_long ifi_xmittiming; /* usec spent xmitting when timing */
|
||||||
|
struct timeval ifi_lastchange; /* time of last administrative change */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define IFF_UP 0x1 /* interface is up */
|
||||||
|
#define IFF_BROADCAST 0x2 /* broadcast address valid */
|
||||||
|
#define IFF_DEBUG 0x4 /* turn on debugging */
|
||||||
|
#define IFF_LOOPBACK 0x8 /* is a loopback net */
|
||||||
|
#define IFF_POINTOPOINT 0x10 /* interface is point-to-point link */
|
||||||
|
/*#define IFF_NOTRAILERS 0x20 * obsolete: avoid use of trailers */
|
||||||
|
#define IFF_RUNNING 0x40 /* resources allocated */
|
||||||
|
#define IFF_NOARP 0x80 /* no address resolution protocol */
|
||||||
|
#define IFF_PROMISC 0x100 /* receive all packets */
|
||||||
|
#define IFF_ALLMULTI 0x200 /* receive all multicast packets */
|
||||||
|
#define IFF_OACTIVE 0x400 /* transmission in progress */
|
||||||
|
#define IFF_SIMPLEX 0x800 /* can't hear own transmissions */
|
||||||
|
#define IFF_LINK0 0x1000 /* per link layer defined bit */
|
||||||
|
#define IFF_LINK1 0x2000 /* per link layer defined bit */
|
||||||
|
#define IFF_LINK2 0x4000 /* per link layer defined bit */
|
||||||
|
#define IFF_ALTPHYS IFF_LINK2 /* use alternate physical connection */
|
||||||
|
#define IFF_MULTICAST 0x8000 /* supports multicast */
|
||||||
|
|
||||||
|
/* flags set internally only: */
|
||||||
|
#define IFF_CANTCHANGE \
|
||||||
|
(IFF_BROADCAST|IFF_POINTOPOINT|IFF_RUNNING|IFF_OACTIVE|\
|
||||||
|
IFF_SIMPLEX|IFF_MULTICAST|IFF_ALLMULTI)
|
||||||
|
|
||||||
|
#define IFQ_MAXLEN 50
|
||||||
|
#define IFNET_SLOWHZ 1 /* granularity is 1 second */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Message format for use in obtaining information about interfaces
|
||||||
|
* from getkerninfo and the routing socket
|
||||||
|
*/
|
||||||
|
struct if_msghdr {
|
||||||
|
u_short ifm_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char ifm_version; /* future binary compatability */
|
||||||
|
u_char ifm_type; /* message type */
|
||||||
|
int ifm_addrs; /* like rtm_addrs */
|
||||||
|
int ifm_flags; /* value of if_flags */
|
||||||
|
u_short ifm_index; /* index for associated ifp */
|
||||||
|
struct if_data ifm_data;/* statistics and other data about if */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Message format for use in obtaining information about interface addresses
|
||||||
|
* from getkerninfo and the routing socket
|
||||||
|
*/
|
||||||
|
struct ifa_msghdr {
|
||||||
|
u_short ifam_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char ifam_version; /* future binary compatability */
|
||||||
|
u_char ifam_type; /* message type */
|
||||||
|
int ifam_addrs; /* like rtm_addrs */
|
||||||
|
int ifam_flags; /* value of ifa_flags */
|
||||||
|
u_short ifam_index; /* index for associated ifp */
|
||||||
|
int ifam_metric; /* value of ifa_metric */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Message format for use in obtaining information about multicast addresses
|
||||||
|
* from the routing socket
|
||||||
|
*/
|
||||||
|
struct ifma_msghdr {
|
||||||
|
u_short ifmam_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char ifmam_version; /* future binary compatability */
|
||||||
|
u_char ifmam_type; /* message type */
|
||||||
|
int ifmam_addrs; /* like rtm_addrs */
|
||||||
|
int ifmam_flags; /* value of ifa_flags */
|
||||||
|
u_short ifmam_index; /* index for associated ifp */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interface request structure used for socket
|
||||||
|
* ioctl's. All interface ioctl's must have parameter
|
||||||
|
* definitions which begin with ifr_name. The
|
||||||
|
* remainder may be interface specific.
|
||||||
|
*/
|
||||||
|
struct ifreq {
|
||||||
|
#define IFNAMSIZ 16
|
||||||
|
char ifr_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||||
|
union {
|
||||||
|
struct sockaddr ifru_addr;
|
||||||
|
struct sockaddr ifru_dstaddr;
|
||||||
|
struct sockaddr ifru_broadaddr;
|
||||||
|
short ifru_flags;
|
||||||
|
int ifru_metric;
|
||||||
|
int ifru_mtu;
|
||||||
|
int ifru_phys;
|
||||||
|
int ifru_media;
|
||||||
|
caddr_t ifru_data;
|
||||||
|
} ifr_ifru;
|
||||||
|
#define ifr_addr ifr_ifru.ifru_addr /* address */
|
||||||
|
#define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-to-p link */
|
||||||
|
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
|
||||||
|
#define ifr_flags ifr_ifru.ifru_flags /* flags */
|
||||||
|
#define ifr_metric ifr_ifru.ifru_metric /* metric */
|
||||||
|
#define ifr_mtu ifr_ifru.ifru_mtu /* mtu */
|
||||||
|
#define ifr_phys ifr_ifru.ifru_phys /* physical wire */
|
||||||
|
#define ifr_media ifr_ifru.ifru_media /* physical media */
|
||||||
|
#define ifr_data ifr_ifru.ifru_data /* for use by interface */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define _SIZEOF_ADDR_IFREQ(ifr) \
|
||||||
|
((ifr).ifr_addr.sa_len > sizeof(struct sockaddr) ? \
|
||||||
|
(sizeof(struct ifreq) - sizeof(struct sockaddr) + \
|
||||||
|
(ifr).ifr_addr.sa_len) : sizeof(struct ifreq))
|
||||||
|
|
||||||
|
struct ifaliasreq {
|
||||||
|
char ifra_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||||
|
struct sockaddr ifra_addr;
|
||||||
|
struct sockaddr ifra_broadaddr;
|
||||||
|
struct sockaddr ifra_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ifmediareq {
|
||||||
|
char ifm_name[IFNAMSIZ]; /* if name, e.g. "en0" */
|
||||||
|
int ifm_current; /* current media options */
|
||||||
|
int ifm_mask; /* don't care mask */
|
||||||
|
int ifm_status; /* media status */
|
||||||
|
int ifm_active; /* active options */
|
||||||
|
int ifm_count; /* # entries in ifm_ulist array */
|
||||||
|
int *ifm_ulist; /* media words */
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
* Structure used in SIOCGIFCONF request.
|
||||||
|
* Used to retrieve interface configuration
|
||||||
|
* for machine (useful for programs which
|
||||||
|
* must know all networks accessible).
|
||||||
|
*/
|
||||||
|
struct ifconf {
|
||||||
|
int ifc_len; /* size of associated buffer */
|
||||||
|
union {
|
||||||
|
caddr_t ifcu_buf;
|
||||||
|
struct ifreq *ifcu_req;
|
||||||
|
} ifc_ifcu;
|
||||||
|
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
|
||||||
|
#define ifc_req ifc_ifcu.ifcu_req /* array of structures returned */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
#ifdef MALLOC_DECLARE
|
||||||
|
MALLOC_DECLARE(M_IFADDR);
|
||||||
|
MALLOC_DECLARE(M_IFMADDR);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* XXX - this should go away soon */
|
||||||
|
#ifdef KERNEL
|
||||||
|
#include <net/if_var.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* !_NET_IF_H_ */
|
86
StdLib/Include/net/if_dl.h
Normal file
86
StdLib/Include/net/if_dl.h
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1990, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)if_dl.h 8.1 (Berkeley) 6/10/93
|
||||||
|
* $Id: if_dl.h,v 1.1.1.1 2006/05/30 06:12:42 hhzhou Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NET_IF_DL_H_
|
||||||
|
#define _NET_IF_DL_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A Link-Level Sockaddr may specify the interface in one of two
|
||||||
|
* ways: either by means of a system-provided index number (computed
|
||||||
|
* anew and possibly differently on every reboot), or by a human-readable
|
||||||
|
* string such as "il0" (for managerial convenience).
|
||||||
|
*
|
||||||
|
* Census taking actions, such as something akin to SIOCGCONF would return
|
||||||
|
* both the index and the human name.
|
||||||
|
*
|
||||||
|
* High volume transactions (such as giving a link-level ``from'' address
|
||||||
|
* in a recvfrom or recvmsg call) may be likely only to provide the indexed
|
||||||
|
* form, (which requires fewer copy operations and less space).
|
||||||
|
*
|
||||||
|
* The form and interpretation of the link-level address is purely a matter
|
||||||
|
* of convention between the device driver and its consumers; however, it is
|
||||||
|
* expected that all drivers for an interface of a given if_type will agree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure of a Link-Level sockaddr:
|
||||||
|
*/
|
||||||
|
struct sockaddr_dl {
|
||||||
|
u_char sdl_len; /* Total length of sockaddr */
|
||||||
|
u_char sdl_family; /* AF_DLI */
|
||||||
|
u_short sdl_index; /* if != 0, system given index for interface */
|
||||||
|
u_char sdl_type; /* interface type */
|
||||||
|
u_char sdl_nlen; /* interface name length, no trailing 0 reqd. */
|
||||||
|
u_char sdl_alen; /* link level address length */
|
||||||
|
u_char sdl_slen; /* link layer selector length */
|
||||||
|
char sdl_data[12]; /* minimum work area, can be larger;
|
||||||
|
contains both if name and ll address */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define LLADDR(s) ((caddr_t)((s)->sdl_data + (s)->sdl_nlen))
|
||||||
|
|
||||||
|
#ifndef KERNEL
|
||||||
|
|
||||||
|
#include <sys/EfiCdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
void link_addr __P((const char *, struct sockaddr_dl *));
|
||||||
|
char *link_ntoa __P((const struct sockaddr_dl *));
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* !KERNEL */
|
||||||
|
|
||||||
|
#endif
|
170
StdLib/Include/net/radix.h
Normal file
170
StdLib/Include/net/radix.h
Normal file
@ -0,0 +1,170 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1988, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)radix.h 8.2 (Berkeley) 10/31/94
|
||||||
|
* $Id: radix.h,v 1.1.1.1 2006/05/30 06:12:46 hhzhou Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RADIX_H_
|
||||||
|
#define _RADIX_H_
|
||||||
|
|
||||||
|
#ifdef MALLOC_DECLARE
|
||||||
|
MALLOC_DECLARE(M_RTABLE);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Radix search tree node layout.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct radix_node {
|
||||||
|
struct radix_mask *rn_mklist; /* list of masks contained in subtree */
|
||||||
|
struct radix_node *rn_p; /* parent */
|
||||||
|
short rn_b; /* bit offset; -1-index(netmask) */
|
||||||
|
char rn_bmask; /* node: mask for bit test*/
|
||||||
|
u_char rn_flags; /* enumerated next */
|
||||||
|
#define RNF_NORMAL 1 /* leaf contains normal route */
|
||||||
|
#define RNF_ROOT 2 /* leaf is root leaf for tree */
|
||||||
|
#define RNF_ACTIVE 4 /* This node is alive (for rtfree) */
|
||||||
|
union {
|
||||||
|
struct { /* leaf only data: */
|
||||||
|
caddr_t rn_Key; /* object of search */
|
||||||
|
caddr_t rn_Mask; /* netmask, if present */
|
||||||
|
struct radix_node *rn_Dupedkey;
|
||||||
|
} rn_leaf;
|
||||||
|
struct { /* node only data: */
|
||||||
|
int rn_Off; /* where to start compare */
|
||||||
|
struct radix_node *rn_L;/* progeny */
|
||||||
|
struct radix_node *rn_R;/* progeny */
|
||||||
|
} rn_node;
|
||||||
|
} rn_u;
|
||||||
|
#ifdef RN_DEBUG
|
||||||
|
int rn_info;
|
||||||
|
struct radix_node *rn_twin;
|
||||||
|
struct radix_node *rn_ybro;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
#define rn_dupedkey rn_u.rn_leaf.rn_Dupedkey
|
||||||
|
#define rn_key rn_u.rn_leaf.rn_Key
|
||||||
|
#define rn_mask rn_u.rn_leaf.rn_Mask
|
||||||
|
#define rn_off rn_u.rn_node.rn_Off
|
||||||
|
#define rn_l rn_u.rn_node.rn_L
|
||||||
|
#define rn_r rn_u.rn_node.rn_R
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Annotations to tree concerning potential routes applying to subtrees.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct radix_mask {
|
||||||
|
short rm_b; /* bit offset; -1-index(netmask) */
|
||||||
|
char rm_unused; /* cf. rn_bmask */
|
||||||
|
u_char rm_flags; /* cf. rn_flags */
|
||||||
|
struct radix_mask *rm_mklist; /* more masks to try */
|
||||||
|
union {
|
||||||
|
caddr_t rmu_mask; /* the mask */
|
||||||
|
struct radix_node *rmu_leaf; /* for normal routes */
|
||||||
|
} rm_rmu;
|
||||||
|
int rm_refs; /* # of references to this struct */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define rm_mask rm_rmu.rmu_mask
|
||||||
|
#define rm_leaf rm_rmu.rmu_leaf /* extra field would make 32 bytes */
|
||||||
|
|
||||||
|
#define MKGet(m) {\
|
||||||
|
if (rn_mkfreelist) {\
|
||||||
|
m = rn_mkfreelist; \
|
||||||
|
rn_mkfreelist = (m)->rm_mklist; \
|
||||||
|
} else \
|
||||||
|
R_Malloc(m, struct radix_mask *, sizeof (*(m))); }\
|
||||||
|
|
||||||
|
#define MKFree(m) { (m)->rm_mklist = rn_mkfreelist; rn_mkfreelist = (m);}
|
||||||
|
|
||||||
|
typedef int walktree_f_t __P((struct radix_node *, void *));
|
||||||
|
|
||||||
|
struct radix_node_head {
|
||||||
|
struct radix_node *rnh_treetop;
|
||||||
|
int rnh_addrsize; /* permit, but not require fixed keys */
|
||||||
|
int rnh_pktsize; /* permit, but not require fixed keys */
|
||||||
|
struct radix_node *(*rnh_addaddr) /* add based on sockaddr */
|
||||||
|
__P((void *v, void *mask,
|
||||||
|
struct radix_node_head *head, struct radix_node nodes[]));
|
||||||
|
struct radix_node *(*rnh_addpkt) /* add based on packet hdr */
|
||||||
|
__P((void *v, void *mask,
|
||||||
|
struct radix_node_head *head, struct radix_node nodes[]));
|
||||||
|
struct radix_node *(*rnh_deladdr) /* remove based on sockaddr */
|
||||||
|
__P((void *v, void *mask, struct radix_node_head *head));
|
||||||
|
struct radix_node *(*rnh_delpkt) /* remove based on packet hdr */
|
||||||
|
__P((void *v, void *mask, struct radix_node_head *head));
|
||||||
|
struct radix_node *(*rnh_matchaddr) /* locate based on sockaddr */
|
||||||
|
__P((void *v, struct radix_node_head *head));
|
||||||
|
struct radix_node *(*rnh_lookup) /* locate based on sockaddr */
|
||||||
|
__P((void *v, void *mask, struct radix_node_head *head));
|
||||||
|
struct radix_node *(*rnh_matchpkt) /* locate based on packet hdr */
|
||||||
|
__P((void *v, struct radix_node_head *head));
|
||||||
|
int (*rnh_walktree) /* traverse tree */
|
||||||
|
__P((struct radix_node_head *head, walktree_f_t *f, void *w));
|
||||||
|
int (*rnh_walktree_from) /* traverse tree below a */
|
||||||
|
__P((struct radix_node_head *head, void *a, void *m,
|
||||||
|
walktree_f_t *f, void *w));
|
||||||
|
void (*rnh_close) /* do something when the last ref drops */
|
||||||
|
__P((struct radix_node *rn, struct radix_node_head *head));
|
||||||
|
struct radix_node rnh_nodes[3]; /* empty tree for common case */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef KERNEL
|
||||||
|
#define Bcmp(a, b, n) bcmp(((char *)(a)), ((char *)(b)), (n))
|
||||||
|
#define Bcopy(a, b, n) bcopy(((char *)(a)), ((char *)(b)), (unsigned)(n))
|
||||||
|
#define Bzero(p, n) bzero((char *)(p), (int)(n));
|
||||||
|
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned int)(n)))
|
||||||
|
#define Free(p) free((char *)p);
|
||||||
|
#else
|
||||||
|
#define Bcmp(a, b, n) bcmp(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
|
||||||
|
#define Bcopy(a, b, n) bcopy(((caddr_t)(a)), ((caddr_t)(b)), (unsigned)(n))
|
||||||
|
#define Bzero(p, n) bzero((caddr_t)(p), (unsigned)(n));
|
||||||
|
#define R_Malloc(p, t, n) (p = (t) malloc((unsigned long)(n), M_RTABLE, M_DONTWAIT))
|
||||||
|
#define Free(p) free((caddr_t)p, M_RTABLE);
|
||||||
|
#endif /*KERNEL*/
|
||||||
|
|
||||||
|
void rn_init __P((void));
|
||||||
|
int rn_inithead __P((void **, int));
|
||||||
|
int rn_refines __P((void *, void *));
|
||||||
|
struct radix_node
|
||||||
|
*rn_addmask __P((void *, int, int)),
|
||||||
|
*rn_addroute __P((void *, void *, struct radix_node_head *,
|
||||||
|
struct radix_node [2])),
|
||||||
|
*rn_delete __P((void *, void *, struct radix_node_head *)),
|
||||||
|
*rn_lookup __P((void *v_arg, void *m_arg,
|
||||||
|
struct radix_node_head *head)),
|
||||||
|
*rn_match __P((void *, struct radix_node_head *));
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* _RADIX_H_ */
|
292
StdLib/Include/net/route.h
Normal file
292
StdLib/Include/net/route.h
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1980, 1986, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)route.h 8.3 (Berkeley) 4/19/94
|
||||||
|
* $Id: route.h,v 1.1.1.1 2006/05/30 06:12:46 hhzhou Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NET_ROUTE_H_
|
||||||
|
#define _NET_ROUTE_H_
|
||||||
|
|
||||||
|
#define __P(protos) protos /* full-blown ANSI C */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Kernel resident routing tables.
|
||||||
|
*
|
||||||
|
* The routing tables are initialized when interface addresses
|
||||||
|
* are set by making entries for all directly connected interfaces.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* A route consists of a destination address and a reference
|
||||||
|
* to a routing entry. These are often held by protocols
|
||||||
|
* in their control blocks, e.g. inpcb.
|
||||||
|
*/
|
||||||
|
struct route {
|
||||||
|
struct rtentry *ro_rt;
|
||||||
|
struct sockaddr ro_dst;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These numbers are used by reliable protocols for determining
|
||||||
|
* retransmission behavior and are included in the routing structure.
|
||||||
|
*/
|
||||||
|
struct rt_metrics {
|
||||||
|
u_long rmx_locks; /* Kernel must leave these values alone */
|
||||||
|
u_long rmx_mtu; /* MTU for this path */
|
||||||
|
u_long rmx_hopcount; /* max hops expected */
|
||||||
|
u_long rmx_expire; /* lifetime for route, e.g. redirect */
|
||||||
|
u_long rmx_recvpipe; /* inbound delay-bandwidth product */
|
||||||
|
u_long rmx_sendpipe; /* outbound delay-bandwidth product */
|
||||||
|
u_long rmx_ssthresh; /* outbound gateway buffer limit */
|
||||||
|
u_long rmx_rtt; /* estimated round trip time */
|
||||||
|
u_long rmx_rttvar; /* estimated rtt variance */
|
||||||
|
u_long rmx_pksent; /* packets sent using this route */
|
||||||
|
u_long rmx_filler[4]; /* will be used for T/TCP later */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* rmx_rtt and rmx_rttvar are stored as microseconds;
|
||||||
|
* RTTTOPRHZ(rtt) converts to a value suitable for use
|
||||||
|
* by a protocol slowtimo counter.
|
||||||
|
*/
|
||||||
|
#define RTM_RTTUNIT 1000000 /* units for rtt, rttvar, as units per sec */
|
||||||
|
#define RTTTOPRHZ(r) ((r) / (RTM_RTTUNIT / PR_SLOWHZ))
|
||||||
|
|
||||||
|
/*
|
||||||
|
* XXX kernel function pointer `rt_output' is visible to applications.
|
||||||
|
*/
|
||||||
|
struct mbuf;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We distinguish between routes to hosts and routes to networks,
|
||||||
|
* preferring the former if available. For each route we infer
|
||||||
|
* the interface to use from the gateway address supplied when
|
||||||
|
* the route was entered. Routes that forward packets through
|
||||||
|
* gateways are marked so that the output routines know to address the
|
||||||
|
* gateway rather than the ultimate destination.
|
||||||
|
*/
|
||||||
|
#ifndef RNF_NORMAL
|
||||||
|
#include <net/radix.h>
|
||||||
|
#endif
|
||||||
|
struct rtentry {
|
||||||
|
struct radix_node rt_nodes[2]; /* tree glue, and other values */
|
||||||
|
#define rt_key(r) ((struct sockaddr *)((r)->rt_nodes->rn_key))
|
||||||
|
#define rt_mask(r) ((struct sockaddr *)((r)->rt_nodes->rn_mask))
|
||||||
|
struct sockaddr *rt_gateway; /* value */
|
||||||
|
short rt_filler; /* was short flags field */
|
||||||
|
short rt_refcnt; /* # held references */
|
||||||
|
u_long rt_flags; /* up/down?, host/net */
|
||||||
|
struct ifnet *rt_ifp; /* the answer: interface to use */
|
||||||
|
struct ifaddr *rt_ifa; /* the answer: interface to use */
|
||||||
|
struct sockaddr *rt_genmask; /* for generation of cloned routes */
|
||||||
|
caddr_t rt_llinfo; /* pointer to link level info cache */
|
||||||
|
struct rt_metrics rt_rmx; /* metrics used by rx'ing protocols */
|
||||||
|
struct rtentry *rt_gwroute; /* implied entry for gatewayed routes */
|
||||||
|
int (*rt_output) __P((struct ifnet *, struct mbuf *,
|
||||||
|
struct sockaddr *, struct rtentry *));
|
||||||
|
/* output routine for this (rt,if) */
|
||||||
|
struct rtentry *rt_parent; /* cloning parent of this route */
|
||||||
|
void *rt_filler2; /* more filler */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Following structure necessary for 4.3 compatibility;
|
||||||
|
* We should eventually move it to a compat file.
|
||||||
|
*/
|
||||||
|
struct ortentry {
|
||||||
|
u_long rt_hash; /* to speed lookups */
|
||||||
|
struct sockaddr rt_dst; /* key */
|
||||||
|
struct sockaddr rt_gateway; /* value */
|
||||||
|
short rt_flags; /* up/down?, host/net */
|
||||||
|
short rt_refcnt; /* # held references */
|
||||||
|
u_long rt_use; /* raw # packets forwarded */
|
||||||
|
struct ifnet *rt_ifp; /* the answer: interface to use */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define rt_use rt_rmx.rmx_pksent
|
||||||
|
|
||||||
|
#define RTF_UP 0x1 /* route usable */
|
||||||
|
#define RTF_GATEWAY 0x2 /* destination is a gateway */
|
||||||
|
#define RTF_HOST 0x4 /* host entry (net otherwise) */
|
||||||
|
#define RTF_REJECT 0x8 /* host or net unreachable */
|
||||||
|
#define RTF_DYNAMIC 0x10 /* created dynamically (by redirect) */
|
||||||
|
#define RTF_MODIFIED 0x20 /* modified dynamically (by redirect) */
|
||||||
|
#define RTF_DONE 0x40 /* message confirmed */
|
||||||
|
/* 0x80 unused */
|
||||||
|
#define RTF_CLONING 0x100 /* generate new routes on use */
|
||||||
|
#define RTF_XRESOLVE 0x200 /* external daemon resolves name */
|
||||||
|
#define RTF_LLINFO 0x400 /* generated by link layer (e.g. ARP) */
|
||||||
|
#define RTF_STATIC 0x800 /* manually added */
|
||||||
|
#define RTF_BLACKHOLE 0x1000 /* just discard pkts (during updates) */
|
||||||
|
#define RTF_PROTO2 0x4000 /* protocol specific routing flag */
|
||||||
|
#define RTF_PROTO1 0x8000 /* protocol specific routing flag */
|
||||||
|
|
||||||
|
#define RTF_PRCLONING 0x10000 /* protocol requires cloning */
|
||||||
|
#define RTF_WASCLONED 0x20000 /* route generated through cloning */
|
||||||
|
#define RTF_PROTO3 0x40000 /* protocol specific routing flag */
|
||||||
|
/* 0x80000 unused */
|
||||||
|
#define RTF_PINNED 0x100000 /* future use */
|
||||||
|
#define RTF_LOCAL 0x200000 /* route represents a local address */
|
||||||
|
#define RTF_BROADCAST 0x400000 /* route represents a bcast address */
|
||||||
|
#define RTF_MULTICAST 0x800000 /* route represents a mcast address */
|
||||||
|
/* 0x1000000 and up unassigned */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Routing statistics.
|
||||||
|
*/
|
||||||
|
struct rtstat {
|
||||||
|
short rts_badredirect; /* bogus redirect calls */
|
||||||
|
short rts_dynamic; /* routes created by redirects */
|
||||||
|
short rts_newgateway; /* routes modified by redirects */
|
||||||
|
short rts_unreach; /* lookups which failed */
|
||||||
|
short rts_wildcard; /* lookups satisfied by a wildcard */
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
* Structures for routing messages.
|
||||||
|
*/
|
||||||
|
struct rt_msghdr {
|
||||||
|
u_short rtm_msglen; /* to skip over non-understood messages */
|
||||||
|
u_char rtm_version; /* future binary compatibility */
|
||||||
|
u_char rtm_type; /* message type */
|
||||||
|
u_short rtm_index; /* index for associated ifp */
|
||||||
|
int rtm_flags; /* flags, incl. kern & message, e.g. DONE */
|
||||||
|
int rtm_addrs; /* bitmask identifying sockaddrs in msg */
|
||||||
|
pid_t rtm_pid; /* identify sender */
|
||||||
|
int rtm_seq; /* for sender to identify action */
|
||||||
|
int rtm_errno; /* why failed */
|
||||||
|
int rtm_use; /* from rtentry */
|
||||||
|
u_long rtm_inits; /* which metrics we are initializing */
|
||||||
|
struct rt_metrics rtm_rmx; /* metrics themselves */
|
||||||
|
};
|
||||||
|
|
||||||
|
#define RTM_VERSION 5 /* Up the ante and ignore older versions */
|
||||||
|
|
||||||
|
#define RTM_ADD 0x1 /* Add Route */
|
||||||
|
#define RTM_DELETE 0x2 /* Delete Route */
|
||||||
|
#define RTM_CHANGE 0x3 /* Change Metrics or flags */
|
||||||
|
#define RTM_GET 0x4 /* Report Metrics */
|
||||||
|
#define RTM_LOSING 0x5 /* Kernel Suspects Partitioning */
|
||||||
|
#define RTM_REDIRECT 0x6 /* Told to use different route */
|
||||||
|
#define RTM_MISS 0x7 /* Lookup failed on this address */
|
||||||
|
#define RTM_LOCK 0x8 /* fix specified metrics */
|
||||||
|
#define RTM_OLDADD 0x9 /* caused by SIOCADDRT */
|
||||||
|
#define RTM_OLDDEL 0xa /* caused by SIOCDELRT */
|
||||||
|
#define RTM_RESOLVE 0xb /* req to resolve dst to LL addr */
|
||||||
|
#define RTM_NEWADDR 0xc /* address being added to iface */
|
||||||
|
#define RTM_DELADDR 0xd /* address being removed from iface */
|
||||||
|
#define RTM_IFINFO 0xe /* iface going up/down etc. */
|
||||||
|
#define RTM_NEWMADDR 0xf /* mcast group membership being added to if */
|
||||||
|
#define RTM_DELMADDR 0x10 /* mcast group membership being deleted */
|
||||||
|
|
||||||
|
#define RTV_MTU 0x1 /* init or lock _mtu */
|
||||||
|
#define RTV_HOPCOUNT 0x2 /* init or lock _hopcount */
|
||||||
|
#define RTV_EXPIRE 0x4 /* init or lock _hopcount */
|
||||||
|
#define RTV_RPIPE 0x8 /* init or lock _recvpipe */
|
||||||
|
#define RTV_SPIPE 0x10 /* init or lock _sendpipe */
|
||||||
|
#define RTV_SSTHRESH 0x20 /* init or lock _ssthresh */
|
||||||
|
#define RTV_RTT 0x40 /* init or lock _rtt */
|
||||||
|
#define RTV_RTTVAR 0x80 /* init or lock _rttvar */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitmask values for rtm_addr.
|
||||||
|
*/
|
||||||
|
#define RTA_DST 0x1 /* destination sockaddr present */
|
||||||
|
#define RTA_GATEWAY 0x2 /* gateway sockaddr present */
|
||||||
|
#define RTA_NETMASK 0x4 /* netmask sockaddr present */
|
||||||
|
#define RTA_GENMASK 0x8 /* cloning mask sockaddr present */
|
||||||
|
#define RTA_IFP 0x10 /* interface name sockaddr present */
|
||||||
|
#define RTA_IFA 0x20 /* interface addr sockaddr present */
|
||||||
|
#define RTA_AUTHOR 0x40 /* sockaddr for author of redirect */
|
||||||
|
#define RTA_BRD 0x80 /* for NEWADDR, broadcast or p-p dest addr */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Index offsets for sockaddr array for alternate internal encoding.
|
||||||
|
*/
|
||||||
|
#define RTAX_DST 0 /* destination sockaddr present */
|
||||||
|
#define RTAX_GATEWAY 1 /* gateway sockaddr present */
|
||||||
|
#define RTAX_NETMASK 2 /* netmask sockaddr present */
|
||||||
|
#define RTAX_GENMASK 3 /* cloning mask sockaddr present */
|
||||||
|
#define RTAX_IFP 4 /* interface name sockaddr present */
|
||||||
|
#define RTAX_IFA 5 /* interface addr sockaddr present */
|
||||||
|
#define RTAX_AUTHOR 6 /* sockaddr for author of redirect */
|
||||||
|
#define RTAX_BRD 7 /* for NEWADDR, broadcast or p-p dest addr */
|
||||||
|
#define RTAX_MAX 8 /* size of array to allocate */
|
||||||
|
|
||||||
|
struct rt_addrinfo {
|
||||||
|
int rti_addrs;
|
||||||
|
struct sockaddr *rti_info[RTAX_MAX];
|
||||||
|
};
|
||||||
|
|
||||||
|
struct route_cb {
|
||||||
|
int ip_count;
|
||||||
|
int ipx_count;
|
||||||
|
int ns_count;
|
||||||
|
int iso_count;
|
||||||
|
int any_count;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
#define RTFREE(rt) \
|
||||||
|
if ((rt)->rt_refcnt <= 1) \
|
||||||
|
rtfree(rt); \
|
||||||
|
else \
|
||||||
|
(rt)->rt_refcnt--;
|
||||||
|
|
||||||
|
extern struct route_cb route_cb;
|
||||||
|
extern struct radix_node_head *rt_tables[AF_MAX+1];
|
||||||
|
|
||||||
|
struct ifmultiaddr;
|
||||||
|
struct proc;
|
||||||
|
|
||||||
|
void route_init __P((void));
|
||||||
|
void rt_ifmsg __P((struct ifnet *));
|
||||||
|
void rt_missmsg __P((int, struct rt_addrinfo *, int, int));
|
||||||
|
void rt_newaddrmsg __P((int, struct ifaddr *, int, struct rtentry *));
|
||||||
|
void rt_newmaddrmsg __P((int, struct ifmultiaddr *));
|
||||||
|
int rt_setgate __P((struct rtentry *,
|
||||||
|
struct sockaddr *, struct sockaddr *));
|
||||||
|
void rtalloc __P((struct route *));
|
||||||
|
void rtalloc_ign __P((struct route *, unsigned long));
|
||||||
|
struct rtentry *
|
||||||
|
rtalloc1 __P((struct sockaddr *, int, unsigned long));
|
||||||
|
void rtfree __P((struct rtentry *));
|
||||||
|
int rtinit __P((struct ifaddr *, int, int));
|
||||||
|
int rtioctl __P((int, caddr_t, struct proc *));
|
||||||
|
void rtredirect __P((struct sockaddr *, struct sockaddr *,
|
||||||
|
struct sockaddr *, int, struct sockaddr *, struct rtentry **));
|
||||||
|
int rtrequest __P((int, struct sockaddr *,
|
||||||
|
struct sockaddr *, struct sockaddr *, int, struct rtentry **));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
92
StdLib/Include/netatalk/at.h
Normal file
92
StdLib/Include/netatalk/at.h
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1990,1991 Regents of The University of Michigan.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software and
|
||||||
|
* its documentation for any purpose and without fee is hereby granted,
|
||||||
|
* provided that the above copyright notice appears in all copies and
|
||||||
|
* that both that copyright notice and this permission notice appear
|
||||||
|
* in supporting documentation, and that the name of The University
|
||||||
|
* of Michigan not be used in advertising or publicity pertaining to
|
||||||
|
* distribution of the software without specific, written prior
|
||||||
|
* permission. This software is supplied as is without expressed or
|
||||||
|
* implied warranties of any kind.
|
||||||
|
*
|
||||||
|
* Research Systems Unix Group
|
||||||
|
* The University of Michigan
|
||||||
|
* c/o Mike Clark
|
||||||
|
* 535 W. William Street
|
||||||
|
* Ann Arbor, Michigan
|
||||||
|
* +1-313-763-0525
|
||||||
|
* netatalk@itd.umich.edu
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __AT_HEADER__
|
||||||
|
#define __AT_HEADER__
|
||||||
|
/*
|
||||||
|
* Supported protocols
|
||||||
|
*/
|
||||||
|
#define ATPROTO_DDP 0
|
||||||
|
#define ATPROTO_AARP 254
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ethernet types, for DIX.
|
||||||
|
* These should really be in some global header file, but we can't
|
||||||
|
* count on them being there, and it's annoying to patch system files.
|
||||||
|
*/
|
||||||
|
#define ETHERTYPE_AT 0x809B /* AppleTalk protocol */
|
||||||
|
#define ETHERTYPE_AARP 0x80F3 /* AppleTalk ARP */
|
||||||
|
|
||||||
|
#define DDP_MAXSZ 587
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If ATPORT_FIRST <= Port < ATPORT_RESERVED,
|
||||||
|
* Port was created by a privileged process.
|
||||||
|
* If ATPORT_RESERVED <= Port < ATPORT_LAST,
|
||||||
|
* Port was not necessarily created by a
|
||||||
|
* privileged process.
|
||||||
|
*/
|
||||||
|
#define ATPORT_FIRST 1
|
||||||
|
#define ATPORT_RESERVED 128
|
||||||
|
#define ATPORT_LAST 255
|
||||||
|
|
||||||
|
/*
|
||||||
|
* AppleTalk address.
|
||||||
|
*/
|
||||||
|
struct at_addr {
|
||||||
|
u_short s_net;
|
||||||
|
u_char s_node;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define ATADDR_ANYNET (u_short)0x0000
|
||||||
|
#define ATADDR_ANYNODE (u_char)0x00
|
||||||
|
#define ATADDR_ANYPORT (u_char)0x00
|
||||||
|
#define ATADDR_BCAST (u_char)0xff /* There is no BCAST for NET */
|
||||||
|
|
||||||
|
struct netrange {
|
||||||
|
u_char nr_phase;
|
||||||
|
u_short nr_firstnet;
|
||||||
|
u_short nr_lastnet;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Socket address, AppleTalk style. We keep magic information in the
|
||||||
|
* zero bytes. There are three types, NONE, CONFIG which has the phase
|
||||||
|
* and a net range, and IFACE which has the network address of an
|
||||||
|
* interface. IFACE may be filled in by the client, and is filled in
|
||||||
|
* by the kernel.
|
||||||
|
*/
|
||||||
|
struct sockaddr_at {
|
||||||
|
u_char sat_len;
|
||||||
|
u_char sat_family;
|
||||||
|
u_char sat_port;
|
||||||
|
struct at_addr sat_addr;
|
||||||
|
union {
|
||||||
|
struct netrange r_netrange;
|
||||||
|
char r_zero[ 8 ]; /* Hide a struct netrange in here */
|
||||||
|
} sat_range;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define sat_zero sat_range.r_zero
|
||||||
|
|
||||||
|
#endif /* !__AT_HEADER__ */
|
@ -94,6 +94,7 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/featuretest.h>
|
#include <sys/featuretest.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
#include <paths.h>
|
||||||
/*
|
/*
|
||||||
* Data types
|
* Data types
|
||||||
*/
|
*/
|
||||||
@ -108,27 +109,6 @@ typedef __socklen_t socklen_t;
|
|||||||
#undef _BSD_SIZE_T_
|
#undef _BSD_SIZE_T_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////#if defined(_NETBSD_SOURCE)
|
|
||||||
////#ifndef _PATH_HEQUIV
|
|
||||||
////#define _PATH_HEQUIV "/etc/hosts.equiv"
|
|
||||||
////#endif
|
|
||||||
#ifndef _PATH_HOSTS
|
|
||||||
#define _PATH_HOSTS "/etc/hosts"
|
|
||||||
#endif
|
|
||||||
#ifndef _PATH_NETWORKS
|
|
||||||
#define _PATH_NETWORKS "/etc/networks"
|
|
||||||
#endif
|
|
||||||
#ifndef _PATH_PROTOCOLS
|
|
||||||
#define _PATH_PROTOCOLS "/etc/protocols"
|
|
||||||
#endif
|
|
||||||
#ifndef _PATH_SERVICES
|
|
||||||
#define _PATH_SERVICES "/etc/services"
|
|
||||||
#endif
|
|
||||||
////#ifndef _PATH_SERVICES_DB
|
|
||||||
////#define _PATH_SERVICES_DB "/var/db/services.db"
|
|
||||||
////#endif
|
|
||||||
////#endif
|
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
extern int h_errno;
|
extern int h_errno;
|
||||||
__END_DECLS
|
__END_DECLS
|
||||||
@ -219,14 +199,11 @@ struct addrinfo {
|
|||||||
#define NETDB_INTERNAL -1 /*%< see errno */
|
#define NETDB_INTERNAL -1 /*%< see errno */
|
||||||
#define NETDB_SUCCESS 0 /*%< no problem */
|
#define NETDB_SUCCESS 0 /*%< no problem */
|
||||||
#endif
|
#endif
|
||||||
////#define NO_ADDRESS NO_DATA /* no address, look for MX record */
|
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
|
||||||
#define HOST_NOT_FOUND 1 /*%< Authoritative Answer Host not found */
|
#define HOST_NOT_FOUND 1 /*%< Authoritative Answer Host not found */
|
||||||
#define TRY_AGAIN 2 /*%< Non-Authoritive Host not found, or SERVERFAIL */
|
#define TRY_AGAIN 2 /*%< Non-Authoritive Host not found, or SERVERFAIL */
|
||||||
#define NO_RECOVERY 3 /*%< Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
#define NO_RECOVERY 3 /*%< Non recoverable errors, FORMERR, REFUSED, NOTIMP */
|
||||||
////#define NO_DATA 4 /*%< Valid name, no data record of requested type */
|
#define NO_DATA 4 /*%< Valid name, no data record of requested type */
|
||||||
////#if defined(_NETBSD_SOURCE)
|
|
||||||
////#define NO_ADDRESS NO_DATA /*%< no address, look for MX record */
|
|
||||||
////#endif
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Error return codes from getaddrinfo()
|
* Error return codes from getaddrinfo()
|
||||||
|
62
StdLib/Include/netinet/in_systm.h
Normal file
62
StdLib/Include/netinet/in_systm.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1982, 1986, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)in_systm.h 8.1 (Berkeley) 6/10/93
|
||||||
|
* $Id: in_systm.h,v 1.1.1.1 2006/05/30 06:12:48 hhzhou Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NETINET_IN_SYSTM_H_
|
||||||
|
#define _NETINET_IN_SYSTM_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Miscellaneous internetwork
|
||||||
|
* definitions for kernel.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Network types.
|
||||||
|
*
|
||||||
|
* Internally the system keeps counters in the headers with the bytes
|
||||||
|
* swapped so that VAX instructions will work on them. It reverses
|
||||||
|
* the bytes before transmission at each protocol level. The n_ types
|
||||||
|
* represent the types with the bytes in ``high-ender'' order.
|
||||||
|
*/
|
||||||
|
typedef u_int16_t n_short; /* short as received from the net */
|
||||||
|
typedef u_int32_t n_long; /* long as received from the net */
|
||||||
|
|
||||||
|
typedef u_int32_t n_time; /* ms since 00:00 GMT, byte rev */
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
n_time iptime __P((void));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
197
StdLib/Include/netinet/ip.h
Normal file
197
StdLib/Include/netinet/ip.h
Normal file
@ -0,0 +1,197 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1982, 1986, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Portions copyright (c) 1999, 2000
|
||||||
|
* Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
*
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley, Intel Corporation, and its contributors.
|
||||||
|
*
|
||||||
|
* 4. Neither the name of University, Intel Corporation, or their respective
|
||||||
|
* contributors may be used to endorse or promote products derived from
|
||||||
|
* this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION 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 REGENTS,
|
||||||
|
* INTEL CORPORATION 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.
|
||||||
|
*
|
||||||
|
* @(#)ip.h 8.2 (Berkeley) 6/1/94
|
||||||
|
* $Id: ip.h,v 1.1.1.1 2006/05/30 06:12:48 hhzhou Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NETINET_IP_H_
|
||||||
|
#define _NETINET_IP_H_
|
||||||
|
|
||||||
|
#ifndef _ORG_FREEBSD_
|
||||||
|
#define _IP_VHL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definitions for internet protocol version 4.
|
||||||
|
* Per RFC 791, September 1981.
|
||||||
|
*/
|
||||||
|
#define IPVERSION 4
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Structure of an internet header, naked of options.
|
||||||
|
*/
|
||||||
|
struct ip {
|
||||||
|
#ifdef _IP_VHL
|
||||||
|
u_char ip_vhl; /* version << 4 | header length >> 2 */
|
||||||
|
#else
|
||||||
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
|
u_int ip_hl:4, /* header length */
|
||||||
|
ip_v:4; /* version */
|
||||||
|
#endif
|
||||||
|
#if BYTE_ORDER == BIG_ENDIAN
|
||||||
|
u_int ip_v:4, /* version */
|
||||||
|
ip_hl:4; /* header length */
|
||||||
|
#endif
|
||||||
|
#endif /* not _IP_VHL */
|
||||||
|
u_char ip_tos; /* type of service */
|
||||||
|
u_short ip_len; /* total length */
|
||||||
|
u_short ip_id; /* identification */
|
||||||
|
u_short ip_off; /* fragment offset field */
|
||||||
|
#define IP_RF 0x8000 /* reserved fragment flag */
|
||||||
|
#define IP_DF 0x4000 /* dont fragment flag */
|
||||||
|
#define IP_MF 0x2000 /* more fragments flag */
|
||||||
|
#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
|
||||||
|
u_char ip_ttl; /* time to live */
|
||||||
|
u_char ip_p; /* protocol */
|
||||||
|
u_short ip_sum; /* checksum */
|
||||||
|
struct in_addr ip_src,ip_dst; /* source and dest address */
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef _IP_VHL
|
||||||
|
#define IP_MAKE_VHL(v, hl) ((v) << 4 | (hl))
|
||||||
|
#define IP_VHL_HL(vhl) ((vhl) & 0x0f)
|
||||||
|
#define IP_VHL_V(vhl) ((vhl) >> 4)
|
||||||
|
#define IP_VHL_BORING 0x45
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define IP_MAXPACKET 65535 /* maximum packet size */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definitions for IP type of service (ip_tos)
|
||||||
|
*/
|
||||||
|
#define IPTOS_LOWDELAY 0x10
|
||||||
|
#define IPTOS_THROUGHPUT 0x08
|
||||||
|
#define IPTOS_RELIABILITY 0x04
|
||||||
|
#define IPTOS_MINCOST 0x02
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definitions for IP precedence (also in ip_tos) (hopefully unused)
|
||||||
|
*/
|
||||||
|
#define IPTOS_PREC_NETCONTROL 0xe0
|
||||||
|
#define IPTOS_PREC_INTERNETCONTROL 0xc0
|
||||||
|
#define IPTOS_PREC_CRITIC_ECP 0xa0
|
||||||
|
#define IPTOS_PREC_FLASHOVERRIDE 0x80
|
||||||
|
#define IPTOS_PREC_FLASH 0x60
|
||||||
|
#define IPTOS_PREC_IMMEDIATE 0x40
|
||||||
|
#define IPTOS_PREC_PRIORITY 0x20
|
||||||
|
#define IPTOS_PREC_ROUTINE 0x00
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Definitions for options.
|
||||||
|
*/
|
||||||
|
#define IPOPT_COPIED(o) ((o)&0x80)
|
||||||
|
#define IPOPT_CLASS(o) ((o)&0x60)
|
||||||
|
#define IPOPT_NUMBER(o) ((o)&0x1f)
|
||||||
|
|
||||||
|
#define IPOPT_CONTROL 0x00
|
||||||
|
#define IPOPT_RESERVED1 0x20
|
||||||
|
#define IPOPT_DEBMEAS 0x40
|
||||||
|
#define IPOPT_RESERVED2 0x60
|
||||||
|
|
||||||
|
#define IPOPT_EOL 0 /* end of option list */
|
||||||
|
#define IPOPT_NOP 1 /* no operation */
|
||||||
|
|
||||||
|
#define IPOPT_RR 7 /* record packet route */
|
||||||
|
#define IPOPT_TS 68 /* timestamp */
|
||||||
|
#define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
|
||||||
|
#define IPOPT_LSRR 131 /* loose source route */
|
||||||
|
#define IPOPT_SATID 136 /* satnet id */
|
||||||
|
#define IPOPT_SSRR 137 /* strict source route */
|
||||||
|
#define IPOPT_RA 148 /* router alert */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Offsets to fields in options other than EOL and NOP.
|
||||||
|
*/
|
||||||
|
#define IPOPT_OPTVAL 0 /* option ID */
|
||||||
|
#define IPOPT_OLEN 1 /* option length */
|
||||||
|
#define IPOPT_OFFSET 2 /* offset within option */
|
||||||
|
#define IPOPT_MINOFF 4 /* min value of above */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Time stamp option structure.
|
||||||
|
*/
|
||||||
|
struct ip_timestamp {
|
||||||
|
u_char ipt_code; /* IPOPT_TS */
|
||||||
|
u_char ipt_len; /* size of structure (variable) */
|
||||||
|
u_char ipt_ptr; /* index of current entry */
|
||||||
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||||
|
u_int ipt_flg:4, /* flags, see below */
|
||||||
|
ipt_oflw:4; /* overflow counter */
|
||||||
|
#endif
|
||||||
|
#if BYTE_ORDER == BIG_ENDIAN
|
||||||
|
u_int ipt_oflw:4, /* overflow counter */
|
||||||
|
ipt_flg:4; /* flags, see below */
|
||||||
|
#endif
|
||||||
|
union ipt_timestamp {
|
||||||
|
n_long ipt_time[1];
|
||||||
|
struct ipt_ta {
|
||||||
|
struct in_addr ipt_addr;
|
||||||
|
n_long ipt_time;
|
||||||
|
} ipt_ta[1];
|
||||||
|
} ipt_timestamp;
|
||||||
|
};
|
||||||
|
|
||||||
|
/* flag bits for ipt_flg */
|
||||||
|
#define IPOPT_TS_TSONLY 0 /* timestamps only */
|
||||||
|
#define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
|
||||||
|
#define IPOPT_TS_PRESPEC 3 /* specified modules only */
|
||||||
|
|
||||||
|
/* bits for security (not byte swapped) */
|
||||||
|
#define IPOPT_SECUR_UNCLASS 0x0000
|
||||||
|
#define IPOPT_SECUR_CONFID 0xf135
|
||||||
|
#define IPOPT_SECUR_EFTO 0x789a
|
||||||
|
#define IPOPT_SECUR_MMMM 0xbc4d
|
||||||
|
#define IPOPT_SECUR_RESTR 0xaf13
|
||||||
|
#define IPOPT_SECUR_SECRET 0xd788
|
||||||
|
#define IPOPT_SECUR_TOPSECRET 0x6bc5
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Internet implementation parameters.
|
||||||
|
*/
|
||||||
|
#define MAXTTL 255 /* maximum time to live (seconds) */
|
||||||
|
#define IPDEFTTL 64 /* default ttl, from RFC 1340 */
|
||||||
|
#define IPFRAGTTL 60 /* time to live for frags, slowhz */
|
||||||
|
#define IPTTLDEC 1 /* subtracted when forwarding */
|
||||||
|
|
||||||
|
#define IP_MSS 576 /* default maximum segment size */
|
||||||
|
|
||||||
|
#endif
|
157
StdLib/Include/netns/ns.h
Normal file
157
StdLib/Include/netns/ns.h
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 1984, 1985, 1986, 1987, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)ns.h 8.1 (Berkeley) 6/10/93
|
||||||
|
* $Id: ns.h,v 1.1.1.1 2003/11/19 01:48:56 kyu3 Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _NETNS_NS_H_
|
||||||
|
#define _NETNS_NS_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants and Structures defined by the Xerox Network Software
|
||||||
|
* per "Internet Transport Protocols", XSIS 028112, December 1981
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Protocols
|
||||||
|
*/
|
||||||
|
#define NSPROTO_RI 1 /* Routing Information */
|
||||||
|
#define NSPROTO_ECHO 2 /* Echo Protocol */
|
||||||
|
#define NSPROTO_ERROR 3 /* Error Protocol */
|
||||||
|
#define NSPROTO_PE 4 /* Packet Exchange */
|
||||||
|
#define NSPROTO_SPP 5 /* Sequenced Packet */
|
||||||
|
#define NSPROTO_RAW 255 /* Placemarker*/
|
||||||
|
#define NSPROTO_MAX 256 /* Placemarker*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Port/Socket numbers: network standard functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define NSPORT_RI 1 /* Routing Information */
|
||||||
|
#define NSPORT_ECHO 2 /* Echo */
|
||||||
|
#define NSPORT_RE 3 /* Router Error */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Ports < NSPORT_RESERVED are reserved for priveleged
|
||||||
|
* processes (e.g. root).
|
||||||
|
*/
|
||||||
|
#define NSPORT_RESERVED 3000
|
||||||
|
|
||||||
|
/* flags passed to ns_output as last parameter */
|
||||||
|
|
||||||
|
#define NS_FORWARDING 0x1 /* most of idp header exists */
|
||||||
|
#define NS_ROUTETOIF 0x10 /* same as SO_DONTROUTE */
|
||||||
|
#define NS_ALLOWBROADCAST SO_BROADCAST /* can send broadcast packets */
|
||||||
|
|
||||||
|
#define NS_MAXHOPS 15
|
||||||
|
|
||||||
|
/* flags passed to get/set socket option */
|
||||||
|
#define SO_HEADERS_ON_INPUT 1
|
||||||
|
#define SO_HEADERS_ON_OUTPUT 2
|
||||||
|
#define SO_DEFAULT_HEADERS 3
|
||||||
|
#define SO_LAST_HEADER 4
|
||||||
|
#define SO_NSIP_ROUTE 5
|
||||||
|
#define SO_SEQNO 6
|
||||||
|
#define SO_ALL_PACKETS 7
|
||||||
|
#define SO_MTU 8
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* NS addressing
|
||||||
|
*/
|
||||||
|
union ns_host {
|
||||||
|
u_char c_host[6];
|
||||||
|
u_short s_host[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
union ns_net {
|
||||||
|
u_char c_net[4];
|
||||||
|
u_short s_net[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
union ns_net_u {
|
||||||
|
union ns_net net_e;
|
||||||
|
u_long long_e;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ns_addr {
|
||||||
|
union ns_net x_net;
|
||||||
|
union ns_host x_host;
|
||||||
|
u_short x_port;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Socket address, Xerox style
|
||||||
|
*/
|
||||||
|
struct sockaddr_ns {
|
||||||
|
u_char sns_len;
|
||||||
|
u_char sns_family;
|
||||||
|
struct ns_addr sns_addr;
|
||||||
|
char sns_zero[2];
|
||||||
|
};
|
||||||
|
#define sns_port sns_addr.x_port
|
||||||
|
|
||||||
|
#ifdef vax
|
||||||
|
#define ns_netof(a) (*(long *) & ((a).x_net)) /* XXX - not needed */
|
||||||
|
#endif
|
||||||
|
#define ns_neteqnn(a,b) (((a).s_net[0]==(b).s_net[0]) && \
|
||||||
|
((a).s_net[1]==(b).s_net[1]))
|
||||||
|
#define ns_neteq(a,b) ns_neteqnn((a).x_net, (b).x_net)
|
||||||
|
#define satons_addr(sa) (((struct sockaddr_ns *)&(sa))->sns_addr)
|
||||||
|
#define ns_hosteqnh(s,t) ((s).s_host[0] == (t).s_host[0] && \
|
||||||
|
(s).s_host[1] == (t).s_host[1] && (s).s_host[2] == (t).s_host[2])
|
||||||
|
#define ns_hosteq(s,t) (ns_hosteqnh((s).x_host,(t).x_host))
|
||||||
|
#define ns_nullhost(x) (((x).x_host.s_host[0]==0) && \
|
||||||
|
((x).x_host.s_host[1]==0) && ((x).x_host.s_host[2]==0))
|
||||||
|
|
||||||
|
#ifdef KERNEL
|
||||||
|
extern struct domain nsdomain;
|
||||||
|
union ns_host ns_thishost;
|
||||||
|
union ns_host ns_zerohost;
|
||||||
|
union ns_host ns_broadhost;
|
||||||
|
union ns_net ns_zeronet;
|
||||||
|
union ns_net ns_broadnet;
|
||||||
|
u_short ns_cksum();
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
extern struct ns_addr ns_addr (const char *);
|
||||||
|
extern char *ns_ntoa (struct ns_addr);
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
@ -45,6 +45,19 @@
|
|||||||
//#define _PATH_DEFPATH "/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"
|
//#define _PATH_DEFPATH "/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin"
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Provide trailing slash, since mostly used for building pathnames.
|
||||||
|
* see the __CONCAT() macro from <sys/EfiCdefs.h> for cpp examples.
|
||||||
|
*/
|
||||||
|
#define _PATH_DEV "/dev/"
|
||||||
|
#define _PATH_ETC "/Efi/etc/"
|
||||||
|
#define _PATH_TMP "/Efi/Temp/"
|
||||||
|
//#define _PATH_DEV_PTS "/dev/pts/"
|
||||||
|
//#define _PATH_EMUL_AOUT "/emul/aout/"
|
||||||
|
//#define _PATH_VARDB "/var/db/"
|
||||||
|
//#define _PATH_VARRUN "/var/run/"
|
||||||
|
//#define _PATH_VARTMP "/var/tmp/"
|
||||||
|
|
||||||
///*
|
///*
|
||||||
// * All standard utilities path.
|
// * All standard utilities path.
|
||||||
// * set by init(8) for system programs & scripts (e.g. /etc/rc)
|
// * set by init(8) for system programs & scripts (e.g. /etc/rc)
|
||||||
@ -97,33 +110,34 @@
|
|||||||
#define _PATH_SOCKET "socket:"
|
#define _PATH_SOCKET "socket:"
|
||||||
|
|
||||||
// *nix style device paths
|
// *nix style device paths
|
||||||
#define _PATH_DEVTTY "/dev/tty"
|
#define _PATH_DEVTTY _PATH_DEV "tty"
|
||||||
#define _PATH_DEVNULL "/dev/null"
|
#define _PATH_DEVNULL _PATH_DEV "null"
|
||||||
#define _PATH_DEVCONSOLE "/dev/console"
|
#define _PATH_DEVCONSOLE _PATH_DEV "console"
|
||||||
#define _PATH_DEVCONSTTY "/dev/constty"
|
#define _PATH_DEVCONSTTY _PATH_DEV "constty"
|
||||||
#define _PATH_DEVSTDIN "/dev/stdin"
|
#define _PATH_DEVSTDIN _PATH_DEV "stdin"
|
||||||
#define _PATH_DEVSTDOUT "/dev/stdout"
|
#define _PATH_DEVSTDOUT _PATH_DEV "stdout"
|
||||||
#define _PATH_DEVSTDERR "/dev/stderr"
|
#define _PATH_DEVSTDERR _PATH_DEV "stderr"
|
||||||
#define _PATH_DEVSOCKET "/dev/socket"
|
#define _PATH_DEVSOCKET _PATH_DEV "socket"
|
||||||
|
|
||||||
// Special files and locations
|
// Special files and locations
|
||||||
#define _PATH_HOSTS "/Efi/etc/hosts"
|
#define _PATH_FSTAB _PATH_ETC "fstab"
|
||||||
#define _PATH_SERVICES "/Efi/etc/services"
|
////#define _PATH_HEQUIV _PATH_ETC "hosts.equiv"
|
||||||
#define _PATH_HOSTNAME "/Efi/etc/hostname"
|
#define _PATH_HOSTNAME _PATH_ETC "hostname"
|
||||||
#define _PATH_LOCALE "/Efi/etc/Locale"
|
#define _PATH_HOSTS _PATH_ETC "hosts"
|
||||||
#define _PATH_FSTAB "/Efi/etc/fstab"
|
#define _PATH_HOSTCONF _PATH_ETC "host.conf"
|
||||||
|
#define _PATH_LOCALE _PATH_ETC "Locale"
|
||||||
|
#define _PATH_NETCONF _PATH_ETC "host.conf"
|
||||||
|
#define _PATH_NETWORKS _PATH_ETC "networks"
|
||||||
|
#define _PATH_PROTOCOLS _PATH_ETC "protocols"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Provide trailing slash, since mostly used for building pathnames.
|
* Resolver configuration file.
|
||||||
* see the __CONCAT() macro from <sys/EfiCdefs.h> for cpp examples.
|
* Normally not present, but may contain the address of the
|
||||||
|
* inital name server(s) to query and the domain search list.
|
||||||
*/
|
*/
|
||||||
#define _PATH_DEV "/dev/"
|
#define _PATH_RESCONF _PATH_ETC "resolv.conf"
|
||||||
#define _PATH_TMP "/Efi/Temp/"
|
#define _PATH_SERVICES _PATH_ETC "services"
|
||||||
//#define _PATH_DEV_PTS "/dev/pts/"
|
////#define _PATH_SERVICES_DB "/Efi/var/db/services.db"
|
||||||
//#define _PATH_EMUL_AOUT "/emul/aout/"
|
|
||||||
//#define _PATH_VARDB "/var/db/"
|
|
||||||
//#define _PATH_VARRUN "/var/run/"
|
|
||||||
//#define _PATH_VARTMP "/var/tmp/"
|
|
||||||
|
|
||||||
//#define _PATH_BSHELL RESCUEDIR "/sh"
|
//#define _PATH_BSHELL RESCUEDIR "/sh"
|
||||||
//#define _PATH_CSHELL RESCUEDIR "/csh"
|
//#define _PATH_CSHELL RESCUEDIR "/csh"
|
||||||
|
145
StdLib/Include/pwd.h
Normal file
145
StdLib/Include/pwd.h
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
/* $NetBSD: pwd.h,v 1.39 2005/05/24 17:36:29 kleink Exp $ */
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Copyright (c) 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
* (c) UNIX System Laboratories, Inc.
|
||||||
|
* All or some portions of this file are derived from material licensed
|
||||||
|
* to the University of California by American Telephone and Telegraph
|
||||||
|
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
|
||||||
|
* the permission of UNIX System Laboratories, Inc.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*
|
||||||
|
* @(#)pwd.h 8.2 (Berkeley) 1/21/94
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*-
|
||||||
|
* Portions Copyright(C) 1995, Jason Downs. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``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 AUTHOR(S) 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PWD_H_
|
||||||
|
#define _PWD_H_
|
||||||
|
|
||||||
|
#include <sys/EfiCdefs.h>
|
||||||
|
#include <sys/featuretest.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#define _PATH_PASSWD "/etc/passwd"
|
||||||
|
#define _PATH_MASTERPASSWD "/etc/master.passwd"
|
||||||
|
#define _PATH_MASTERPASSWD_LOCK "/etc/ptmp"
|
||||||
|
|
||||||
|
#define _PATH_PASSWD_CONF "/etc/passwd.conf"
|
||||||
|
#define _PATH_PASSWDCONF _PATH_PASSWD_CONF /* XXX: compat */
|
||||||
|
#define _PATH_USERMGMT_CONF "/etc/usermgmt.conf"
|
||||||
|
|
||||||
|
#define _PATH_MP_DB "/etc/pwd.db"
|
||||||
|
#define _PATH_SMP_DB "/etc/spwd.db"
|
||||||
|
|
||||||
|
#define _PATH_PWD_MKDB "/usr/sbin/pwd_mkdb"
|
||||||
|
|
||||||
|
#define _PW_KEYBYNAME '1' /* stored by name */
|
||||||
|
#define _PW_KEYBYNUM '2' /* stored by entry in the "file" */
|
||||||
|
#define _PW_KEYBYUID '3' /* stored by uid */
|
||||||
|
|
||||||
|
#define _PASSWORD_EFMT1 '_' /* extended DES encryption format */
|
||||||
|
#define _PASSWORD_NONDES '$' /* non-DES encryption formats */
|
||||||
|
|
||||||
|
#define _PASSWORD_LEN 128 /* max length, not counting NUL */
|
||||||
|
|
||||||
|
#define _PASSWORD_NOUID 0x01 /* flag for no specified uid. */
|
||||||
|
#define _PASSWORD_NOGID 0x02 /* flag for no specified gid. */
|
||||||
|
#define _PASSWORD_NOCHG 0x04 /* flag for no specified change. */
|
||||||
|
#define _PASSWORD_NOEXP 0x08 /* flag for no specified expire. */
|
||||||
|
|
||||||
|
#define _PASSWORD_OLDFMT 0x10 /* flag to expect an old style entry */
|
||||||
|
#define _PASSWORD_NOWARN 0x20 /* no warnings for bad entries */
|
||||||
|
|
||||||
|
#define _PASSWORD_WARNDAYS 14 /* days to warn about expiry */
|
||||||
|
#define _PASSWORD_CHGNOW -1 /* special day to force password
|
||||||
|
* change at next login */
|
||||||
|
|
||||||
|
struct passwd {
|
||||||
|
__aconst char *pw_name; /* user name */
|
||||||
|
__aconst char *pw_passwd; /* encrypted password */
|
||||||
|
uid_t pw_uid; /* user uid */
|
||||||
|
gid_t pw_gid; /* user gid */
|
||||||
|
time_t pw_change; /* password change time */
|
||||||
|
__aconst char *pw_class; /* user login class */
|
||||||
|
__aconst char *pw_gecos; /* general information */
|
||||||
|
__aconst char *pw_dir; /* home directory */
|
||||||
|
__aconst char *pw_shell; /* default shell */
|
||||||
|
time_t pw_expire; /* account expiration */
|
||||||
|
};
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
struct passwd *getpwuid(uid_t);
|
||||||
|
struct passwd *getpwnam(const char *);
|
||||||
|
|
||||||
|
#if 0 /* Normally declared here but not implemented for UEFI. */
|
||||||
|
|
||||||
|
int getpwnam_r( const char *, struct passwd *, char *, size_t,
|
||||||
|
struct passwd **);
|
||||||
|
int getpwuid_r( uid_t, struct passwd *, char *, size_t,
|
||||||
|
struct passwd **);
|
||||||
|
|
||||||
|
struct passwd *getpwent(void);
|
||||||
|
void setpwent(void);
|
||||||
|
void endpwent(void);
|
||||||
|
|
||||||
|
int pw_gensalt(char *, size_t, const char *, const char *);
|
||||||
|
int pw_scan(char *, struct passwd *, int *);
|
||||||
|
int setpassent(int);
|
||||||
|
int getpwent_r(struct passwd *, char *, size_t, struct passwd **);
|
||||||
|
const char *user_from_uid(uid_t, int);
|
||||||
|
int uid_from_user(const char *, uid_t *);
|
||||||
|
int pwcache_userdb( int (*)(int), void (*)(void),
|
||||||
|
struct passwd * (*)(const char *),
|
||||||
|
struct passwd * (*)(uid_t));
|
||||||
|
#endif
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* !_PWD_H_ */
|
293
StdLib/Include/resolv.h
Normal file
293
StdLib/Include/resolv.h
Normal file
@ -0,0 +1,293 @@
|
|||||||
|
/*-
|
||||||
|
* Copyright (c) 1983, 1987, 1989, 1993
|
||||||
|
* The Regents of the University of California. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. All advertising materials mentioning features or use of this software
|
||||||
|
* must display the following acknowledgement:
|
||||||
|
* This product includes software developed by the University of
|
||||||
|
* California, Berkeley and its contributors.
|
||||||
|
* 4. Neither the name of the University nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Portions Copyright (c) 1996 by Internet Software Consortium.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
||||||
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
||||||
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
||||||
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
||||||
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @(#)resolv.h 8.1 (Berkeley) 6/2/93
|
||||||
|
* From Id: resolv.h,v 8.12 1998/04/28 19:36:46 halley Exp $
|
||||||
|
* $Id: resolv.h,v 1.1.1.1 2003/11/19 01:48:35 kyu3 Exp $
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RESOLV_H_
|
||||||
|
#define _RESOLV_H_
|
||||||
|
|
||||||
|
#include <arpa/nameser.h>
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <paths.h>
|
||||||
|
|
||||||
|
#ifndef __P
|
||||||
|
#define __P(x) x
|
||||||
|
#endif // __P
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Revision information. This is the release date in YYYYMMDD format.
|
||||||
|
* It can change every day so the right thing to do with it is use it
|
||||||
|
* in preprocessor commands such as "#if (__RES > 19931104)". Do not
|
||||||
|
* compare for equality; rather, use it to determine whether your resolver
|
||||||
|
* is new enough to contain a certain feature.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define __RES 19960801
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Global defines and variables for resolver stub.
|
||||||
|
*/
|
||||||
|
#define MAXNS 3 /* max # name servers we'll track */
|
||||||
|
#define MAXDFLSRCH 3 /* # default domain levels to try */
|
||||||
|
#define MAXDNSRCH 6 /* max # domains in search path */
|
||||||
|
#define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */
|
||||||
|
|
||||||
|
#define RES_TIMEOUT 5 /* min. seconds between retries */
|
||||||
|
#define MAXRESOLVSORT 10 /* number of net to sort on */
|
||||||
|
#define RES_MAXNDOTS 15 /* should reflect bit field size */
|
||||||
|
|
||||||
|
struct __res_state {
|
||||||
|
int retrans; /* retransmition time interval */
|
||||||
|
int retry; /* number of times to retransmit */
|
||||||
|
u_long options; /* option flags - see below. */
|
||||||
|
int nscount; /* number of name servers */
|
||||||
|
struct sockaddr_in
|
||||||
|
nsaddr_list[MAXNS]; /* address of name server */
|
||||||
|
#define nsaddr nsaddr_list[0] /* for backward compatibility */
|
||||||
|
u_short id; /* current message id */
|
||||||
|
char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */
|
||||||
|
char defdname[256]; /* default domain (deprecated) */
|
||||||
|
u_long pfcode; /* RES_PRF_ flags - see below. */
|
||||||
|
unsigned ndots:4; /* threshold for initial abs. query */
|
||||||
|
unsigned nsort:4; /* number of elements in sort_list[] */
|
||||||
|
char unused[3];
|
||||||
|
struct {
|
||||||
|
struct in_addr addr;
|
||||||
|
u_int32_t mask;
|
||||||
|
} sort_list[MAXRESOLVSORT];
|
||||||
|
char pad[72]; /* on an i386 this means 512b total */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolver options (keep these in synch with res_debug.c, please)
|
||||||
|
*/
|
||||||
|
#define RES_INIT 0x00000001 /* address initialized */
|
||||||
|
#define RES_DEBUG 0x00000002 /* print debug messages */
|
||||||
|
#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
|
||||||
|
#define RES_USEVC 0x00000008 /* use virtual circuit */
|
||||||
|
#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
|
||||||
|
#define RES_IGNTC 0x00000020 /* ignore truncation errors */
|
||||||
|
#define RES_RECURSE 0x00000040 /* recursion desired */
|
||||||
|
#define RES_DEFNAMES 0x00000080 /* use default domain name */
|
||||||
|
#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
|
||||||
|
#define RES_DNSRCH 0x00000200 /* search up local domain tree */
|
||||||
|
#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
|
||||||
|
#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
|
||||||
|
#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
|
||||||
|
#define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */
|
||||||
|
#define RES_NOTLDQUERY 0x00004000 /* Don't query TLD names */
|
||||||
|
|
||||||
|
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Resolver "pfcode" values. Used by dig.
|
||||||
|
*/
|
||||||
|
#define RES_PRF_STATS 0x00000001
|
||||||
|
#define RES_PRF_UPDATE 0x00000002
|
||||||
|
#define RES_PRF_CLASS 0x00000004
|
||||||
|
#define RES_PRF_CMD 0x00000008
|
||||||
|
#define RES_PRF_QUES 0x00000010
|
||||||
|
#define RES_PRF_ANS 0x00000020
|
||||||
|
#define RES_PRF_AUTH 0x00000040
|
||||||
|
#define RES_PRF_ADD 0x00000080
|
||||||
|
#define RES_PRF_HEAD1 0x00000100
|
||||||
|
#define RES_PRF_HEAD2 0x00000200
|
||||||
|
#define RES_PRF_TTLID 0x00000400
|
||||||
|
#define RES_PRF_HEADX 0x00000800
|
||||||
|
#define RES_PRF_QUERY 0x00001000
|
||||||
|
#define RES_PRF_REPLY 0x00002000
|
||||||
|
#define RES_PRF_INIT 0x00004000
|
||||||
|
/* 0x00008000 */
|
||||||
|
|
||||||
|
typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
|
||||||
|
res_sendhookact;
|
||||||
|
|
||||||
|
typedef res_sendhookact (*res_send_qhook)__P((struct sockaddr_in * const *ns,
|
||||||
|
const u_char **query,
|
||||||
|
int *querylen,
|
||||||
|
u_char *ans,
|
||||||
|
int anssiz,
|
||||||
|
int *resplen));
|
||||||
|
|
||||||
|
typedef res_sendhookact (*res_send_rhook)__P((const struct sockaddr_in *ns,
|
||||||
|
const u_char *query,
|
||||||
|
int querylen,
|
||||||
|
u_char *ans,
|
||||||
|
int anssiz,
|
||||||
|
int *resplen));
|
||||||
|
|
||||||
|
struct res_sym {
|
||||||
|
int number; /* Identifying number, like T_MX */
|
||||||
|
char * name; /* Its symbolic name, like "MX" */
|
||||||
|
char * humanname; /* Its fun name, like "mail exchanger" */
|
||||||
|
};
|
||||||
|
|
||||||
|
extern struct __res_state _res;
|
||||||
|
extern const struct res_sym __p_class_syms[];
|
||||||
|
extern const struct res_sym __p_type_syms[];
|
||||||
|
|
||||||
|
/* Private routines shared between libc/net, named, nslookup and others. */
|
||||||
|
#define res_hnok __res_hnok
|
||||||
|
#define res_ownok __res_ownok
|
||||||
|
#define res_mailok __res_mailok
|
||||||
|
#define res_dnok __res_dnok
|
||||||
|
#define sym_ston __sym_ston
|
||||||
|
#define sym_ntos __sym_ntos
|
||||||
|
#define sym_ntop __sym_ntop
|
||||||
|
#define b64_ntop __b64_ntop
|
||||||
|
#define b64_pton __b64_pton
|
||||||
|
#define loc_ntoa __loc_ntoa
|
||||||
|
#define loc_aton __loc_aton
|
||||||
|
#define fp_resstat __fp_resstat
|
||||||
|
#define p_query __p_query
|
||||||
|
#define dn_skipname __dn_skipname
|
||||||
|
#define fp_resstat __fp_resstat
|
||||||
|
#define fp_query __fp_query
|
||||||
|
#define fp_nquery __fp_nquery
|
||||||
|
#define hostalias __hostalias
|
||||||
|
#define putlong __putlong
|
||||||
|
#define putshort __putshort
|
||||||
|
#define p_class __p_class
|
||||||
|
#define p_time __p_time
|
||||||
|
#define p_type __p_type
|
||||||
|
#define p_query __p_query
|
||||||
|
#define p_cdnname __p_cdnname
|
||||||
|
#define p_section __p_section
|
||||||
|
#define p_cdname __p_cdname
|
||||||
|
#define p_fqnname __p_fqnname
|
||||||
|
#define p_fqname __p_fqname
|
||||||
|
#define p_option __p_option
|
||||||
|
#define p_secstodate __p_secstodate
|
||||||
|
#define dn_count_labels __dn_count_labels
|
||||||
|
#define dn_comp __dn_comp
|
||||||
|
#define dn_expand __dn_expand
|
||||||
|
#define res_init __res_init
|
||||||
|
#define res_randomid __res_randomid
|
||||||
|
#define res_query __res_query
|
||||||
|
#define res_search __res_search
|
||||||
|
#define res_querydomain __res_querydomain
|
||||||
|
#define res_mkquery __res_mkquery
|
||||||
|
#define res_send __res_send
|
||||||
|
#define res_isourserver __res_isourserver
|
||||||
|
#define res_nameinquery __res_nameinquery
|
||||||
|
#define res_queriesmatch __res_queriesmatch
|
||||||
|
#define res_close __res_close
|
||||||
|
#define res_mkupdate __res_mkupdate
|
||||||
|
#define res_mkupdrec __res_mkupdrec
|
||||||
|
#define res_freeupdrec __res_freeupdrec
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
int res_hnok __P((const char *));
|
||||||
|
int res_ownok __P((const char *));
|
||||||
|
int res_mailok __P((const char *));
|
||||||
|
int res_dnok __P((const char *));
|
||||||
|
int sym_ston __P((const struct res_sym *, const char *, int *));
|
||||||
|
const char * sym_ntos __P((const struct res_sym *, int, int *));
|
||||||
|
const char * sym_ntop __P((const struct res_sym *, int, int *));
|
||||||
|
int b64_ntop __P((u_char const *, size_t, char *, size_t));
|
||||||
|
int b64_pton __P((char const *, u_char *, size_t));
|
||||||
|
int loc_aton __P((const char *, u_char *));
|
||||||
|
const char * loc_ntoa __P((const u_char *, char *));
|
||||||
|
int dn_skipname __P((const u_char *, const u_char *));
|
||||||
|
void fp_resstat __P((struct __res_state *, FILE *));
|
||||||
|
void fp_query __P((const u_char *, FILE *));
|
||||||
|
void fp_nquery __P((const u_char *, int, FILE *));
|
||||||
|
const char * hostalias __P((const char *));
|
||||||
|
void putlong __P((u_int32_t, u_char *));
|
||||||
|
void putshort __P((u_int16_t, u_char *));
|
||||||
|
const char * p_class __P((int));
|
||||||
|
const char * p_time __P((u_int32_t));
|
||||||
|
const char * p_type __P((int));
|
||||||
|
void p_query __P((const u_char *));
|
||||||
|
const u_char * p_cdnname __P((const u_char *, const u_char *, int, FILE *));
|
||||||
|
const u_char * p_cdname __P((const u_char *, const u_char *, FILE *));
|
||||||
|
const u_char * p_fqnname __P((const u_char *, const u_char *,
|
||||||
|
int, char *, int));
|
||||||
|
const u_char * p_fqname __P((const u_char *, const u_char *, FILE *));
|
||||||
|
const char * p_option __P((u_long));
|
||||||
|
char * p_secstodate __P((u_long));
|
||||||
|
int dn_count_labels __P((const char *));
|
||||||
|
int dn_comp __P((const char *, u_char *, int,
|
||||||
|
u_char **, u_char **));
|
||||||
|
int dn_expand __P((const u_char *, const u_char *, const u_char *,
|
||||||
|
char *, int));
|
||||||
|
int res_init __P((void));
|
||||||
|
u_int res_randomid __P((void));
|
||||||
|
int res_query __P((const char *, int, int, u_char *, int));
|
||||||
|
int res_search __P((const char *, int, int, u_char *, int));
|
||||||
|
int res_querydomain __P((const char *, const char *, int, int,
|
||||||
|
u_char *, int));
|
||||||
|
int res_mkquery __P((int, const char *, int, int, const u_char *,
|
||||||
|
int, const u_char *, u_char *, int));
|
||||||
|
int res_send __P((const u_char *, int, u_char *, int));
|
||||||
|
int res_isourserver __P((const struct sockaddr_in *));
|
||||||
|
int res_nameinquery __P((const char *, int, int,
|
||||||
|
const u_char *, const u_char *));
|
||||||
|
int res_queriesmatch __P((const u_char *, const u_char *,
|
||||||
|
const u_char *, const u_char *));
|
||||||
|
void res_close __P((void));
|
||||||
|
const char * p_section __P((int, int));
|
||||||
|
/* XXX The following depend on the ns_updrec typedef in arpa/nameser.h */
|
||||||
|
#ifdef _ARPA_NAMESER_H_
|
||||||
|
int res_update __P((ns_updrec *));
|
||||||
|
int res_mkupdate __P((ns_updrec *, u_char *, int));
|
||||||
|
ns_updrec * res_mkupdrec __P((int, const char *, u_int, u_int, u_long));
|
||||||
|
void res_freeupdrec __P((ns_updrec *));
|
||||||
|
#endif
|
||||||
|
__END_DECLS
|
||||||
|
|
||||||
|
#endif /* !_RESOLV_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user