* Removed old network stuff.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29874 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-04-03 07:45:14 +00:00
parent 674996257b
commit 563db5d400
78 changed files with 0 additions and 16477 deletions

View File

@ -1,8 +0,0 @@
SubDir HAIKU_TOP src kits network ;
Package haiku-networkingkit-cvs :
README.html install.sh
;
SubInclude HAIKU_TOP src kits network compat ;
SubInclude HAIKU_TOP src kits network libnetwork ;

View File

@ -1,62 +0,0 @@
<HTML>
<HEAD><TITLE>Haiku Networking Kit Package</TITLE></HEAD>
<BODY BGCOLOR=#FFFFFF TEXT=#000000>
<H2>Haiku Networking Kit Package</H2>
<H3>About</H3>
This package was created to allow BeOS users to have the latest version of the Haiku Networking Kit, without having to compile it themselves. This also lets BeOS users take advantage of bug fixes and new features without having to wait for the next beta release of the Networking Kit.
<P>
However, because this package is made from the latest sources, experimental and unstable features may be present. Such features may cause some programs to behave abnormally.
<P>
USE AT YOUR OWN RISK.
<H3>Included Files</H3>
Currently, this package is intended to contain the Haiku Networking Kit and all of the Haiku network drivers. This may change in the future.
<P>
Files:<BR>
boot/home/config/lib/libnet.so<BR>
boot/home/config/lib/libnetapi.so<BR>
boot/home/config/lib/libsocket.so<BR>
boot/home/config/lib/libbind.so<BR>
boot/home/config/add-ons/kernel/drivers/bin/net_stack_driver<BR>
boot/home/config/add-ons/kernel/drivers/bin/net_server_driver<BR>
boot/home/config/add-ons/kernel/drivers/bin/sis900<BR>
boot/home/config/add-ons/kernel/drivers/bin/rtl8139<BR>
boot/home/config/add-ons/kernel/drivers/bin/rtl8169<BR>
boot/home/config/add-ons/kernel/drivers/bin/via-rhine<BR>
boot/home/config/add-ons/kernel/drivers/bin/wb840<BR>
boot/home/config/add-ons/kernel/drivers/bin/ipro1000<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/net_stack_driver (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/net_server_driver (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/sis900 (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/rtl8139 (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/rtl8169 (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/via-rhine (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/wb840 (link)<BR>
boot/home/config/add-ons/kernel/drivers/dev/net/ipro1000 (link)<BR>
boot/home/config/add-ons/kernel/obos_network/core<BR>
boot/home/config/add-ons/kernel/obos_network/interfaces/ether_drivers<BR>
boot/home/config/add-ons/kernel/obos_network/interfaces/loopback<BR>
boot/home/config/add-ons/kernel/obos_network/interfaces/ppp<BR>
boot/home/config/add-ons/kernel/obos_network/ppp/ipcp<BR>
boot/home/config/add-ons/kernel/obos_network/ppp/modem<BR>
boot/home/config/add-ons/kernel/obos_network/ppp/pap<BR>
boot/home/config/add-ons/kernel/obos_network/ppp/pppoe<BR>
boot/home/config/add-ons/kernel/obos_network/protocols/icmp<BR>
boot/home/config/add-ons/kernel/obos_network/protocols/ipv4<BR>
boot/home/config/add-ons/kernel/obos_network/protocols/raw<BR>
boot/home/config/add-ons/kernel/obos_network/protocols/route<BR>
boot/home/config/add-ons/kernel/obos_network/protocols/tcp<BR>
boot/home/config/add-ons/kernel/obos_network/protocols/udp<BR>
<H3>Installing</H3>
To install this package, simply double-click on the install.sh script. The install process WILL NOT change any of the system files. Because the files are copied to under the home folder, they will be loaded instead of the BeOS system files.
<H3>Bugs</H3>
As always, if you find a bug with the Networking Kit, please e-mail me at phoudoin &lt;@t&gt; users | sourceforge | net. Please include the date of the package in your e-mail so I know which version of the files you are seeing bugs with.
</BODY>
</HTML>

View File

@ -1,6 +0,0 @@
SubDir HAIKU_TOP src kits network compat ;
SubInclude HAIKU_TOP src kits network compat libbind ;
SubInclude HAIKU_TOP src kits network compat libnet ;
SubInclude HAIKU_TOP src kits network compat libnetapi ;
SubInclude HAIKU_TOP src kits network compat libsocket ;

View File

@ -1,9 +0,0 @@
See libnetwork/dns/DEVNOTES for general notes. This file contains information about the legacy libbind.so.
This folder and the headers folder contained within override the respective libnetwork/dns folder. Additionally, the legacy headers override the default posix headers.
The src folder is imported for sources. Currently, it is empty.
You may import files from Haiku's libroot.so if funtionality is missing.
libbind.so links against libnet.so because it needs gethostname() on non-Haiku targets.

View File

@ -1,216 +0,0 @@
SubDir HAIKU_TOP src kits network compat libbind ;
SetSubDirSupportedPlatformsBeOSCompatible ;
LIBNETWORK_DNS_DIR = $(HAIKU_TOP) src kits network libnetwork dns ;
UseHeaders [ FDirName $(SUBDIR) headers ] : true ;
UsePrivateHeaders net ;
UseHeaders [ FDirName $(HAIKU_TOP) headers legacy network ] : true ;
SubDirSysHdrs $(SUBDIR) ;
UseHeaders [ FDirName $(LIBNETWORK_DNS_DIR) headers ] : true ;
SubDirSysHdrs $(LIBNETWORK_DNS_DIR) ;
if $(TARGET_PLATFORM) != haiku {
UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ;
# We need the public network headers also when not compiling for Haiku.
# Unfortunately we get more than we want, namely all POSIX headers.
UseHeaders [ FStandardOSHeaders ] : true ;
# Needed for <support/Errors.h> and maybe other stuff.
# Remove _NO_INLINE_ASM from the defines. Otherwise we get
# references to tls_get/set() etc. that don't exist under BeOS.
TARGET_DEFINES = [ FFilter $(TARGET_DEFINES) : _NO_INLINE_ASM ] ;
}
# our libroot contains functions that are missing in BeOS (e.g.: strlcat)
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src system libroot posix string ] ;
# private sources for this port
SEARCH_SOURCE += [ FDirName $(SUBDIR) src ] ;
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) src ] ;
# BIND sources
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) dst ] ;
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) inet ] ;
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) irs ] ;
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) isc ] ;
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) nameser ] ;
SEARCH_SOURCE += [ FDirName $(LIBNETWORK_DNS_DIR) resolv ] ;
{
# Default libs include BeOS R5 libnet.so, something we don't want here!
LINKFLAGS on libbind.so = [ on libbind.so return $(LINKFLAGS) ] -nodefaultlibs ;
# we want to have the xxx_r functions, too
local defines = _REENTRANT=1 NO_SOCKADDR_UN=1 ISC_SOCKLEN_T=int ;
defines = [ FDefines $(defines) ] ;
SubDirCcFlags $(defines) ;
SubDirC++Flags $(defines) ;
}
MergeObject <compatlibbind>dst.o :
dst_api.c
hmac_link.c
md5_dgst.c
support.c
;
MergeObject <compatlibbind>inet.o :
inet_addr.c
inet_cidr_ntop.c
inet_cidr_pton.c
inet_data.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
nsap_addr.c
;
MergeObject <compatlibbind>irs.o :
dns.c
dns_ho.c
dns_nw.c
dns_pr.c
dns_sv.c
gai_strerror.c
gen.c
gen_ho.c
gen_ng.c
gen_nw.c
gen_pr.c
gen_sv.c
getaddrinfo.c
gethostent.c
gethostent_r.c
getnameinfo.c
getnetent.c
getnetent_r.c
getnetgrent.c
getnetgrent_r.c
getprotoent.c
getprotoent_r.c
getservent.c
getservent_r.c
hesiod.c
irp.c
irp_ho.c
irp_ng.c
irp_nw.c
irp_pr.c
irp_sv.c
irpmarshall.c
irs_data.c
lcl.c
lcl_ho.c
lcl_ng.c
lcl_nw.c
lcl_pr.c
lcl_sv.c
nis.c
nul_ng.c
util.c
;
MergeObject <compatlibbind>isc.o :
assertions.c
base64.c
bitncmp.c
ctl_clnt.c
ctl_p.c
ctl_srvr.c
ev_connects.c
ev_files.c
ev_streams.c
ev_timers.c
ev_waits.c
eventlib.c
heap.c
hex.c
logging.c
memcluster.c
movefile.c
tree.c
;
MergeObject <compatlibbind>nameser.o :
ns_date.c
ns_name.c
ns_netint.c
ns_parse.c
ns_print.c
ns_samedomain.c
ns_sign.c
ns_ttl.c
ns_verify.c
;
MergeObject <compatlibbind>resolv.o :
herror.c
res_comp.c
res_data.c
res_debug.c
res_findzonecut.c
res_init.c
res_mkquery.c
res_mkupdate.c
res_query.c
res_send.c
res_sendsigned.c
res_update.c
;
SharedLibrary libbind.so :
# functions from our libroot
# TODO: these can be removed for the Haiku build
strlcat.c
# private functions
arc4random.c
ethers.c
gettimeofday.c
linkaddr.c
res_resultcodes.c
strsep.c
# UGLY HACK
TLSInit.cpp
;
LinkAgainst libbind.so :
<compatlibbind>dst.o
<compatlibbind>inet.o
<compatlibbind>irs.o
<compatlibbind>isc.o # (not used)
<compatlibbind>nameser.o
<compatlibbind>resolv.o
libsocket.so
libnet.so # for gethostname()
be
root
;
# Installation -- in the test directory for the time being
HaikuInstallRelSymLink install-networking
: [ FDirName $(HAIKU_TEST_DIR) kits net lib ]
: libbind.so
: installed-networking-test ;
HaikuInstallRelSymLink install-userland-networking
: [ FDirName $(HAIKU_TEST_DIR) kits net userland lib ]
: libbind.so
: installed-userland-networking ;
Package haiku-networkingkit-cvs :
libbind.so :
# boot home config lib ;
boot home Desktop haiku-networkingkit lib ;

View File

@ -1,54 +0,0 @@
/* config.h. Generated by configure. */
/* #undef _SOCKADDR_LEN */
#define HAVE_FCNTL_H 1
/* #undef HAVE_PATHS_H */
/* #undef HAVE_SYS_TIMERS_H */
/* #undef SYS_CDEFS_H */
/* #undef _POSIX_PTHREAD_SEMANTICS */
/* #undef POSIX_GETPWUID_R */
/* #undef POSIX_GETPWNAM_R */
/* #undef POSIX_GETGRGID_R */
/* #undef POSIX_GETGRNAM_R */
#define NEED_SETGROUPENT 1
#define NEED_GETGROUPLIST 1
/* define if prototype for getgrnam_r() is required */
#define NEED_GETGRNAM_R 1
#define NEED_GETGRGID_R 1
#define NEED_GETGRENT_R 1
#define NEED_SETGRENT_R 1
#define NEED_ENDGRENT_R 1
#define NEED_INNETGR_R 1
/* #undef NEED_SETNETGRENT_R */
#define NEED_ENDNETGRENT_R 1
#define NEED_GETPWNAM_R 1
#define NEED_GETPWUID_R 1
#define NEED_SETPWENT_R 1
#define NEED_SETPASSENT_R 1
#define NEED_SETPWENT_R 1
#define NEED_GETPWENT_R 1
#define NEED_ENDPWENT_R 1
#define NEED_SETPASSENT 1
/* #undef HAS_PW_CLASS */
/* Shut up warnings about sputaux in stdio.h on BSD/OS pre-4.1 */
/* #undef SHUTUP_SPUTAUX */
#ifdef SHUTUP_SPUTAUX
struct __sFILE;
extern __inline int __sputaux(int _c, struct __sFILE *_p);
#endif
/* #undef BROKEN_IN6ADDR_INIT_MACROS */
/* #undef HAVE_STRLCAT */
/* Shut up warnings about missing braces */
/* #undef SHUTUP_MUTEX_INITIALIZER */
#ifdef SHUTUP_MUTEX_INITIALIZER
#define LIBBIND_MUTEX_INITIALIZER { PTHREAD_MUTEX_INITIALIZER }
#else
#define LIBBIND_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif

View File

@ -1,9 +0,0 @@
#ifndef _FD_SETSIZE_H
#define _FD_SETSIZE_H
/*
* If you need a bigger FD_SETSIZE, this is NOT the place to set it.
* This file is a fallback for BIND ports which don't specify their own.
*/
#endif /* _FD_SETSIZE_H */

View File

@ -1,103 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#ifndef _IRP_H_INCLUDED
#define _IRP_H_INCLUDED
#define IRPD_TIMEOUT 30 /* seconds */
#define IRPD_MAXSESS 50 /* number of simultaneous sessions. */
#define IRPD_PORT 6660 /* 10 times the number of the beast. */
#define IRPD_PATH "/var/run/irpd" /* af_unix socket path */
/* If sets the environment variable IRPDSERVER to an IP address
(e.g. "192.5.5.1"), then that's the host the client expects irpd to be
running on. */
#define IRPD_HOST_ENV "IRPDSERVER"
/* Protocol response codes. */
#define IRPD_WELCOME_CODE 200
#define IRPD_NOT_WELCOME_CODE 500
#define IRPD_GETHOST_ERROR 510
#define IRPD_GETHOST_NONE 210
#define IRPD_GETHOST_OK 211
#define IRPD_GETHOST_SETOK 212
#define IRPD_GETNET_ERROR 520
#define IRPD_GETNET_NONE 220
#define IRPD_GETNET_OK 221
#define IRPD_GETNET_SETOK 222
#define IRPD_GETUSER_ERROR 530
#define IRPD_GETUSER_NONE 230
#define IRPD_GETUSER_OK 231
#define IRPD_GETUSER_SETOK 232
#define IRPD_GETGROUP_ERROR 540
#define IRPD_GETGROUP_NONE 240
#define IRPD_GETGROUP_OK 241
#define IRPD_GETGROUP_SETOK 242
#define IRPD_GETSERVICE_ERROR 550
#define IRPD_GETSERVICE_NONE 250
#define IRPD_GETSERVICE_OK 251
#define IRPD_GETSERVICE_SETOK 252
#define IRPD_GETPROTO_ERROR 560
#define IRPD_GETPROTO_NONE 260
#define IRPD_GETPROTO_OK 261
#define IRPD_GETPROTO_SETOK 262
#define IRPD_GETNETGR_ERROR 570
#define IRPD_GETNETGR_NONE 270
#define IRPD_GETNETGR_OK 271
#define IRPD_GETNETGR_NOMORE 272
#define IRPD_GETNETGR_MATCHES 273
#define IRPD_GETNETGR_NOMATCH 274
#define IRPD_GETNETGR_SETOK 275
#define IRPD_GETNETGR_SETERR 276
#define irs_irp_read_body __irs_irp_read_body
#define irs_irp_read_response __irs_irp_read_response
#define irs_irp_disconnect __irs_irp_disconnect
#define irs_irp_connect __irs_irp_connect
#define irs_irp_connection_setup __irs_irp_connection_setup
#define irs_irp_send_command __irs_irp_send_command
struct irp_p;
char *irs_irp_read_body(struct irp_p *, size_t *);
int irs_irp_read_response(struct irp_p *, char *, size_t);
void irs_irp_disconnect(struct irp_p *);
int irs_irp_connect(struct irp_p *);
int irs_irp_is_connected(struct irp_p *);
int irs_irp_connection_setup(struct irp_p *, int *);
#ifdef __GNUC__
int irs_irp_send_command(struct irp_p *, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
#else
int irs_irp_send_command(struct irp_p *, const char *, ...);
#endif
int irs_irp_get_full_response(struct irp_p *, int *, char *, size_t,
char **, size_t *);
int irs_irp_read_line(struct irp_p *, char *, int);
#endif

View File

@ -1,345 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996,1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#ifndef _IRS_H_INCLUDED
#define _IRS_H_INCLUDED
#include <sys/types.h>
#include <arpa/nameser.h>
#include <grp.h>
#include <netdb.h>
#include <resolv.h>
#include <pwd.h>
/*
* This is the group map class.
*/
struct irs_gr {
void * private;
void (*close) __P((struct irs_gr *));
struct group * (*next) __P((struct irs_gr *));
struct group * (*byname) __P((struct irs_gr *, const char *));
struct group * (*bygid) __P((struct irs_gr *, gid_t));
int (*list) __P((struct irs_gr *, const char *,
gid_t, gid_t *, int *));
void (*rewind) __P((struct irs_gr *));
void (*minimize) __P((struct irs_gr *));
struct __res_state * (*res_get) __P((struct irs_gr *));
void (*res_set) __P((struct irs_gr *, res_state,
void (*)(void *)));
};
/*
* This is the password map class.
*/
struct irs_pw {
void * private;
void (*close) __P((struct irs_pw *));
struct passwd * (*next) __P((struct irs_pw *));
struct passwd * (*byname) __P((struct irs_pw *, const char *));
struct passwd * (*byuid) __P((struct irs_pw *, uid_t));
void (*rewind) __P((struct irs_pw *));
void (*minimize) __P((struct irs_pw *));
struct __res_state * (*res_get) __P((struct irs_pw *));
void (*res_set) __P((struct irs_pw *, res_state,
void (*)(void *)));
};
/*
* This is the service map class.
*/
struct irs_sv {
void * private;
void (*close) __P((struct irs_sv *));
struct servent *(*byname) __P((struct irs_sv *,
const char *, const char *));
struct servent *(*byport) __P((struct irs_sv *, int, const char *));
struct servent *(*next) __P((struct irs_sv *));
void (*rewind) __P((struct irs_sv *));
void (*minimize) __P((struct irs_sv *));
struct __res_state * (*res_get) __P((struct irs_sv *));
void (*res_set) __P((struct irs_sv *, res_state,
void (*)(void *)));
};
/*
* This is the protocols map class.
*/
struct irs_pr {
void * private;
void (*close) __P((struct irs_pr *));
struct protoent *(*byname) __P((struct irs_pr *, const char *));
struct protoent *(*bynumber) __P((struct irs_pr *, int));
struct protoent *(*next) __P((struct irs_pr *));
void (*rewind) __P((struct irs_pr *));
void (*minimize) __P((struct irs_pr *));
struct __res_state * (*res_get) __P((struct irs_pr *));
void (*res_set) __P((struct irs_pr *, res_state,
void (*)(void *)));
};
/*
* This is the hosts map class.
*/
struct irs_ho {
void * private;
void (*close) __P((struct irs_ho *));
struct hostent *(*byname) __P((struct irs_ho *, const char *));
struct hostent *(*byname2) __P((struct irs_ho *, const char *, int));
struct hostent *(*byaddr) __P((struct irs_ho *,
const void *, int, int));
struct hostent *(*next) __P((struct irs_ho *));
void (*rewind) __P((struct irs_ho *));
void (*minimize) __P((struct irs_ho *));
struct __res_state * (*res_get) __P((struct irs_ho *));
void (*res_set) __P((struct irs_ho *, res_state,
void (*)(void *)));
struct addrinfo *(*addrinfo) __P((struct irs_ho *, const char *,
const struct addrinfo *));
};
/*
* This is the networks map class.
*/
struct irs_nw {
void * private;
void (*close) __P((struct irs_nw *));
struct nwent * (*byname) __P((struct irs_nw *, const char *, int));
struct nwent * (*byaddr) __P((struct irs_nw *, void *, int, int));
struct nwent * (*next) __P((struct irs_nw *));
void (*rewind) __P((struct irs_nw *));
void (*minimize) __P((struct irs_nw *));
struct __res_state * (*res_get) __P((struct irs_nw *));
void (*res_set) __P((struct irs_nw *, res_state,
void (*)(void *)));
};
/*
* This is the netgroups map class.
*/
struct irs_ng {
void * private;
void (*close) __P((struct irs_ng *));
int (*next) __P((struct irs_ng *, const char **,
const char **, const char **));
int (*test) __P((struct irs_ng *, const char *,
const char *, const char *,
const char *));
void (*rewind) __P((struct irs_ng *, const char *));
void (*minimize) __P((struct irs_ng *));
};
/*
* This is the generic map class, which copies the front of all others.
*/
struct irs_map {
void * private;
void (*close) __P((void *));
};
/*
* This is the accessor class. It contains pointers to all of the
* initializers for the map classes for a particular accessor.
*/
struct irs_acc {
void * private;
void (*close) __P((struct irs_acc *));
struct irs_gr * (*gr_map) __P((struct irs_acc *));
struct irs_pw * (*pw_map) __P((struct irs_acc *));
struct irs_sv * (*sv_map) __P((struct irs_acc *));
struct irs_pr * (*pr_map) __P((struct irs_acc *));
struct irs_ho * (*ho_map) __P((struct irs_acc *));
struct irs_nw * (*nw_map) __P((struct irs_acc *));
struct irs_ng * (*ng_map) __P((struct irs_acc *));
struct __res_state * (*res_get) __P((struct irs_acc *));
void (*res_set) __P((struct irs_acc *, res_state,
void (*)(void *)));
};
/*
* This is because the official definition of "struct netent" has no
* concept of CIDR even though it allows variant address families (on
* output but not input). The compatibility stubs convert the structs
* below into "struct netent"'s.
*/
struct nwent {
char *n_name; /* official name of net */
char **n_aliases; /* alias list */
int n_addrtype; /* net address type */
void *n_addr; /* network address */
int n_length; /* address length, in bits */
};
/*
* Hide external function names from POSIX.
*/
#define irs_gen_acc __irs_gen_acc
#define irs_lcl_acc __irs_lcl_acc
#define irs_dns_acc __irs_dns_acc
#define irs_nis_acc __irs_nis_acc
#define irs_irp_acc __irs_irp_acc
#define irs_destroy __irs_destroy
#define irs_dns_gr __irs_dns_gr
#define irs_dns_ho __irs_dns_ho
#define irs_dns_nw __irs_dns_nw
#define irs_dns_pr __irs_dns_pr
#define irs_dns_pw __irs_dns_pw
#define irs_dns_sv __irs_dns_sv
#define irs_gen_gr __irs_gen_gr
#define irs_gen_ho __irs_gen_ho
#define irs_gen_ng __irs_gen_ng
#define irs_gen_nw __irs_gen_nw
#define irs_gen_pr __irs_gen_pr
#define irs_gen_pw __irs_gen_pw
#define irs_gen_sv __irs_gen_sv
#define irs_irp_get_full_response __irs_irp_get_full_response
#define irs_irp_gr __irs_irp_gr
#define irs_irp_ho __irs_irp_ho
#define irs_irp_is_connected __irs_irp_is_connected
#define irs_irp_ng __irs_irp_ng
#define irs_irp_nw __irs_irp_nw
#define irs_irp_pr __irs_irp_pr
#define irs_irp_pw __irs_irp_pw
#define irs_irp_read_line __irs_irp_read_line
#define irs_irp_sv __irs_irp_sv
#define irs_lcl_gr __irs_lcl_gr
#define irs_lcl_ho __irs_lcl_ho
#define irs_lcl_ng __irs_lcl_ng
#define irs_lcl_nw __irs_lcl_nw
#define irs_lcl_pr __irs_lcl_pr
#define irs_lcl_pw __irs_lcl_pw
#define irs_lcl_sv __irs_lcl_sv
#define irs_nis_gr __irs_nis_gr
#define irs_nis_ho __irs_nis_ho
#define irs_nis_ng __irs_nis_ng
#define irs_nis_nw __irs_nis_nw
#define irs_nis_pr __irs_nis_pr
#define irs_nis_pw __irs_nis_pw
#define irs_nis_sv __irs_nis_sv
#define net_data_create __net_data_create
#define net_data_destroy __net_data_destroy
#define net_data_minimize __net_data_minimize
/*
* Externs.
*/
extern struct irs_acc * irs_gen_acc __P((const char *, const char *));
extern struct irs_acc * irs_lcl_acc __P((const char *));
extern struct irs_acc * irs_dns_acc __P((const char *));
extern struct irs_acc * irs_nis_acc __P((const char *));
extern struct irs_acc * irs_irp_acc __P((const char *));
extern void irs_destroy __P((void));
/*
* These forward declarations are for the semi-private functions in
* the get*.c files. Each of these funcs implements the real get*
* functionality and the standard versions are just wrappers that
* call these. Apart from the wrappers, only irpd is expected to
* call these directly, hence these decls are put here and not in
* the /usr/include replacements.
*/
struct net_data; /* forward */
/*
* net_data_create gets a singleton net_data object. net_data_init
* creates as many net_data objects as times it is called. Clients using
* the default interface will use net_data_create by default. Servers will
* probably want net_data_init (one call per client)
*/
struct net_data *net_data_create __P((const char *));
struct net_data *net_data_init __P((const char *));
void net_data_destroy __P((void *));
extern struct group *getgrent_p __P((struct net_data *));
extern struct group *getgrnam_p __P((const char *, struct net_data *));
extern struct group *getgrgid_p __P((gid_t, struct net_data *));
extern int setgroupent_p __P((int, struct net_data *));
extern void endgrent_p __P((struct net_data *));
extern int getgrouplist_p __P((const char *, gid_t, gid_t *, int *,
struct net_data *));
#ifdef SETGRENT_VOID
extern void setgrent_p __P((struct net_data *));
#else
extern int setgrent_p __P((struct net_data *));
#endif
extern struct hostent *gethostbyname_p __P((const char *,
struct net_data *));
extern struct hostent *gethostbyname2_p __P((const char *, int,
struct net_data *));
extern struct hostent *gethostbyaddr_p __P((const char *, int, int,
struct net_data *));
extern struct hostent *gethostent_p __P((struct net_data *));
extern void sethostent_p __P((int, struct net_data *));
extern void endhostent_p __P((struct net_data *));
extern struct hostent *getipnodebyname_p __P((const char *, int, int, int *,
struct net_data *));
extern struct hostent *getipnodebyaddr_p __P((const void *, size_t,
int, int *, struct net_data *));
extern struct netent *getnetent_p __P((struct net_data *));
extern struct netent *getnetbyname_p __P((const char *, struct net_data *));
extern struct netent *getnetbyaddr_p __P((unsigned long, int,
struct net_data *));
extern void setnetent_p __P((int, struct net_data *));
extern void endnetent_p __P((struct net_data *));
extern void setnetgrent_p __P((const char *, struct net_data *));
extern void endnetgrent_p __P((struct net_data *));
extern int innetgr_p __P((const char *, const char *, const char *,
const char *, struct net_data *));
extern int getnetgrent_p __P((const char **, const char **,
const char **, struct net_data *));
extern struct protoent *getprotoent_p __P((struct net_data *));
extern struct protoent *getprotobyname_p __P((const char *,
struct net_data *));
extern struct protoent *getprotobynumber_p __P((int, struct net_data *));
extern void setprotoent_p __P((int, struct net_data *));
extern void endprotoent_p __P((struct net_data *));
extern struct passwd *getpwent_p __P((struct net_data *));
extern struct passwd *getpwnam_p __P((const char *, struct net_data *));
extern struct passwd *getpwuid_p __P((uid_t, struct net_data *));
extern int setpassent_p __P((int, struct net_data *));
extern void endpwent_p __P((struct net_data *));
#ifdef SETPWENT_VOID
extern void setpwent_p __P((struct net_data *));
#else
extern int setpwent_p __P((struct net_data *));
#endif
extern struct servent *getservent_p __P((struct net_data *));
extern struct servent *getservbyname_p __P((const char *, const char *,
struct net_data *));
extern struct servent *getservbyport_p __P((int, const char *,
struct net_data *));
extern void setservent_p __P((int, struct net_data *));
extern void endservent_p __P((struct net_data *));
#endif /*_IRS_H_INCLUDED*/

View File

@ -1,122 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1997-1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#ifndef ASSERTIONS_H
#define ASSERTIONS_H 1
typedef enum {
assert_require, assert_ensure, assert_insist, assert_invariant
} assertion_type;
typedef void (*assertion_failure_callback)(const char *, int, assertion_type,
const char *, int);
extern assertion_failure_callback __assertion_failed;
void set_assertion_failure_callback(assertion_failure_callback f);
const char *assertion_type_to_text(assertion_type type);
#ifdef CHECK_ALL
#define CHECK_REQUIRE 1
#define CHECK_ENSURE 1
#define CHECK_INSIST 1
#define CHECK_INVARIANT 1
#endif
#ifdef CHECK_NONE
#define CHECK_REQUIRE 0
#define CHECK_ENSURE 0
#define CHECK_INSIST 0
#define CHECK_INVARIANT 0
#endif
#ifndef CHECK_REQUIRE
#define CHECK_REQUIRE 1
#endif
#ifndef CHECK_ENSURE
#define CHECK_ENSURE 1
#endif
#ifndef CHECK_INSIST
#define CHECK_INSIST 1
#endif
#ifndef CHECK_INVARIANT
#define CHECK_INVARIANT 1
#endif
#if CHECK_REQUIRE != 0
#define REQUIRE(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_require, \
#cond, 0), 0)))
#define REQUIRE_ERR(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_require, \
#cond, 1), 0)))
#else
#define REQUIRE(cond) ((void) (cond))
#define REQUIRE_ERR(cond) ((void) (cond))
#endif /* CHECK_REQUIRE */
#if CHECK_ENSURE != 0
#define ENSURE(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
#cond, 0), 0)))
#define ENSURE_ERR(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_ensure, \
#cond, 1), 0)))
#else
#define ENSURE(cond) ((void) (cond))
#define ENSURE_ERR(cond) ((void) (cond))
#endif /* CHECK_ENSURE */
#if CHECK_INSIST != 0
#define INSIST(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
#cond, 0), 0)))
#define INSIST_ERR(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_insist, \
#cond, 1), 0)))
#else
#define INSIST(cond) ((void) (cond))
#define INSIST_ERR(cond) ((void) (cond))
#endif /* CHECK_INSIST */
#if CHECK_INVARIANT != 0
#define INVARIANT(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
#cond, 0), 0)))
#define INVARIANT_ERR(cond) \
((void) ((cond) || \
((__assertion_failed)(__FILE__, __LINE__, assert_invariant, \
#cond, 1), 0)))
#else
#define INVARIANT(cond) ((void) (cond))
#define INVARIANT_ERR(cond) ((void) (cond))
#endif /* CHECK_INVARIANT */
#endif /* ASSERTIONS_H */

View File

@ -1,109 +0,0 @@
#ifndef ISC_CTL_H
#define ISC_CTL_H
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1998,1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <isc/eventlib.h>
/* Macros. */
#define CTL_MORE 0x0001 /* More will be / should be sent. */
#define CTL_EXIT 0x0002 /* Close connection after this. */
#define CTL_DATA 0x0004 /* Go into / this is DATA mode. */
/* Types. */
struct ctl_cctx;
struct ctl_sctx;
struct ctl_sess;
struct ctl_verb;
enum ctl_severity { ctl_debug, ctl_warning, ctl_error };
typedef void (*ctl_logfunc)(enum ctl_severity, const char *, ...);
typedef void (*ctl_verbfunc)(struct ctl_sctx *, struct ctl_sess *,
const struct ctl_verb *, const char *,
u_int, const void *, void *);
typedef void (*ctl_srvrdone)(struct ctl_sctx *, struct ctl_sess *, void *);
typedef void (*ctl_clntdone)(struct ctl_cctx *, void *, const char *, u_int);
struct ctl_verb {
const char * name;
ctl_verbfunc func;
const char * help;
};
/* General symbols. */
#define ctl_logger __ctl_logger
#ifdef __GNUC__
void ctl_logger(enum ctl_severity, const char *, ...)
__attribute__((__format__(__printf__, 2, 3)));
#else
void ctl_logger(enum ctl_severity, const char *, ...);
#endif
/* Client symbols. */
#define ctl_client __ctl_client
#define ctl_endclient __ctl_endclient
#define ctl_command __ctl_command
struct ctl_cctx * ctl_client(evContext, const struct sockaddr *, size_t,
const struct sockaddr *, size_t,
ctl_clntdone, void *,
u_int, ctl_logfunc);
void ctl_endclient(struct ctl_cctx *);
int ctl_command(struct ctl_cctx *, const char *, size_t,
ctl_clntdone, void *);
/* Server symbols. */
#define ctl_server __ctl_server
#define ctl_endserver __ctl_endserver
#define ctl_response __ctl_response
#define ctl_sendhelp __ctl_sendhelp
#define ctl_getcsctx __ctl_getcsctx
#define ctl_setcsctx __ctl_setcsctx
struct ctl_sctx * ctl_server(evContext, const struct sockaddr *, size_t,
const struct ctl_verb *,
u_int, u_int,
u_int, int, int,
ctl_logfunc, void *);
void ctl_endserver(struct ctl_sctx *);
void ctl_response(struct ctl_sess *, u_int,
const char *, u_int, const void *,
ctl_srvrdone, void *,
const char *, size_t);
void ctl_sendhelp(struct ctl_sess *, u_int);
void * ctl_getcsctx(struct ctl_sess *);
void * ctl_setcsctx(struct ctl_sess *, void *);
#endif /*ISC_CTL_H*/

View File

@ -1,180 +0,0 @@
#ifndef DST_H
#define DST_H
#ifndef HAS_DST_KEY
typedef struct dst_key {
char *dk_key_name; /* name of the key */
int dk_key_size; /* this is the size of the key in bits */
int dk_proto; /* what protocols this key can be used for */
int dk_alg; /* algorithm number from key record */
u_int32_t dk_flags; /* and the flags of the public key */
u_int16_t dk_id; /* identifier of the key */
} DST_KEY;
#endif /* HAS_DST_KEY */
/*
* do not taint namespace
*/
#define dst_bsafe_init __dst_bsafe_init
#define dst_buffer_to_key __dst_buffer_to_key
#define dst_check_algorithm __dst_check_algorithm
#define dst_compare_keys __dst_compare_keys
#define dst_cylink_init __dst_cylink_init
#define dst_dnskey_to_key __dst_dnskey_to_key
#define dst_eay_dss_init __dst_eay_dss_init
#define dst_free_key __dst_free_key
#define dst_generate_key __dst_generate_key
#define dst_hmac_md5_init __dst_hmac_md5_init
#define dst_init __dst_init
#define dst_key_to_buffer __dst_key_to_buffer
#define dst_key_to_dnskey __dst_key_to_dnskey
#define dst_read_key __dst_read_key
#define dst_rsaref_init __dst_rsaref_init
#define dst_s_build_filename __dst_s_build_filename
#define dst_s_calculate_bits __dst_s_calculate_bits
#define dst_s_conv_bignum_b64_to_u8 __dst_s_conv_bignum_b64_to_u8
#define dst_s_conv_bignum_u8_to_b64 __dst_s_conv_bignum_u8_to_b64
#define dst_s_dns_key_id __dst_s_dns_key_id
#define dst_s_dump __dst_s_dump
#define dst_s_filename_length __dst_s_filename_length
#define dst_s_fopen __dst_s_fopen
#define dst_s_get_int16 __dst_s_get_int16
#define dst_s_get_int32 __dst_s_get_int32
#define dst_s_id_calc __dst_s_id_calc
#define dst_s_put_int16 __dst_s_put_int16
#define dst_s_put_int32 __dst_s_put_int32
#define dst_s_quick_random __dst_s_quick_random
#define dst_s_quick_random_set __dst_s_quick_random_set
#define dst_s_random __dst_s_random
#define dst_s_semi_random __dst_s_semi_random
#define dst_s_verify_str __dst_s_verify_str
#define dst_sig_size __dst_sig_size
#define dst_sign_data __dst_sign_data
#define dst_verify_data __dst_verify_data
#define dst_write_key __dst_write_key
/*
* DST Crypto API defintions
*/
void dst_init(void);
int dst_check_algorithm(const int);
int dst_sign_data(const int, /* specifies INIT/UPDATE/FINAL/ALL */
DST_KEY *, /* the key to use */
void **, /* pointer to state structure */
const u_char *, /* data to be signed */
const int, /* length of input data */
u_char *, /* buffer to write signature to */
const int); /* size of output buffer */
int dst_verify_data(const int, /* specifies INIT/UPDATE/FINAL/ALL */
DST_KEY *, /* the key to use */
void **, /* pointer to state structure */
const u_char *, /* data to be verified */
const int, /* length of input data */
const u_char *, /* buffer containing signature */
const int); /* length of signature */
DST_KEY *dst_read_key(const char *, /* name of key */
const u_int16_t, /* key tag identifier */
const int, /* key algorithm */
const int); /* Private/PublicKey wanted*/
int dst_write_key(const DST_KEY *, /* key to write out */
const int); /* Public/Private */
DST_KEY *dst_dnskey_to_key(const char *, /* KEY record name */
const u_char *, /* KEY RDATA */
const int); /* size of input buffer*/
int dst_key_to_dnskey(const DST_KEY *, /* key to translate */
u_char *, /* output buffer */
const int); /* size of out_storage*/
DST_KEY *dst_buffer_to_key(const char *, /* name of the key */
const int, /* algorithm */
const int, /* dns flags */
const int, /* dns protocol */
const u_char *, /* key in dns wire fmt */
const int); /* size of key */
int dst_key_to_buffer(DST_KEY *, u_char *, int);
DST_KEY *dst_generate_key(const char *, /* name of new key */
const int, /* key algorithm to generate */
const int, /* size of new key */
const int, /* alg dependent parameter*/
const int, /* key DNS flags */
const int); /* key DNS protocol */
DST_KEY *dst_free_key(DST_KEY *);
int dst_compare_keys(const DST_KEY *, const DST_KEY *);
int dst_sig_size(DST_KEY *);
/* support for dns key tags/ids */
u_int16_t dst_s_dns_key_id(const u_char *, const int);
u_int16_t dst_s_id_calc(const u_char *, const int);
/* Used by callers as well as by the library. */
#define RAW_KEY_SIZE 8192 /* large enough to store any key */
/* DST_API control flags */
/* These are used used in functions dst_sign_data and dst_verify_data */
#define SIG_MODE_INIT 1 /* initialize digest */
#define SIG_MODE_UPDATE 2 /* add data to digest */
#define SIG_MODE_FINAL 4 /* generate/verify signature */
#define SIG_MODE_ALL (SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
/* Flags for dst_read_private_key() */
#define DST_FORCE_READ 0x1000000
#define DST_CAN_SIGN 0x010F
#define DST_NO_AUTHEN 0x8000
#define DST_EXTEND_FLAG 0x1000
#define DST_STANDARD 0
#define DST_PRIVATE 0x2000000
#define DST_PUBLIC 0x4000000
#define DST_RAND_SEMI 1
#define DST_RAND_STD 2
#define DST_RAND_KEY 3
#define DST_RAND_DSS 4
/* DST algorithm codes */
#define KEY_RSA 1
#define KEY_DH 2
#define KEY_DSA 3
#define KEY_PRIVATE 254
#define KEY_EXPAND 255
#define KEY_HMAC_MD5 157
#define KEY_HMAC_SHA1 158
#define UNKNOWN_KEYALG 0
#define DST_MAX_ALGS KEY_HMAC_SHA1
/* DST constants to locations in KEY record changes in new KEY record */
#define DST_FLAGS_SIZE 2
#define DST_KEY_PROT 2
#define DST_KEY_ALG 3
#define DST_EXT_FLAG 4
#define DST_KEY_START 4
#ifndef SIGN_F_NOKEY
#define SIGN_F_NOKEY 0xC000
#endif
/* error codes from dst routines */
#define SIGN_INIT_FAILURE (-23)
#define SIGN_UPDATE_FAILURE (-24)
#define SIGN_FINAL_FAILURE (-25)
#define VERIFY_INIT_FAILURE (-26)
#define VERIFY_UPDATE_FAILURE (-27)
#define VERIFY_FINAL_FAILURE (-28)
#define MISSING_KEY_OR_SIGNATURE (-30)
#define UNSUPPORTED_KEYALG (-31)
#endif /* DST_H */

View File

@ -1,200 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/* eventlib.h - exported interfaces for eventlib
* vix 09sep95 [initial]
*
* $Id$
*/
#ifndef _EVENTLIB_H
#define _EVENTLIB_H
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <stdio.h>
#ifndef __P
# define __EVENTLIB_P_DEFINED
# ifdef __STDC__
# define __P(x) x
# else
# define __P(x) ()
# endif
#endif
/* In the absence of branded types... */
typedef struct { void *opaque; } evConnID;
typedef struct { void *opaque; } evFileID;
typedef struct { void *opaque; } evStreamID;
typedef struct { void *opaque; } evTimerID;
typedef struct { void *opaque; } evWaitID;
typedef struct { void *opaque; } evContext;
typedef struct { void *opaque; } evEvent;
#define evInitID(id) ((id)->opaque = NULL)
#define evTestID(id) ((id).opaque != NULL)
typedef void (*evConnFunc)__P((evContext, void *, int, const void *, int,
const void *, int));
typedef void (*evFileFunc)__P((evContext, void *, int, int));
typedef void (*evStreamFunc)__P((evContext, void *, int, int));
typedef void (*evTimerFunc)__P((evContext, void *,
struct timespec, struct timespec));
typedef void (*evWaitFunc)__P((evContext, void *, const void *));
typedef struct { unsigned char mask[256/8]; } evByteMask;
#define EV_BYTEMASK_BYTE(b) ((b) / 8)
#define EV_BYTEMASK_MASK(b) (1 << ((b) % 8))
#define EV_BYTEMASK_SET(bm, b) \
((bm).mask[EV_BYTEMASK_BYTE(b)] |= EV_BYTEMASK_MASK(b))
#define EV_BYTEMASK_CLR(bm, b) \
((bm).mask[EV_BYTEMASK_BYTE(b)] &= ~EV_BYTEMASK_MASK(b))
#define EV_BYTEMASK_TST(bm, b) \
((bm).mask[EV_BYTEMASK_BYTE(b)] & EV_BYTEMASK_MASK(b))
#define EV_POLL 1
#define EV_WAIT 2
#define EV_NULL 4
#define EV_READ 1
#define EV_WRITE 2
#define EV_EXCEPT 4
/* eventlib.c */
#define evCreate __evCreate
#define evSetDebug __evSetDebug
#define evDestroy __evDestroy
#define evGetNext __evGetNext
#define evDispatch __evDispatch
#define evDrop __evDrop
#define evMainLoop __evMainLoop
#define evHighestFD __evHighestFD
#define evGetOption __evGetOption
#define evSetOption __evSetOption
int evCreate __P((evContext *));
void evSetDebug __P((evContext, int, FILE *));
int evDestroy __P((evContext));
int evGetNext __P((evContext, evEvent *, int));
int evDispatch __P((evContext, evEvent));
void evDrop __P((evContext, evEvent));
int evMainLoop __P((evContext));
int evHighestFD __P((evContext));
int evGetOption __P((evContext *, const char *, int *));
int evSetOption __P((evContext *, const char *, int));
/* ev_connects.c */
#define evListen __evListen
#define evConnect __evConnect
#define evCancelConn __evCancelConn
#define evHold __evHold
#define evUnhold __evUnhold
#define evTryAccept __evTryAccept
int evListen __P((evContext, int, int, evConnFunc, void *, evConnID *));
int evConnect __P((evContext, int, const void *, int,
evConnFunc, void *, evConnID *));
int evCancelConn __P((evContext, evConnID));
int evHold __P((evContext, evConnID));
int evUnhold __P((evContext, evConnID));
int evTryAccept __P((evContext, evConnID, int *));
/* ev_files.c */
#define evSelectFD __evSelectFD
#define evDeselectFD __evDeselectFD
int evSelectFD __P((evContext, int, int, evFileFunc, void *, evFileID *));
int evDeselectFD __P((evContext, evFileID));
/* ev_streams.c */
#define evConsIovec __evConsIovec
#define evWrite __evWrite
#define evRead __evRead
#define evTimeRW __evTimeRW
#define evUntimeRW __evUntimeRW
#define evCancelRW __evCancelRW
struct iovec evConsIovec __P((void *, size_t));
int evWrite __P((evContext, int, const struct iovec *, int,
evStreamFunc func, void *, evStreamID *));
int evRead __P((evContext, int, const struct iovec *, int,
evStreamFunc func, void *, evStreamID *));
int evTimeRW __P((evContext, evStreamID, evTimerID timer));
int evUntimeRW __P((evContext, evStreamID));
int evCancelRW __P((evContext, evStreamID));
/* ev_timers.c */
#define evConsTime __evConsTime
#define evAddTime __evAddTime
#define evSubTime __evSubTime
#define evCmpTime __evCmpTime
#define evTimeSpec __evTimeSpec
#define evTimeVal __evTimeVal
#define evNowTime __evNowTime
#define evUTCTime __evUTCTime
#define evLastEventTime __evLastEventTime
#define evSetTimer __evSetTimer
#define evClearTimer __evClearTimer
#define evConfigTimer __evConfigTimer
#define evResetTimer __evResetTimer
#define evSetIdleTimer __evSetIdleTimer
#define evClearIdleTimer __evClearIdleTimer
#define evResetIdleTimer __evResetIdleTimer
#define evTouchIdleTimer __evTouchIdleTimer
struct timespec evConsTime __P((time_t sec, long nsec));
struct timespec evAddTime __P((struct timespec, struct timespec));
struct timespec evSubTime __P((struct timespec, struct timespec));
struct timespec evNowTime __P((void));
struct timespec evUTCTime __P((void));
struct timespec evLastEventTime __P((evContext));
struct timespec evTimeSpec __P((struct timeval));
struct timeval evTimeVal __P((struct timespec));
int evCmpTime __P((struct timespec, struct timespec));
int evSetTimer __P((evContext, evTimerFunc, void *, struct timespec,
struct timespec, evTimerID *));
int evClearTimer __P((evContext, evTimerID));
int evConfigTimer __P((evContext, evTimerID, const char *param,
int value));
int evResetTimer __P((evContext, evTimerID, evTimerFunc, void *,
struct timespec, struct timespec));
int evSetIdleTimer __P((evContext, evTimerFunc, void *, struct timespec,
evTimerID *));
int evClearIdleTimer __P((evContext, evTimerID));
int evResetIdleTimer __P((evContext, evTimerID, evTimerFunc, void *,
struct timespec));
int evTouchIdleTimer __P((evContext, evTimerID));
/* ev_waits.c */
#define evWaitFor __evWaitFor
#define evDo __evDo
#define evUnwait __evUnwait
#define evDefer __evDefer
int evWaitFor __P((evContext, const void *, evWaitFunc, void *, evWaitID *));
int evDo __P((evContext, const void *));
int evUnwait __P((evContext, evWaitID));
int evDefer __P((evContext, evWaitFunc, void *));
#ifdef __EVENTLIB_P_DEFINED
# undef __P
#endif
#endif /*_EVENTLIB_H*/

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1997,1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
typedef int (*heap_higher_priority_func)(void *, void *);
typedef void (*heap_index_func)(void *, int);
typedef void (*heap_for_each_func)(void *, void *);
typedef struct heap_context {
int array_size;
int array_size_increment;
int heap_size;
void **heap;
heap_higher_priority_func higher_priority;
heap_index_func index;
} *heap_context;
#define heap_new __heap_new
#define heap_free __heap_free
#define heap_insert __heap_insert
#define heap_delete __heap_delete
#define heap_increased __heap_increased
#define heap_decreased __heap_decreased
#define heap_element __heap_element
#define heap_for_each __heap_for_each
heap_context heap_new(heap_higher_priority_func, heap_index_func, int);
int heap_free(heap_context);
int heap_insert(heap_context, void *);
int heap_delete(heap_context, int);
int heap_increased(heap_context, int);
int heap_decreased(heap_context, int);
void * heap_element(heap_context, int);
int heap_for_each(heap_context, heap_for_each_func, void *);

View File

@ -1,115 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#ifndef _IRPMARSHALL_H_INCLUDED
#define _IRPMARSHALL_H_INCLUDED
/* Hide function names */
#define irp_marshall_gr __irp_marshall_gr
#define irp_marshall_ho __irp_marshall_ho
#define irp_marshall_ne __irp_marshall_ne
#define irp_marshall_ng __irp_marshall_ng
#define irp_marshall_nw __irp_marshall_nw
#define irp_marshall_pr __irp_marshall_pr
#define irp_marshall_pw __irp_marshall_pw
#define irp_marshall_sv __irp_marshall_sv
#define irp_unmarshall_gr __irp_unmarshall_gr
#define irp_unmarshall_ho __irp_unmarshall_ho
#define irp_unmarshall_ne __irp_unmarshall_ne
#define irp_unmarshall_ng __irp_unmarshall_ng
#define irp_unmarshall_nw __irp_unmarshall_nw
#define irp_unmarshall_pr __irp_unmarshall_pr
#define irp_unmarshall_pw __irp_unmarshall_pw
#define irp_unmarshall_sv __irp_unmarshall_sv
#define MAXPADDRSIZE (sizeof "255.255.255.255" + 1)
#define ADDR_T_STR(x) (x == AF_INET ? "AF_INET" :\
(x == AF_INET6 ? "AF_INET6" : "UNKNOWN"))
/* See comment below on usage */
int irp_marshall_pw(const struct passwd *, char **, size_t *);
int irp_unmarshall_pw(struct passwd *, char *);
int irp_marshall_gr(const struct group *, char **, size_t *);
int irp_unmarshall_gr(struct group *, char *);
int irp_marshall_sv(const struct servent *, char **, size_t *);
int irp_unmarshall_sv(struct servent *, char *);
int irp_marshall_pr(struct protoent *, char **, size_t *);
int irp_unmarshall_pr(struct protoent *, char *);
int irp_marshall_ho(struct hostent *, char **, size_t *);
int irp_unmarshall_ho(struct hostent *, char *);
int irp_marshall_ng(const char *, const char *, const char *,
char **, size_t *);
int irp_unmarshall_ng(const char **, const char **, const char **, char *);
int irp_marshall_nw(struct nwent *, char **, size_t *);
int irp_unmarshall_nw(struct nwent *, char *);
int irp_marshall_ne(struct netent *, char **, size_t *);
int irp_unmarshall_ne(struct netent *, char *);
/*
* Functions to marshall and unmarshall various system data structures. We
* use a printable ascii format that is as close to various system config
* files as reasonable (e.g. /etc/passwd format).
*
* We are not forgiving with unmarhsalling misformatted buffers. In
* particular whitespace in fields is not ignored. So a formatted password
* entry "brister :1364:100:...." will yield a username of "brister "
*
* We potentially do a lot of mallocs to fill fields that are of type
* (char **) like a hostent h_addr field. Building (for example) the
* h_addr field and its associated addresses all in one buffer is
* certainly possible, but not done here.
*
* The following description is true for all the marshalling functions:
*
*/
/* int irp_marshall_XX(struct yyyy *XX, char **buffer, size_t *len);
*
* The argument XX (of type struct passwd for example) is marshalled in the
* buffer pointed at by *BUFFER, which is of length *LEN. Returns 0
* on success and -1 on failure. Failure will occur if *LEN is
* smaller than needed.
*
* If BUFFER is NULL, then *LEN is set to the size of the buffer
* needed to marshall the data and no marshalling is actually done.
*
* If *BUFFER is NULL, then a buffer large enough will be allocated
* with memget() and the size allocated will be stored in *LEN. An extra 2
* bytes will be allocated for the client to append CRLF if wanted. The
* value of *LEN will include these two bytes.
*
* All the marshalling functions produce a buffer with the fields
* separated by colons (except for the hostent marshalling, which uses '@'
* to separate fields). Fields that have multiple subfields (like the
* gr_mem field in struct group) have their subparts separated by
* commas.
*/
/*
* int irp_unmarshall_XX(struct YYYYY *XX, char *buffer);
*
* The unmashalling functions break apart the buffer and store the
* values in the struct pointed to by XX. All pointer values inside
* XX are allocated with malloc. All arrays of pointers have a NULL
* as the last element.
*/
#endif

View File

@ -1,112 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1997,1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 LIST_H
#define LIST_H 1
#include <isc/assertions.h>
#define LIST(type) struct { type *head, *tail; }
#define INIT_LIST(list) \
do { (list).head = NULL; (list).tail = NULL; } while (0)
#define LINK(type) struct { type *prev, *next; }
#define INIT_LINK_TYPE(elt, link, type) \
do { \
(elt)->link.prev = (type *)(-1); \
(elt)->link.next = (type *)(-1); \
} while (0)
#define INIT_LINK(elt, link) \
INIT_LINK_TYPE(elt, link, void)
#define LINKED(elt, link) ((void *)((elt)->link.prev) != (void *)(-1))
#define HEAD(list) ((list).head)
#define TAIL(list) ((list).tail)
#define EMPTY(list) ((list).head == NULL)
#define PREPEND(list, elt, link) \
do { \
INSIST(!LINKED(elt, link));\
if ((list).head != NULL) \
(list).head->link.prev = (elt); \
else \
(list).tail = (elt); \
(elt)->link.prev = NULL; \
(elt)->link.next = (list).head; \
(list).head = (elt); \
} while (0)
#define APPEND(list, elt, link) \
do { \
INSIST(!LINKED(elt, link));\
if ((list).tail != NULL) \
(list).tail->link.next = (elt); \
else \
(list).head = (elt); \
(elt)->link.prev = (list).tail; \
(elt)->link.next = NULL; \
(list).tail = (elt); \
} while (0)
#define UNLINK_TYPE(list, elt, link, type) \
do { \
INSIST(LINKED(elt, link));\
if ((elt)->link.next != NULL) \
(elt)->link.next->link.prev = (elt)->link.prev; \
else \
(list).tail = (elt)->link.prev; \
if ((elt)->link.prev != NULL) \
(elt)->link.prev->link.next = (elt)->link.next; \
else \
(list).head = (elt)->link.next; \
INIT_LINK_TYPE(elt, link, type); \
} while (0)
#define UNLINK(list, elt, link) \
UNLINK_TYPE(list, elt, link, void)
#define PREV(elt, link) ((elt)->link.prev)
#define NEXT(elt, link) ((elt)->link.next)
#define INSERT_BEFORE(list, before, elt, link) \
do { \
INSIST(!LINKED(elt, link));\
if ((before)->link.prev == NULL) \
PREPEND(list, elt, link); \
else { \
(elt)->link.prev = (before)->link.prev; \
(before)->link.prev = (elt); \
(elt)->link.prev->link.next = (elt); \
(elt)->link.next = (before); \
} \
} while (0)
#define INSERT_AFTER(list, after, elt, link) \
do { \
INSIST(!LINKED(elt, link));\
if ((after)->link.next == NULL) \
APPEND(list, elt, link); \
else { \
(elt)->link.next = (after)->link.next; \
(after)->link.next = (elt); \
(elt)->link.next->link.prev = (elt); \
(elt)->link.prev = (after); \
} \
} while (0)
#define ENQUEUE(list, elt, link) APPEND(list, elt, link)
#define DEQUEUE(list, elt, link) UNLINK(list, elt, link)
#endif /* LIST_H */

View File

@ -1,112 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1996-1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 LOGGING_H
#define LOGGING_H
#include <sys/types.h>
#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>
#define log_critical (-5)
#define log_error (-4)
#define log_warning (-3)
#define log_notice (-2)
#define log_info (-1)
#define log_debug(level) (level)
typedef enum { log_syslog, log_file, log_null } log_channel_type;
#define LOG_MAX_VERSIONS 99
#define LOG_CLOSE_STREAM 0x0001
#define LOG_TIMESTAMP 0x0002
#define LOG_TRUNCATE 0x0004
#define LOG_USE_CONTEXT_LEVEL 0x0008
#define LOG_PRINT_LEVEL 0x0010
#define LOG_REQUIRE_DEBUG 0x0020
#define LOG_CHANNEL_BROKEN 0x0040
#define LOG_PRINT_CATEGORY 0x0080
#define LOG_CHANNEL_OFF 0x0100
typedef struct log_context *log_context;
typedef struct log_channel *log_channel;
#define LOG_OPTION_DEBUG 0x01
#define LOG_OPTION_LEVEL 0x02
#define log_open_stream __log_open_stream
#define log_close_stream __log_close_stream
#define log_get_stream __log_get_stream
#define log_get_filename __log_get_filename
#define log_check_channel __log_check_channel
#define log_check __log_check
#define log_vwrite __log_vwrite
#define log_write __log_write
#define log_new_context __log_new_context
#define log_free_context __log_free_context
#define log_add_channel __log_add_channel
#define log_remove_channel __log_remove_channel
#define log_option __log_option
#define log_category_is_active __log_category_is_active
#define log_new_syslog_channel __log_new_syslog_channel
#define log_new_file_channel __log_new_file_channel
#define log_set_file_owner __log_set_file_owner
#define log_new_null_channel __log_new_null_channel
#define log_inc_references __log_inc_references
#define log_dec_references __log_dec_references
#define log_get_channel_type __log_get_channel_type
#define log_free_channel __log_free_channel
#define log_close_debug_channels __log_close_debug_channels
FILE * log_open_stream(log_channel);
int log_close_stream(log_channel);
FILE * log_get_stream(log_channel);
char * log_get_filename(log_channel);
int log_check_channel(log_context, int, log_channel);
int log_check(log_context, int, int);
#ifdef __GNUC__
void log_vwrite(log_context, int, int, const char *,
va_list args)
__attribute__((__format__(__printf__, 4, 0)));
void log_write(log_context, int, int, const char *, ...)
__attribute__((__format__(__printf__, 4, 5)));
#else
void log_vwrite(log_context, int, int, const char *,
va_list args);
void log_write(log_context, int, int, const char *, ...);
#endif
int log_new_context(int, char **, log_context *);
void log_free_context(log_context);
int log_add_channel(log_context, int, log_channel);
int log_remove_channel(log_context, int, log_channel);
int log_option(log_context, int, int);
int log_category_is_active(log_context, int);
log_channel log_new_syslog_channel(unsigned int, int, int);
log_channel log_new_file_channel(unsigned int, int, const char *,
FILE *, unsigned int,
unsigned long);
int log_set_file_owner(log_channel, uid_t, gid_t);
log_channel log_new_null_channel(void);
int log_inc_references(log_channel);
int log_dec_references(log_channel);
log_channel_type log_get_channel_type(log_channel);
int log_free_channel(log_channel);
void log_close_debug_channels(log_context);
#endif /* !LOGGING_H */

View File

@ -1,49 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1997,1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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 MEMCLUSTER_H
#define MEMCLUSTER_H
#include <stdio.h>
#define meminit __meminit
#ifdef MEMCLUSTER_DEBUG
#define memget(s) __memget_debug(s, __FILE__, __LINE__)
#define memput(p, s) __memput_debug(p, s, __FILE__, __LINE__)
#else /*MEMCLUSTER_DEBUG*/
#ifdef MEMCLUSTER_RECORD
#define memget(s) __memget_record(s, __FILE__, __LINE__)
#define memput(p, s) __memput_record(p, s, __FILE__, __LINE__)
#else /*MEMCLUSTER_RECORD*/
#define memget __memget
#define memput __memput
#endif /*MEMCLUSTER_RECORD*/
#endif /*MEMCLUSTER_DEBUG*/
#define memstats __memstats
#define memactive __memactive
int meminit(size_t, size_t);
void * __memget(size_t);
void __memput(void *, size_t);
void * __memget_debug(size_t, const char *, int);
void __memput_debug(void *, size_t, const char *, int);
void * __memget_record(size_t, const char *, int);
void __memput_record(void *, size_t, const char *, int);
void memstats(FILE *);
int memactive(void);
#endif /* MEMCLUSTER_H */

View File

@ -1,39 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1995-1999 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#ifndef _ISC_MISC_H
#define _ISC_MISC_H
#include <stdio.h>
#define bitncmp __bitncmp
/*#define isc_movefile __isc_movefile */
extern int bitncmp(const void *, const void *, int);
extern int isc_movefile(const char *, const char *);
extern int isc_gethexstring(unsigned char *, size_t, int, FILE *,
int *);
extern void isc_puthexstring(FILE *, const unsigned char *, size_t,
size_t, size_t, const char *);
extern void isc_tohex(const unsigned char *, size_t, char *);
#endif /*_ISC_MISC_H*/

View File

@ -1,58 +0,0 @@
/* tree.h - declare structures used by tree library
*
* vix 22jan93 [revisited; uses RCS, ANSI, POSIX; has bug fixes]
* vix 27jun86 [broken out of tree.c]
*
* $Id$
*/
#ifndef _TREE_H_INCLUDED
#define _TREE_H_INCLUDED
#ifndef __P
# if defined(__STDC__) || defined(__GNUC__)
# define __P(x) x
# else
# define __P(x) ()
# endif
#endif
/*
* tree_t is our package-specific anonymous pointer.
*/
#if defined(__STDC__) || defined(__GNUC__)
typedef void *tree_t;
#else
typedef char *tree_t;
#endif
/*
* Do not taint namespace
*/
#define tree_add __tree_add
#define tree_delete __tree_delete
#define tree_init __tree_init
#define tree_mung __tree_mung
#define tree_srch __tree_srch
#define tree_trav __tree_trav
typedef struct tree_s {
tree_t data;
struct tree_s *left, *right;
short bal;
}
tree;
void tree_init __P((tree **));
tree_t tree_srch __P((tree **, int (*)(), tree_t));
tree_t tree_add __P((tree **, int (*)(), tree_t, void (*)()));
int tree_delete __P((tree **, int (*)(), tree_t, void (*)()));
int tree_trav __P((tree **, int (*)()));
void tree_mung __P((tree **, void (*)()));
#endif /* _TREE_H_INCLUDED */

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999 by Internet Software Consortium, Inc.
*
* 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 ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC 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.
*/
/*
* $Id$
*/
#ifndef __RES_UPDATE_H
#define __RES_UPDATE_H
#include <sys/types.h>
#include <arpa/nameser.h>
#include <isc/list.h>
#include <resolv.h>
/*
* This RR-like structure is particular to UPDATE.
*/
struct ns_updrec {
LINK(struct ns_updrec) r_link, r_glink;
ns_sect r_section; /* ZONE/PREREQUISITE/UPDATE */
char * r_dname; /* owner of the RR */
ns_class r_class; /* class number */
ns_type r_type; /* type number */
u_int32_t r_ttl; /* time to live */
u_char * r_data; /* rdata fields as text string */
u_int r_size; /* size of r_data field */
int r_opcode; /* type of operation */
/* following fields for private use by the resolver/server routines */
struct databuf *r_dp; /* databuf to process */
struct databuf *r_deldp; /* databuf's deleted/overwritten */
u_int r_zone; /* zone number on server */
};
typedef struct ns_updrec ns_updrec;
typedef LIST(ns_updrec) ns_updque;
#define res_mkupdate __res_mkupdate
#define res_update __res_update
#define res_mkupdrec __res_mkupdrec
#define res_freeupdrec __res_freeupdrec
#define res_nmkupdate __res_nmkupdate
#define res_nupdate __res_nupdate
int res_mkupdate __P((ns_updrec *, u_char *, int));
int res_update __P((ns_updrec *));
ns_updrec * res_mkupdrec __P((int, const char *, u_int, u_int, u_long));
void res_freeupdrec __P((ns_updrec *));
int res_nmkupdate __P((res_state, ns_updrec *, u_char *, int));
int res_nupdate __P((res_state, ns_updrec *, ns_tsig_key *));
#endif /*__RES_UPDATE_H*/

View File

@ -1,8 +0,0 @@
#ifndef _SYS_UN_H
#define _SYS_UN_H
/* TODO: implement */
#endif /* _SYS_UN_H */

View File

@ -1,8 +0,0 @@
#ifndef UTMP_H
#define UTMP_H
/* TODO: implement */
#endif /* UTMP_H */

View File

@ -1,422 +0,0 @@
#ifndef port_after_h
#define port_after_h
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/param.h>
#if (!defined(BSD)) || (BSD < 199306)
#include <sys/bitypes.h>
#endif
// CHANGED: Haiku does not have these error codes
#define ETOOMANYREFS B_ERROR
// CHANGED: Haiku fd_set has 'bits' instead of 'fds_bits'
#define fds_bits bits
// CHANGED: Haiku does have pselect, turn on when not compiling for Haiku
#ifndef __HAIKU__
#define NEED_PSELECT
#endif
// CHANGED: we don't want the daemon
#undef NEED_DAEMON
// CHANGED
#define HAVE_SOCKADDR_STORAGE 1
#define HAVE_SA_LEN 1
#undef HAVE_MINIMUM_IFREQ
#define NEED_STRSEP 1
#undef NEED_STRERROR
#undef HAS_INET6_STRUCTS
#define HAVE_SIN6_SCOPE_ID 1
#undef NEED_IN6ADDR_ANY
#undef NEED_GETTIMEOFDAY
#undef HAVE_STRNDUP
#undef USE_FIONBIO_IOCTL
#undef USE_SYSERROR_LIST
#undef INNETGR_ARGS
#undef SETNETGRENT_ARGS
#undef USE_IFNAMELINKID
/* XXX sunos and cygwin needs O_NDELAY */
#define PORT_NONBLOCK O_NONBLOCK
/*
* We need to know the IPv6 address family number even on IPv4-only systems.
* Note that this is NOT a protocol constant, and that if the system has its
* own AF_INET6, different from ours below, all of BIND's libraries and
* executables will need to be recompiled after the system <sys/socket.h>
* has had this type added. The type number below is correct on most BSD-
* derived systems for which AF_INET6 is defined.
*/
#ifndef AF_INET6
#define AF_INET6 24
#endif
#ifndef PF_INET6
#define PF_INET6 AF_INET6
#endif
#ifdef HAS_IN_ADDR6
/* Map to pre-RFC structure. */
#define in6_addr in_addr6
#endif
#ifndef HAS_INET6_STRUCTS
/* Replace with structure from later rev of O/S if known. */
struct in6_addr {
u_int8_t s6_addr[16];
};
#define IN6ADDR_ANY_INIT \
{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
#define IN6ADDR_LOOPBACK_INIT \
{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
/* Replace with structure from later rev of O/S if known. */
struct sockaddr_in6 {
#ifdef HAVE_SA_LEN
u_int8_t sin6_len; /* length of this struct */
u_int8_t sin6_family; /* AF_INET6 */
#else
u_int16_t sin6_family; /* AF_INET6 */
#endif
u_int16_t sin6_port; /* transport layer port # */
u_int32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
u_int32_t sin6_scope_id; /* set of interfaces for a scope */
};
#endif /* HAS_INET6_STRUCTS */
#ifdef BROKEN_IN6ADDR_INIT_MACROS
#undef IN6ADDR_ANY_INIT
#undef IN6ADDR_LOOPBACK_INIT
#endif
#ifdef _AIX
#ifndef IN6ADDR_ANY_INIT
#define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0 }}}
#endif
#ifndef IN6ADDR_LOOPBACK_INIT
#if BYTE_ORDER == BIG_ENDIAN
#define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 1 }}}
#else
#define IN6ADDR_LOOPBACK_INIT {{{0, 0, 0, 0x01000000}}}
#endif
#endif
#endif
#ifndef IN6ADDR_ANY_INIT
#ifdef s6_addr
#define IN6ADDR_ANY_INIT \
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}}
#else
#define IN6ADDR_ANY_INIT \
{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }}
#endif
#endif
#ifndef IN6ADDR_LOOPBACK_INIT
#ifdef s6_addr
#define IN6ADDR_LOOPBACK_INIT \
{{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}}
#else
#define IN6ADDR_LOOPBACK_INIT \
{{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }}
#endif
#endif
#ifndef HAVE_SOCKADDR_STORAGE
#define __SS_MAXSIZE 128
#define __SS_ALLIGSIZE (sizeof (long))
struct sockaddr_storage {
#ifdef HAVE_SA_LEN
u_int8_t ss_len; /* address length */
u_int8_t ss_family; /* address family */
char __ss_pad1[__SS_ALLIGSIZE - 2 * sizeof(u_int8_t)];
long __ss_align;
char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
#else
u_int16_t ss_family; /* address family */
char __ss_pad1[__SS_ALLIGSIZE - sizeof(u_int16_t)];
long __ss_align;
char __ss_pad2[__SS_MAXSIZE - 2 * __SS_ALLIGSIZE];
#endif
};
#endif
#if !defined(HAS_INET6_STRUCTS) || defined(NEED_IN6ADDR_ANY)
#define in6addr_any isc_in6addr_any
extern const struct in6_addr in6addr_any;
#endif
/*
* IN6_ARE_ADDR_EQUAL, IN6_IS_ADDR_UNSPECIFIED, IN6_IS_ADDR_V4COMPAT and
* IN6_IS_ADDR_V4MAPPED are broken in glibc 2.1.
*/
#ifdef __GLIBC__
#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 2)
#undef IN6_ARE_ADDR_EQUAL
#undef IN6_IS_ADDR_UNSPECIFIED
#undef IN6_IS_ADDR_V4COMPAT
#undef IN6_IS_ADDR_V4MAPPED
#endif
#endif
#ifndef IN6_ARE_ADDR_EQUAL
#define IN6_ARE_ADDR_EQUAL(a,b) \
(memcmp(&(a)->s6_addr[0], &(b)->s6_addr[0], sizeof(struct in6_addr)) == 0)
#endif
#ifndef IN6_IS_ADDR_UNSPECIFIED
#define IN6_IS_ADDR_UNSPECIFIED(a) \
IN6_ARE_ADDR_EQUAL(a, &in6addr_any)
#endif
#ifndef IN6_IS_ADDR_LOOPBACK
extern const struct in6_addr isc_in6addr_loopback;
#define IN6_IS_ADDR_LOOPBACK(a) \
IN6_ARE_ADDR_EQUAL(a, &isc_in6addr_loopback)
#endif
#ifndef IN6_IS_ADDR_V4MAPPED
#define IN6_IS_ADDR_V4MAPPED(a) \
((a)->s6_addr[0] == 0x00 && (a)->s6_addr[1] == 0x00 && \
(a)->s6_addr[2] == 0x00 && (a)->s6_addr[3] == 0x00 && \
(a)->s6_addr[4] == 0x00 && (a)->s6_addr[5] == 0x00 && \
(a)->s6_addr[6] == 0x00 && (a)->s6_addr[9] == 0x00 && \
(a)->s6_addr[8] == 0x00 && (a)->s6_addr[9] == 0x00 && \
(a)->s6_addr[10] == 0xff && (a)->s6_addr[11] == 0xff)
#endif
#ifndef IN6_IS_ADDR_SITELOCAL
#define IN6_IS_ADDR_SITELOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0))
#endif
#ifndef IN6_IS_ADDR_LINKLOCAL
#define IN6_IS_ADDR_LINKLOCAL(a) \
(((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80))
#endif
#ifndef IN6_IS_ADDR_MULTICAST
#define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff)
#endif
#ifndef __IPV6_ADDR_MC_SCOPE
#define __IPV6_ADDR_MC_SCOPE(a) ((a)->s6_addr[1] & 0x0f)
#endif
#ifndef __IPV6_ADDR_SCOPE_SITELOCAL
#define __IPV6_ADDR_SCOPE_SITELOCAL 0x05
#endif
#ifndef __IPV6_ADDR_SCOPE_ORGLOCAL
#define __IPV6_ADDR_SCOPE_ORGLOCAL 0x08
#endif
#ifndef IN6_IS_ADDR_MC_SITELOCAL
#define IN6_IS_ADDR_MC_SITELOCAL(a) \
(IN6_IS_ADDR_MULTICAST(a) && \
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_SITELOCAL))
#endif
#ifndef IN6_IS_ADDR_MC_ORGLOCAL
#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
(IN6_IS_ADDR_MULTICAST(a) && \
(__IPV6_ADDR_MC_SCOPE(a) == __IPV6_ADDR_SCOPE_ORGLOCAL))
#endif
#ifndef INADDR_NONE
#define INADDR_NONE 0xffffffff
#endif
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 256
#endif
#ifndef INET6_ADDRSTRLEN
/* sizeof("aaaa:bbbb:cccc:dddd:eeee:ffff:123.123.123.123") */
#define INET6_ADDRSTRLEN 46
#endif
#ifndef MIN
#define MIN(x,y) (((x) <= (y)) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x,y) (((x) >= (y)) ? (x) : (y))
#endif
#ifdef NEED_DAEMON
int daemon(int nochdir, int noclose);
#endif
#ifdef NEED_STRSEP
char * strsep(char **stringp, const char *delim);
#endif
#ifndef ALIGN
#define ALIGN(p) (((unsigned int)(p) + (sizeof(int) - 1)) & ~(sizeof(int) - 1))
#endif
#ifdef NEED_SETGROUPENT
int setgroupent(int stayopen);
#endif
#ifdef NEED_GETGROUPLIST
int getgrouplist(GETGROUPLIST_ARGS);
#endif
#ifdef POSIX_GETGRNAM_R
int
__posix_getgrnam_r(const char *, struct group *, char *, int, struct group **);
#endif
#ifdef NEED_GETGRNAM_R
int
getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
#endif
#ifdef POSIX_GETGRGID_R
int
__posix_getgrgid_r(gid_t, struct group *, char *, int, struct group **) ;
#endif
#ifdef NEED_GETGRGID_R
int
getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
#endif
#ifdef NEED_GETGRENT_R
GROUP_R_RETURN getgrent_r(struct group *gptr, GROUP_R_ARGS);
#endif
#ifdef NEED_SETGRENT_R
GROUP_R_SET_RETURN setgrent_r(GROUP_R_ENT_ARGS);
#endif
#ifdef NEED_ENDGRENT_R
GROUP_R_END_RETURN endgrent_r(GROUP_R_ENT_ARGS);
#endif
#ifdef NEED_INNETGR_R
NGR_R_RETURN
innetgr_r(const char *, const char *, const char *, const char *);
#endif
#ifdef NEED_SETNETGRENT_R
#ifdef NGR_R_ENT_ARGS
NGR_R_SET_RETURN setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS);
#else
NGR_R_SET_RETURN setnetgrent_r(const char *netgroup);
#endif
#endif
#ifdef NEED_ENDNETGRENT_R
#ifdef NGR_R_ENT_ARGS
NGR_R_END_RETURN endnetgrent_r(NGR_R_ENT_ARGS);
#else
NGR_R_END_RETURN endnetgrent_r(void);
#endif
#endif
#ifdef POSIX_GETPWNAM_R
int
__posix_getpwnam_r(const char *login, struct passwd *pwptr,
char *buf, size_t buflen, struct passwd **result);
#endif
#ifdef NEED_GETPWNAM_R
int
getpwnam_r(const char *login, struct passwd *pwptr,
char *buf, size_t buflen, struct passwd **result);
#endif
#ifdef POSIX_GETPWUID_R
int
__posix_getpwuid_r(uid_t uid, struct passwd *pwptr,
char *buf, int buflen, struct passwd **result);
#endif
#ifdef NEED_GETPWUID_R
int
getpwuid_r(uid_t uid, struct passwd *pwptr,
char *buf, size_t buflen, struct passwd **result);
#endif
#ifdef NEED_SETPWENT_R
#ifdef PASS_R_ENT_ARGS
PASS_R_SET_RETURN setpwent_r(PASS_R_ENT_ARGS);
#else
PASS_R_SET_RETURN setpwent_r(void);
#endif
#endif
#ifdef NEED_SETPASSENT_R
#ifdef PASS_R_ENT_ARGS
PASS_R_SET_RETURN setpassent_r(int stayopen, PASS_R_ENT_ARGS);
#else
PASS_R_SET_RETURN setpassent_r(int stayopen);
#endif
#endif
#ifdef NEED_GETPWENT_R
PASS_R_RETURN getpwent_r(struct passwd *pwptr, PASS_R_ARGS);
#endif
#ifdef NEED_ENDPWENT_R
void endpwent_r(void);
#endif
#ifdef NEED_SETPASSENT
int setpassent(int stayopen);
#endif
#define gettimeofday isc__gettimeofday
#ifdef NEED_GETTIMEOFDAY
int isc__gettimeofday(struct timeval *tvp, struct _TIMEZONE *tzp);
#else
int isc__gettimeofday(struct timeval *tp, struct timezone *tzp);
#endif
int getnetgrent(char **machinep, char **userp, char **domainp);
int getnetgrent_r(char **machinep, char **userp, char **domainp, NGR_R_ARGS);
#ifdef SETNETGRENT_ARGS
void setnetgrent(SETNETGRENT_ARGS);
#else
void setnetgrent(const char *netgroup);
#endif
void endnetgrent(void);
#ifdef INNETGR_ARGS
int innetgr(INNETGR_ARGS);
#else
int innetgr(const char *netgroup, const char *machine,
const char *user, const char *domain);
#endif
#ifdef NGR_R_ENT_ARGS
NGR_R_SET_RETURN
setnetgrent_r(const char *netgroup, NGR_R_ENT_ARGS);
#else
NGR_R_SET_RETURN
setnetgrent_r(const char *netgroup);
#endif
#endif

View File

@ -1,140 +0,0 @@
#ifndef port_before_h
#define port_before_h
#include <config.h>
struct group; /* silence warning */
struct passwd; /* silence warning */
struct timeval; /* silence warning */
struct timezone; /* silence warning */
#ifdef HAVE_SYS_TIMERS_H
#include <sys/timers.h>
#endif
#include <limits.h>
#undef WANT_IRS_GR
#undef WANT_IRS_NIS
#undef WANT_IRS_PW
#undef BSD_COMP
// CHANGED: pthread emulation
#define DO_PTHREADS 1
#define GETGROUPLIST_ARGS const char *name, gid_t basegid, gid_t *groups, int *ngroups
#define GETNETBYADDR_ADDR_T long
#define SETPWENT_VOID 1
#define SETGRENT_VOID 1
#define NET_R_ARGS char *buf, int buflen
#define NET_R_BAD NULL
#define NET_R_COPY buf, buflen
#define NET_R_COPY_ARGS NET_R_ARGS
#define NET_R_END_RESULT(x) /*empty*/
#define NET_R_END_RETURN void
#undef NET_R_ENT_ARGS /*empty*/
#define NET_R_OK nptr
#define NET_R_RETURN struct netent *
#undef NET_R_SET_RESULT /*empty*/
#undef NET_R_SETANSWER
#define NET_R_SET_RETURN void
#undef NETENT_DATA
#define GROUP_R_RETURN struct group *
#define GROUP_R_SET_RETURN void
#undef GROUP_R_SET_RESULT /*empty*/
#define GROUP_R_END_RETURN void
#define GROUP_R_END_RESULT(x) /*empty*/
#define GROUP_R_ARGS char *buf, int buflen
#define GROUP_R_ENT_ARGS void
#define GROUP_R_OK gptr
#define GROUP_R_BAD NULL
#define HOST_R_ARGS char *buf, int buflen, int *h_errnop
#define HOST_R_BAD NULL
#define HOST_R_COPY buf, buflen
#define HOST_R_COPY_ARGS char *buf, int buflen
#define HOST_R_END_RESULT(x) /*empty*/
#define HOST_R_END_RETURN void
#undef HOST_R_ENT_ARGS /*empty*/
#define HOST_R_ERRNO *h_errnop = h_errno
#define HOST_R_OK hptr
#define HOST_R_RETURN struct hostent *
#undef HOST_R_SETANSWER
#undef HOST_R_SET_RESULT
#define HOST_R_SET_RETURN void
#undef HOSTENT_DATA
#define NGR_R_ARGS char *buf, int buflen
#define NGR_R_BAD (0)
#define NGR_R_COPY buf, buflen
#define NGR_R_COPY_ARGS NGR_R_ARGS
#define NGR_R_END_RESULT(x) /*empty*/
#define NGR_R_END_RETURN void
#undef NGR_R_ENT_ARGS /*empty*/
#define NGR_R_OK 1
#define NGR_R_RETURN int
#undef NGR_R_SET_RESULT /*empty*/
#define NGR_R_SET_RETURN void
#define PROTO_R_ARGS char *buf, int buflen
#define PROTO_R_BAD NULL
#define PROTO_R_COPY buf, buflen
#define PROTO_R_COPY_ARGS PROTO_R_ARGS
#define PROTO_R_END_RESULT(x) /*empty*/
#define PROTO_R_END_RETURN void
#undef PROTO_R_ENT_ARGS /*empty*/
#define PROTO_R_OK pptr
#undef PROTO_R_SETANSWER
#define PROTO_R_RETURN struct protoent *
#undef PROTO_R_SET_RESULT
#define PROTO_R_SET_RETURN void
#define PASS_R_ARGS char *buf, int buflen
#define PASS_R_BAD NULL
#define PASS_R_COPY buf, buflen
#define PASS_R_COPY_ARGS PASS_R_ARGS
#define PASS_R_END_RESULT(x) /*empty*/
#define PASS_R_END_RETURN void
#undef PASS_R_ENT_ARGS
#define PASS_R_OK pwptr
#define PASS_R_RETURN struct passwd *
#undef PASS_R_SET_RESULT /*empty*/
#define PASS_R_SET_RETURN void
#define SERV_R_ARGS char *buf, int buflen
#define SERV_R_BAD NULL
#define SERV_R_COPY buf, buflen
#define SERV_R_COPY_ARGS SERV_R_ARGS
#define SERV_R_END_RESULT(x) /*empty*/
#define SERV_R_END_RETURN void
#undef SERV_R_ENT_ARGS /*empty*/
#define SERV_R_OK sptr
#undef SERV_R_SETANSWER
#define SERV_R_RETURN struct servent *
#undef SERV_R_SET_RESULT
#define SERV_R_SET_RETURN void
#define DE_CONST(konst, var) \
do { \
union { const void *k; void *v; } _u; \
_u.k = konst; \
var = _u.v; \
} while (0)
#define UNUSED(x) (x) = (x)
#undef NEED_SOLARIS_BITTYPES
#define ISC_SOCKLEN_T int
#ifdef __GNUC__
#define ISC_FORMAT_PRINTF(fmt, args) \
__attribute__((__format__(__printf__, fmt, args)))
#else
#define ISC_FORMAT_PRINTF(fmt, args)
#endif
#endif

View File

@ -1,124 +0,0 @@
SubDir HAIKU_TOP src kits network compat libnet ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UseHeaders [ FDirName $(SUBDIR) headers ] : true ;
UsePrivateHeaders net ;
UseHeaders [ FDirName $(HAIKU_TOP) headers legacy network ] : true ;
if $(TARGET_PLATFORM) != haiku {
UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ;
# We need the public network headers also when not compiling for Haiku.
# Unfortunately we get more than we want, namely all POSIX headers.
# Default libs include BeOS R5 libnet.so, something we don't want here!
LINKFLAGS on libnet.so = [ on libnet.so return $(LINKFLAGS) ]
-nodefaultlibs -lroot ;
}
{
# actually we are always BUILDING_R5_LIBNET, as this means we get unprefixed
# versions of inet_* functions in libnet.so, which is how it should be in any case
# BONE versions of the inet_* functions are prefixed with __ in <arpa/inet.h> and
# implemented in libbind.so as are ours.
local defines ;
if $(TARGET_PLATFORM) = r5 {
defines += BUILDING_R5_LIBNET ;
} else if $(TARGET_PLATFORM) = bone {
defines += BONE_VERSION ;
defines += BUILDING_R5_LIBNET ;
} else if $(TARGET_PLATFORM) = haiku {
defines += BUILDING_R5_LIBNET ;
}
defines = [ FDefines $(defines) ] ;
SubDirCcFlags $(defines) ;
SubDirC++Flags $(defines) ;
}
#Depends libnet.so : install_network_etc_files ;
if $(TARGET_PLATFORM) = r5 {
PLATFORM_SOURCES =
select.c
poll.c
;
PLATFORM_LIBS = ;
} else {
# under Haiku and BONE we don't need the above
# because they are in libsocket.so or libroot.so
PLATFORM_SOURCES = ;
PLATFORM_LIBS = libsocket.so ;
}
SharedLibrary libnet.so :
$(PLATFORM_SOURCES)
netdebug.c
netconfig.c
socket.c
compat.c
arc4random.c
base64.c
ethers.c
freeaddrinfo.c
inet_addr.c
inet_ntoa.c
inet_neta.c
inet_netof.c
inet_lnaof.c
inet_network.c
inet_pton.c
inet_ntop.c
getaddrinfo.c
gethostnamadr.c
getnameinfo.c
getnetbyaddr.c
getnetbyname.c
getnetnamadr.c
getprotoname.c
getnetent.c
getproto.c
getprotoent.c
getservent.c
getservbyname.c
getservbyport.c
linkaddr.c
res_comp.c
res_data.c
res_debug.c
res_init.c
res_mkquery.c
res_query.c
res_random.c
res_send.c
sethostent.c
: $(PLATFORM_LIBS)
;
# HaikuInstall install_network_etc_files : [ FDirName $(HAIKU_ETC_DIR) ] :
# resolv.conf
# services
# protocols
# networks
# ;
# Installation -- in the test directory for the time being
HaikuInstallRelSymLink install-networking
: [ FDirName $(HAIKU_TEST_DIR) kits net lib ]
: libnet.so
: installed-networking-test ;
HaikuInstallRelSymLink install-userland-networking
: [ FDirName $(HAIKU_TEST_DIR) kits net userland lib ]
: libnet.so
: installed-userland-networking ;
Package haiku-networkingkit-cvs :
libnet.so :
# boot home config lib ;
boot home Desktop haiku-networkingkit lib ;
Package haiku-networkingkit-cvs :
resolv.conf services protocols networks :
# boot beos etc ;
boot home Desktop haiku-networkingkit etc ;

View File

@ -1,146 +0,0 @@
/*
* Arc4 random number generator for OpenBSD.
* Copyright 1996 David Mazieres <dm@lcs.mit.edu>.
*
* Modification and redistribution in source and binary forms is
* permitted provided that due credit is given to the author and the
* OpenBSD project by leaving this copyright notice intact.
*/
/*
* This code is derived from section 17.1 of Applied Cryptography,
* second edition, which describes a stream cipher allegedly
* compatible with RSA Labs "RC4" cipher (the actual description of
* which is a trade secret). The same algorithm is used as a stream
* cipher called "arcfour" in Tatu Ylonen's ssh package.
*
* Here the stream cipher has been modified always to include the time
* when initializing the state. That makes it impossible to
* regenerate the same random sequence twice, so this can't be used
* for encryption, but will generate good random numbers.
*
* RC4 is a registered trademark of RSA Laboratories.
*/
#include <kernel/OS.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#ifdef __GNUC__
#define inline __inline
#else /* !__GNUC__ */
#define inline
#endif /* !__GNUC__ */
struct arc4_stream {
uint8 i;
uint8 j;
uint8 s[256];
};
int rs_initialized;
static struct arc4_stream rs;
static inline void arc4_init(struct arc4_stream *as)
{
int n;
for (n = 0; n < 256; n++)
as->s[n] = n;
as->i = 0;
as->j = 0;
}
static inline void arc4_addrandom(struct arc4_stream *as,
u_char *dat, int datlen)
{
int n;
uint8 si;
as->i--;
for (n = 0; n < 256; n++) {
as->i = (as->i + 1);
si = as->s[as->i];
as->j = (as->j + si + dat[n % datlen]);
as->s[as->i] = as->s[as->j];
as->s[as->j] = si;
}
as->j = as->i;
}
static void arc4_stir(struct arc4_stream *as)
{
int fd;
struct {
struct timeval tv;
u_int rnd[(128 - sizeof(struct timeval)) / sizeof(u_int)];
} rdat;
gettimeofday(&rdat.tv, NULL);
fd = open("/dev/arandom", O_RDONLY);
if (fd != -1) {
read(fd, rdat.rnd, sizeof(rdat.rnd));
close(fd);
}
/* fd < 0 or failed sysctl ? Ah, what the heck. We'll just take
* whatever was on the stack... */
arc4_addrandom(as, (void *) &rdat, sizeof(rdat));
}
static inline uint8 arc4_getbyte(struct arc4_stream *as)
{
uint8 si, sj;
as->i = (as->i + 1);
si = as->s[as->i];
as->j = (as->j + si);
sj = as->s[as->j];
as->s[as->i] = sj;
as->s[as->j] = si;
return (as->s[(si + sj) & 0xff]);
}
static inline uint32 arc4_getword(struct arc4_stream *as)
{
uint32 val;
val = arc4_getbyte(as) << 24;
val |= arc4_getbyte(as) << 16;
val |= arc4_getbyte(as) << 8;
val |= arc4_getbyte(as);
return val;
}
void arc4random_stir(void)
{
if (!rs_initialized) {
arc4_init(&rs);
rs_initialized = 1;
}
arc4_stir(&rs);
}
void arc4random_addrandom(u_char *dat, int datlen)
{
if (!rs_initialized)
arc4random_stir();
arc4_addrandom(&rs, dat, datlen);
}
uint32 arc4random()
{
if (!rs_initialized)
arc4random_stir();
return arc4_getword(&rs);
}

View File

@ -1,315 +0,0 @@
/*
* 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) 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.
*/
#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(src, srclength, target, targsize)
u_char const *src;
size_t srclength;
char *target;
size_t targsize;
{
size_t datalength = 0;
u_char input[3];
u_char output[4];
int 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 (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(src, target, targsize)
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 (tarindex >= targsize)
return (-1);
target[tarindex] = (pos - Base64) << 2;
}
state = 1;
break;
case 1:
if (target) {
if (tarindex + 1 >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 4;
target[tarindex+1] = ((pos - Base64) & 0x0f)
<< 4 ;
}
tarindex++;
state = 2;
break;
case 2:
if (target) {
if (tarindex + 1 >= targsize)
return (-1);
target[tarindex] |= (pos - Base64) >> 2;
target[tarindex+1] = ((pos - Base64) & 0x03)
<< 6;
}
tarindex++;
state = 3;
break;
case 3:
if (target) {
if (tarindex >= targsize)
return (-1);
target[tarindex] |= (pos - Base64);
}
tarindex++;
state = 0;
break;
}
}
/*
* 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 (; 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 (; 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);
}

View File

@ -1,185 +0,0 @@
/* compat.c */
/* These routines are included in libnet simply because R5 expects them
* to be there. They should mostly be no-ops...
* Some of them are hacks! We must fix this!!!
*/
#include <fcntl.h>
#include <unistd.h>
#include <OS.h>
#include <iovec.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <net_settings.h>
#include <netdb.h>
#include <TLS.h>
static int32 h_errno_tls = -1;
void _init(void);
void _fini(void);
void initialize_before(void);
void terminate_after(void);
int _netstat(int fd, char **output, int verbose);
void _b_pre_accept(void);
void _b_post_accept(void);
const char * hstrerror(int error);
int _socket_interrupt(void);
char _socket_signals[5];
_EXPORT void _b_pre_accept(void)
{
}
_EXPORT void _b_post_accept(void)
{
}
_EXPORT void initialize_before(void)
{
h_errno_tls = tls_allocate();
}
_EXPORT void terminate_after(void)
{
}
_EXPORT int
_netstat(int fd, char **output, int verbose)
{
return ENOSYS;
}
_EXPORT int closesocket(int sock)
{
return close(sock);
}
_EXPORT const char * hstrerror(int error)
{
printf("hstrerror() not yet supported.");
return "hstrerror() not supported yet";
}
_EXPORT void herror(const char *error)
{
printf("herror() not yet supported.");
}
_EXPORT int * _h_errnop()
{
return (int *) tls_address(h_errno_tls);
}
_EXPORT int _socket_interrupt(void)
{
printf("_socket_interrupt\n");
return 0;
}
/* XXX: HACK HACK HACK! FIXME! */
/* This is a terrible hack :(
* TODO: We should really get these settings values by parsing
* $HOME/config/settings/network file, which will make both R5 and BONE compatible.
*/
_EXPORT char * find_net_setting(net_settings * ncw, const char * heading,
const char * name, char * value, unsigned nbytes)
{
// printf("find_net_setting\n");
if (strcmp(heading, "GLOBAL") != 0)
return NULL;
if (strcmp(name, "HOSTNAME") == 0)
strncpy(value, "hostname", nbytes);
else if (strcmp(name, "USERNAME") == 0)
strncpy(value, "baron\0", nbytes);
else if (strcmp(name, "PASSWORD") == 0)
strncpy(value, "password", nbytes);
else if (strcmp(name, "FTP_ENABLED") == 0)
strncpy(value, "1", nbytes);
else if (strcmp(name, "TELNETD_ENABLED") == 0)
strncpy(value, "1", nbytes);
else
return NULL;
return value;
}
_EXPORT status_t set_net_setting(net_settings * ncw, const char * heading,
const char * name, const char * value)
{
printf("set_net_setting\n");
return B_UNSUPPORTED;
}
_EXPORT int gethostname(char * name, size_t length)
{
// printf("gethostname\n");
if (find_net_setting(NULL, "GLOBAL", "HOSTNAME", name, length) == NULL)
return B_ERROR;
return strlen(name);
}
_EXPORT int getusername(char * name, size_t length)
{
// printf("getusername\n");
if (find_net_setting(NULL, "GLOBAL", "USERNAME", name, length) == NULL)
return B_ERROR;
return strlen(name);
}
_EXPORT int getpassword(char * pwd, size_t length)
{
// printf("getpassword\n");
if (find_net_setting(NULL, "GLOBAL", "PASSWORD", pwd, length) == NULL)
return B_ERROR;
return strlen(pwd);
}
// TODO: This is not a good solution. The complete compat.c should not be
// included in a libnet.so for Haiku, but if left out, _h_errnop is missing
// when linking.
#ifndef __HAIKU__
struct utsname {
char sysname[32];
char nodename[32];
char release[32];
char version[32];
char machine[32];
};
int uname(struct utsname *name);
_EXPORT int uname(struct utsname *name)
{
if (!name)
return B_ERROR;
strcpy(name->sysname, "BeOS");
strcpy(name->nodename, "trantor");
strcpy(name->release, "5.0");
strcpy(name->version, "1000009");
strcpy(name->machine, "BePC");
return B_OK;
}
#endif // !defined(__HAIKU__)

View File

@ -1,261 +0,0 @@
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* 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. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``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 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.
*/
/*
* ethers(3) a la Sun.
* Originally Written by Roland McGrath <roland@frob.com> 10/14/93.
* Substantially modified by Todd C. Miller <Todd.Miller@courtesan.com>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <sys/param.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef YP
#include <rpcsvc/ypclnt.h>
#endif
#include "netdb.h" /* for MAXHOSTNAMELEN */
#ifndef _PATH_ETHERS
#define _PATH_ETHERS "/etc/ethers"
#endif
static char * _ether_aton (char *, struct ether_addr *);
char *ether_ntoa(struct ether_addr *e)
{
static char a[] = "xx:xx:xx:xx:xx:xx";
if (e->ether_addr_octet[0] > 0xFF || e->ether_addr_octet[1] > 0xFF ||
e->ether_addr_octet[2] > 0xFF || e->ether_addr_octet[3] > 0xFF ||
e->ether_addr_octet[4] > 0xFF || e->ether_addr_octet[5] > 0xFF) {
errno = EINVAL;
return (NULL);
}
(void)sprintf(a, "%02x:%02x:%02x:%02x:%02x:%02x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
e->ether_addr_octet[4], e->ether_addr_octet[5]);
return (a);
}
static char *_ether_aton(char *s, struct ether_addr *e)
{
int i;
long l;
char *pp;
while (isspace(*s))
s++;
/* expect 6 hex octets separated by ':' or space/NUL if last octet */
for (i = 0; i < 6; i++) {
l = strtol(s, &pp, 16);
if (pp == s || l > 0xFF || l < 0)
return (NULL);
if (!(*pp == ':' || (i == 5 && (isspace(*pp) || *pp == '\0'))))
return (NULL);
e->ether_addr_octet[i] = (u_char)l;
s = pp + 1;
}
/* return character after the octets ala strtol(3) */
return (pp);
}
struct ether_addr *ether_aton(char *s)
{
static struct ether_addr n;
return (_ether_aton(s, &n) ? &n : NULL);
}
int ether_ntohost(char *hostname, struct ether_addr *e)
{
FILE *f;
char buf[BUFSIZ+1], *p;
size_t len;
struct ether_addr try;
char lbuf[80];
#ifdef YP
char trybuf[sizeof("xx:xx:xx:xx:xx:xx")];
int trylen;
#endif
if (e->ether_addr_octet[0] > 0xFF || e->ether_addr_octet[1] > 0xFF ||
e->ether_addr_octet[2] > 0xFF || e->ether_addr_octet[3] > 0xFF ||
e->ether_addr_octet[4] > 0xFF || e->ether_addr_octet[5] > 0xFF) {
errno = EINVAL;
return (-1);
}
#ifdef YP
sprintf(trybuf, "%x:%x:%x:%x:%x:%x",
e->ether_addr_octet[0], e->ether_addr_octet[1],
e->ether_addr_octet[2], e->ether_addr_octet[3],
e->ether_addr_octet[4], e->ether_addr_octet[5]);
trylen = strlen(trybuf);
#endif
f = fopen(_PATH_ETHERS, "r");
if (f == NULL)
return (-1);
while (fgets(lbuf, 80, f) != NULL) {
len = strlen(lbuf);
p = lbuf;
if (p[len-1] == '\n')
len--;
if (len > sizeof(buf) - 2)
continue;
(void)memcpy(buf, p, len);
buf[len] = '\n'; /* code assumes newlines later on */
buf[len+1] = '\0';
#ifdef YP
/* A + in the file means try YP now. */
if (!strncmp(buf, "+\n", sizeof(buf))) {
char *ypbuf, *ypdom;
int ypbuflen;
if (yp_get_default_domain(&ypdom))
continue;
if (yp_match(ypdom, "ethers.byaddr", trybuf,
trylen, &ypbuf, &ypbuflen))
continue;
if (ether_line(ypbuf, &try, hostname) == 0) {
free(ypbuf);
(void)fclose(f);
return (0);
}
free(ypbuf);
continue;
}
#endif
if (ether_line(buf, &try, hostname) == 0 &&
memcmp((void *)&try, (void *)e, sizeof(try)) == 0) {
(void)fclose(f);
return (0);
}
}
(void)fclose(f);
errno = ENOENT;
return (-1);
}
int
ether_hostton(hostname, e)
char *hostname;
struct ether_addr *e;
{
FILE *f;
char buf[BUFSIZ+1], *p;
char try[MAXHOSTNAMELEN];
size_t len;
char lbuf[80];
#ifdef YP
int hostlen = strlen(hostname);
#endif
f = fopen(_PATH_ETHERS, "r");
if (f==NULL)
return (-1);
while (fgets(lbuf, 80, f) != NULL) {
len = strlen(lbuf);
p = lbuf;
if (p[len-1] == '\n')
len--;
if (len > sizeof(buf) - 2)
continue;
memcpy(buf, p, len);
buf[len] = '\n'; /* code assumes newlines later on */
buf[len+1] = '\0';
#ifdef YP
/* A + in the file means try YP now. */
if (!strncmp(buf, "+\n", sizeof(buf))) {
char *ypbuf, *ypdom;
int ypbuflen;
if (yp_get_default_domain(&ypdom))
continue;
if (yp_match(ypdom, "ethers.byname", hostname, hostlen,
&ypbuf, &ypbuflen))
continue;
if (ether_line(ypbuf, e, try) == 0) {
free(ypbuf);
(void)fclose(f);
return (0);
}
free(ypbuf);
continue;
}
#endif
if (ether_line(buf, e, try) == 0 && strcmp(hostname, try) == 0) {
(void)fclose(f);
return (0);
}
}
(void)fclose(f);
errno = ENOENT;
return (-1);
}
int ether_line(char *line, struct ether_addr *e, char *hostname)
{
char *p;
size_t n;
/* Parse "xx:xx:xx:xx:xx:xx" */
if ((p = _ether_aton(line, e)) == NULL || (*p != ' ' && *p != '\t'))
goto bad;
/* Now get the hostname */
while (isspace(*p))
p++;
if (*p == '\0')
goto bad;
n = strcspn(p, " \t\n");
if (n >= MAXHOSTNAMELEN)
goto bad;
strncpy(hostname, p, n + 1);
return (0);
bad:
errno = EINVAL;
return (-1);
}

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 1996, 1997, 1998, 1999, Craig Metz, 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 Craig Metz and
* by other contributors.
* 4. Neither the name of the author nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE 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.
*/
#include <stdlib.h>
#include <netinet/in.h>
#include <netdb.h>
void
freeaddrinfo(ai)
struct addrinfo *ai;
{
struct addrinfo *p;
do {
p = ai;
ai = ai->ai_next;
if (p->ai_canonname)
free(p->ai_canonname);
free((void *)p);
} while (ai);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,358 +0,0 @@
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* 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. Neither the name of the project 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 PROJECT 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 PROJECT 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.
*/
/*
* Issues to be discussed:
* - Thread safe-ness must be checked
* - RFC2553 says that we should raise error on short buffer. X/Open says
* we need to truncate the result. We obey RFC2553 (and X/Open should be
* modified). ipngwg rough consensus seems to follow RFC2553.
* - What is "local" in NI_FQDN?
* - NI_NAMEREQD and NI_NUMERICHOST conflict with each other.
* - (KAME extension) always attach textual scopeid (fe80::1%lo0), if
* sin6_scope_id is filled - standardization status?
* XXX breaks backward compat for code that expects no scopeid.
* beware on merge.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
#include <string.h>
#include <stddef.h>
static const struct afd {
int a_af;
int a_addrlen;
int a_socklen;
int a_off;
} afdl [] = {
#ifdef INET6
{PF_INET6, sizeof(struct in6_addr), sizeof(struct sockaddr_in6),
offsetof(struct sockaddr_in6, sin6_addr)},
#endif
{PF_INET, sizeof(struct in_addr), sizeof(struct sockaddr_in),
offsetof(struct sockaddr_in, sin_addr)},
{0, 0, 0},
};
struct sockinet {
u_char si_len;
u_char si_family;
u_short si_port;
};
#ifdef INET6
static int ip6_parsenumeric (const struct sockaddr *, const char *, char *,
size_t, int);
static int ip6_sa2str (const struct sockaddr_in6 *, char *, size_t, int);
#endif
int
getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
const struct sockaddr *sa;
socklen_t salen;
char *host;
size_t hostlen;
char *serv;
size_t servlen;
int flags;
{
const struct afd *afd;
struct servent *sp;
struct hostent *hp;
u_short port;
int family, i;
const char *addr;
uint32 v4a;
int h_error;
char numserv[512];
char numaddr[512];
if (sa == NULL)
return EAI_FAIL;
if (sa->sa_len != salen)
return EAI_FAIL;
family = sa->sa_family;
for (i = 0; afdl[i].a_af; i++)
if (afdl[i].a_af == family) {
afd = &afdl[i];
goto found;
}
return EAI_FAMILY;
found:
if (salen != afd->a_socklen)
return EAI_FAIL;
/* network byte order */
port = ((const struct sockinet *)sa)->si_port;
addr = (const char *)sa + afd->a_off;
if (serv == NULL || servlen == 0) {
/*
* do nothing in this case.
* in case you are wondering if "&&" is more correct than
* "||" here: rfc2553bis-03 says that serv == NULL OR
* servlen == 0 means that the caller does not want the result.
*/
} else {
if (flags & NI_NUMERICSERV)
sp = NULL;
else {
sp = getservbyport(port,
(flags & NI_DGRAM) ? "udp" : "tcp");
}
if (sp) {
if (strlen(sp->s_name) + 1 > servlen)
return EAI_MEMORY;
strcpy(serv, sp->s_name);
} else {
#ifdef _MWERKS_STDIO_H_
sprintf(numserv, "%d", ntohs(port));
#else
snprintf(numserv, sizeof(numserv), "%d", ntohs(port));
#endif
if (strlen(numserv) + 1 > servlen)
return EAI_MEMORY;
strcpy(serv, numserv);
}
}
switch (sa->sa_family) {
case AF_INET:
v4a = (uint32)
ntohl(((const struct sockaddr_in *)sa)->sin_addr.s_addr);
if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a))
flags |= NI_NUMERICHOST;
v4a >>= IN_CLASSA_NSHIFT;
if (v4a == 0)
flags |= NI_NUMERICHOST;
break;
#ifdef INET6
case AF_INET6:
{
const struct sockaddr_in6 *sin6;
sin6 = (const struct sockaddr_in6 *)sa;
switch (sin6->sin6_addr.s6_addr[0]) {
case 0x00:
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr))
;
else if (IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr))
;
else
flags |= NI_NUMERICHOST;
break;
default:
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
flags |= NI_NUMERICHOST;
}
else if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
flags |= NI_NUMERICHOST;
break;
}
}
break;
#endif
}
if (host == NULL || hostlen == 0) {
/*
* do nothing in this case.
* in case you are wondering if "&&" is more correct than
* "||" here: rfc2553bis-03 says that host == NULL or
* hostlen == 0 means that the caller does not want the result.
*/
} else if (flags & NI_NUMERICHOST) {
int numaddrlen;
/* NUMERICHOST and NAMEREQD conflicts with each other */
if (flags & NI_NAMEREQD)
return EAI_NONAME;
switch(afd->a_af) {
#ifdef INET6
case AF_INET6:
{
int error;
if ((error = ip6_parsenumeric(sa, addr, host,
hostlen, flags)) != 0)
return(error);
break;
}
#endif
default:
if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr))
== NULL)
return EAI_SYSTEM;
numaddrlen = strlen(numaddr);
if (numaddrlen + 1 > hostlen) /* don't forget terminator */
return EAI_MEMORY;
strcpy(host, numaddr);
break;
}
} else {
hp = gethostbyaddr(addr, afd->a_addrlen, afd->a_af);
h_error = h_errno;
if (hp) {
#if 0
/*
* commented out, since "for local host" is not
* implemented here - see RFC2553 p30
*/
if (flags & NI_NOFQDN) {
char *p;
p = strchr(hp->h_name, '.');
if (p)
*p = '\0';
}
#endif
if (strlen(hp->h_name) + 1 > hostlen) {
return EAI_MEMORY;
}
strcpy(host, hp->h_name);
} else {
if (flags & NI_NAMEREQD)
return EAI_NONAME;
switch(afd->a_af) {
#ifdef INET6
case AF_INET6:
{
int error;
if ((error = ip6_parsenumeric(sa, addr, host,
hostlen,
flags)) != 0)
return(error);
break;
}
#endif
default:
if (inet_ntop(afd->a_af, addr, host,
hostlen) == NULL)
return EAI_SYSTEM;
break;
}
}
}
return(0);
}
#ifdef INET6
static int
ip6_parsenumeric(sa, addr, host, hostlen, flags)
const struct sockaddr *sa;
const char *addr;
char *host;
size_t hostlen;
int flags;
{
int numaddrlen;
char numaddr[512];
if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
return EAI_SYSTEM;
numaddrlen = strlen(numaddr);
if (numaddrlen + 1 > hostlen) /* don't forget terminator */
return EAI_MEMORY;
strcpy(host, numaddr);
if (((const struct sockaddr_in6 *)sa)->sin6_scope_id) {
char zonebuf[MAXHOSTNAMELEN];
int zonelen;
zonelen = ip6_sa2str(
(const struct sockaddr_in6 *)(const void *)sa,
zonebuf, sizeof(zonebuf), flags);
if (zonelen < 0)
return EAI_MEMORY;
if (zonelen + 1 + numaddrlen + 1 > hostlen)
return EAI_MEMORY;
/* construct <numeric-addr><delim><zoneid> */
memcpy(host + numaddrlen + 1, zonebuf,
(size_t)zonelen);
host[numaddrlen] = SCOPE_DELIMITER;
host[numaddrlen + 1 + zonelen] = '\0';
}
return 0;
}
/* ARGSUSED */
static int
ip6_sa2str(sa6, buf, bufsiz, flags)
const struct sockaddr_in6 *sa6;
char *buf;
size_t bufsiz;
int flags;
{
unsigned int ifindex;
const struct in6_addr *a6;
int n;
ifindex = (unsigned int)sa6->sin6_scope_id;
a6 = &sa6->sin6_addr;
#ifdef notdef
if ((flags & NI_NUMERICSCOPE) != 0) {
n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
if (n < 0 || n >= bufsiz)
return -1;
else
return n;
}
#endif
/* if_indextoname() does not take buffer size. not a good api... */
if ((IN6_IS_ADDR_LINKLOCAL(a6) || IN6_IS_ADDR_MC_LINKLOCAL(a6)) &&
bufsiz >= IF_NAMESIZE) {
char *p = if_indextoname(ifindex, buf);
if (p) {
return(strlen(p));
}
}
/* last resort */
n = snprintf(buf, bufsiz, "%u", sa6->sin6_scope_id);
if (n < 0 || n >= bufsiz)
return -1;
else
return n;
}
#endif /* INET6 */

View File

@ -1,54 +0,0 @@
/*
* 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.
*/
#include <kernel/OS.h>
#include <netinet/in.h>
#include <netdb.h>
extern int _net_stayopen;
struct netent *
_getnetbyaddr(net, type)
register in_addr_t net;
register int type;
{
register struct netent *p;
setnetent(_net_stayopen);
while ((p = getnetent()))
if (p->n_addrtype == type && p->n_net == net)
break;
if (!_net_stayopen)
endnetent();
return (p);
}

View File

@ -1,60 +0,0 @@
/*
* 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.
*/
#include <OS.h>
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
extern int _net_stayopen;
struct netent *
_getnetbyname(name)
register const char *name;
{
register struct netent *p;
register char **cp;
setnetent(_net_stayopen);
while ((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);
}

View File

@ -1,131 +0,0 @@
/*
* 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.
*/
#include <sys/types.h>
#include <kernel/OS.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.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];
int _net_stayopen;
void
setnetent(f)
int f;
{
if (netf == NULL)
netf = fopen(_PATH_NETWORKS, "r" );
else
rewind(netf);
_net_stayopen |= f;
}
void
endnetent()
{
if (netf) {
fclose(netf);
netf = NULL;
}
_net_stayopen = 0;
}
struct netent *
getnetent()
{
char *p, *cp, **q;
size_t len;
char buf[80];
if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
return (NULL);
again:
if (fgets(buf, 80, netf) == NULL)
return NULL;
len = strlen(buf);
p = &buf[len];
// if ((p = fgetln(netf, &len)) == NULL)
// return (NULL);
if (p[len-1] == '\n')
len--;
if (len >= sizeof(line) || len == 0)
goto again;
p = memcpy(line, p, len);
line[len] = '\0';
if (*p == '#')
goto again;
if ((cp = strchr(p, '#')) != NULL)
*cp = '\0';
net.n_name = p;
if (strlen(net.n_name) >= MAXHOSTNAMELEN-1)
net.n_name[MAXHOSTNAMELEN-1] = '\0';
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;
if (strlen(cp) >= MAXHOSTNAMELEN-1)
cp[MAXHOSTNAMELEN-1] = '\0';
}
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
*q = NULL;
return (&net);
}

View File

@ -1,391 +0,0 @@
/*
* Copyright (c) 1997, 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Jason Downs for the
* OpenBSD system.
* 4. Neither the name(s) of the author(s) nor the name OpenBSD
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* 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.
*/
/* 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.
*/
/*
* 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.
*/
#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 <netdb.h>
#include <resolv.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
struct netent *_getnetbyaddr (in_addr_t net, int type);
struct netent *_getnetbyname (const char *name);
int _hokchar (const char *);
#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(answer, anslen, net_i)
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[BUFSIZ+1];
/*
* 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);
#ifdef USE_RESOLV_NAME_OK
if ((n < 0) || !res_dnok(bp))
#else
if ((n < 0) || !_hokchar(bp))
#endif
break;
cp += n;
ans[0] = '\0';
strncpy(&ans[0], bp, sizeof ans);
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);
#ifdef USE_RESOLV_NAME_OK
if ((n < 0) || !res_hnok(bp)) {
#else
if ((n < 0) || !_hokchar(bp)) {
#endif
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;
strncpy(paux1,
(i==0) ? in : in-1,
(i==0) ? nchar+1 : nchar+2);
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 *
getnetbyaddr(net, net_type)
register in_addr_t net;
register int net_type;
{
unsigned int netbr[4];
int nn, anslen;
querybuf buf;
char qbuf[MAXDNAME];
in_addr_t net2;
struct netent *net_entry = NULL;
char lookups[MAXDNSLUS];
int i;
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
return(_getnetbyaddr(net, net_type));
memcpy(lookups, _res.lookups, sizeof lookups);
if (lookups[0] == '\0')
strncpy(lookups, "bf", sizeof lookups);
for (i = 0; i < MAXDNSLUS && lookups[i]; i++) {
switch (lookups[i]) {
#ifdef YP
case 'y':
/* There is no YP support. */
break;
#endif /* YP */
case 'b':
if (net_type != AF_INET)
break; /* DNS only supports AF_INET? */
for (nn = 4, net2 = net; net2; net2 >>= 8)
netbr[--nn] = net2 & 0xff;
switch (nn) {
#ifndef _MWERKS_STDIO_H_
case 3: /* Class A */
snprintf(qbuf, sizeof(qbuf),
"0.0.0.%u.in-addr.arpa", netbr[3]);
break;
case 2: /* Class B */
snprintf(qbuf, sizeof(qbuf),
"0.0.%u.%u.in-addr.arpa",
netbr[3], netbr[2]);
break;
case 1: /* Class C */
snprintf(qbuf, sizeof(qbuf),
"0.%u.%u.%u.in-addr.arpa",
netbr[3], netbr[2], netbr[1]);
break;
case 0: /* Class D - E */
snprintf(qbuf, sizeof(qbuf),
"%u.%u.%u.%u.in-addr.arpa",
netbr[3], netbr[2], netbr[1], netbr[0]);
break;
#else
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;
#endif
}
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
break;
}
net_entry = getnetanswer(&buf, anslen, BYADDR);
if (net_entry != NULL) {
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);
}
break;
case 'f':
net_entry = _getnetbyaddr(net, net_type);
if (net_entry != NULL)
return (net_entry);
}
}
/* Nothing matched. */
return (NULL);
}
struct netent *
getnetbyname(net)
register const char *net;
{
int anslen;
querybuf buf;
char qbuf[MAXDNAME];
struct netent *net_entry = NULL;
char lookups[MAXDNSLUS];
int i;
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
return (_getnetbyname(net));
memcpy(lookups, _res.lookups, sizeof lookups);
if (lookups[0] == '\0')
strncpy(lookups, "bf", sizeof lookups);
for (i = 0; i < MAXDNSLUS && lookups[i]; i++) {
switch (lookups[i]) {
#ifdef YP
case 'y':
/* There is no YP support. */
break;
#endif /* YP */
case 'b':
strncpy(qbuf, net, sizeof qbuf);
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
break;
}
net_entry = getnetanswer(&buf, anslen, BYNAME);
if (net_entry != NULL)
return (net_entry);
break;
case 'f':
net_entry = _getnetbyname(net);
if (net_entry != NULL)
return (net_entry);
break;
}
}
/* Nothing matched. */
return (NULL);
}

View File

@ -1,50 +0,0 @@
/*
* 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.
*/
#include <netinet/in.h>
#include <netdb.h>
extern int _proto_stayopen;
struct protoent *getprotobynumber(int proto)
{
struct protoent *p;
setprotoent(_proto_stayopen);
while ((p = getprotoent()))
if (p->p_proto == proto)
break;
if (!_proto_stayopen)
endprotoent();
return (p);
}

View File

@ -1,126 +0,0 @@
/*
* 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.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.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, *cp, **q, *endp;
long l;
size_t len;
char buf[80];
if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
return (NULL);
again:
if (fgets(buf, 80, protof) == NULL)
return NULL;
len = strlen(buf);
p = buf;
// if ((p = fgetln(protof, &len)) == NULL)
// return (NULL);
if (p[len-1] == '\n')
len--;
if (len >= sizeof(line) || len == 0)
goto again;
p = memcpy(line, p, len);
line[len] = '\0';
if (*p == '#')
goto again;
if ((cp = strchr(p, '#')) != NULL)
*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';
l = strtol(cp, &endp, 10);
if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX)
goto again;
proto.p_proto = l;
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);
}

View File

@ -1,58 +0,0 @@
/*
* 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.
*/
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
extern int _proto_stayopen;
struct protoent *getprotobyname(const char *name)
{
struct protoent *p;
char **cp;
setprotoent(_proto_stayopen);
while ((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);
}

View File

@ -1,81 +0,0 @@
/*
* 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.
*/
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
extern int _serv_stayopen;
struct servent *getservent();
struct servent *
getservbyname_r(name, proto, se, buf, buflen)
const char *name, *proto;
struct servent *se;
char *buf;
int buflen;
{
register struct servent *p;
register char **cp;
setservent(_serv_stayopen);
while ((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();
return (p);
}
struct servent *getservbyname(name, proto)
const char *name, *proto;
{
static char buf[4096];
char *bufp = (char*)&buf;
if (bufp == NULL)
return (NULL);
return getservbyname_r(name, proto, (struct servent*) bufp,
bufp + sizeof(struct servent),
sizeof buf - sizeof(struct servent) );
}

View File

@ -1,58 +0,0 @@
/*
* 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.
*/
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
extern int _serv_stayopen;
struct servent *getservent();
struct servent *
getservbyport(port, proto)
int port;
const char *proto;
{
register struct servent *p;
setservent(_serv_stayopen);
while ((p = getservent())) {
if (p->s_port != port)
continue;
if (proto == 0 || strcmp(p->s_proto, proto) == 0)
break;
}
if (!_serv_stayopen)
endservent();
return (p);
}

View File

@ -1,133 +0,0 @@
/*
* 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.
*/
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAXALIASES 35
static FILE *servf = NULL;
static char line[BUFSIZ+1];
static struct servent serv;
static char *serv_aliases[MAXALIASES];
int _serv_stayopen;
void
setservent(f)
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, *cp, **q, *endp;
long l;
size_t len;
char buf[80];
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
return (NULL);
again:
if (fgets(buf, 80, servf) == NULL)
return NULL;
len = strlen(buf);
p = buf;
// if ((p = fgetln(servf, &len)) == NULL)
// return (NULL);
if (p[len-1] == '\n')
len--;
if (len >= sizeof(line) || len == 0)
goto again;
p = memcpy(line, p, len);
line[len] = '\0';
if (*p == '#')
goto again;
if ((cp = strchr(p, '#')) != NULL)
*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';
l = strtol(p, &endp, 10);
if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX)
goto again;
serv.s_port = htons((in_port_t)l);
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);
}

View File

@ -1,57 +0,0 @@
/* arpa/inet.h */
/* public definitions of inet functions... */
#ifndef _INET_H_
#define _INET_H_
#include <sys/param.h>
#include <sys/types.h>
#include <netinet/in.h>
/* R5 libnet function names conflict with libbind. BONE uses a prefix to solve this. */
#ifndef BUILDING_R5_LIBNET
#define inet_addr __inet_addr
#define inet_aton __inet_aton
#define inet_lnaof __inet_lnaof
#define inet_makeaddr __inet_makeaddr
#define inet_neta __inet_neta
#define inet_netof __inet_netof
#define inet_network __inet_network
#define inet_net_ntop __inet_net_ntop
#define inet_net_pton __inet_net_pton
#define inet_ntoa __inet_ntoa
#define inet_pton __inet_pton
#define inet_ntop __inet_ntop
#define inet_nsap_addr __inet_nsap_addr
#define inet_nsap_ntoa __inet_nsap_ntoa
#endif /* BUILDING_R5_LIBNET */
#ifdef __cplusplus
extern "C" {
#endif
in_addr_t inet_addr (const char *);
int inet_aton (const char *, struct in_addr *);
in_addr_t inet_lnaof (struct in_addr);
struct in_addr inet_makeaddr (in_addr_t , in_addr_t);
char * inet_neta (in_addr_t, char *, size_t);
in_addr_t inet_netof (struct in_addr);
in_addr_t inet_network (const char *);
char *inet_net_ntop (int, const void *, int, char *, size_t);
int inet_net_pton (int, const char *, void *, size_t);
char *inet_ntoa (struct in_addr);
int inet_pton (int, const char *, void *);
const char *inet_ntop (int, const void *, char *, size_t);
u_int inet_nsap_addr (const char *, u_char *, int);
char *inet_nsap_ntoa (int, const u_char *, char *);
#ifdef __cplusplus
}
#endif
#endif /* _INET_H */

View File

@ -1,370 +0,0 @@
/* $OpenBSD: nameser.h,v 1.6 2001/07/31 22:02:18 jakob Exp $ */
/*
* ++Copyright++ 1983, 1989, 1993
* -
* 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.
* -
* 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.
* --Copyright--
*/
/*
* @(#)nameser.h 8.1 (Berkeley) 6/2/93
* $From: nameser.h,v 8.11 1996/10/08 04:51:02 vixie Exp $
*/
#ifndef _NAMESER_H_
#define _NAMESER_H_
#include <sys/param.h>
#include <sys/types.h>
#include <endian.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* 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 (__BIND > 19931104)". do not
* compare for equality; rather, use it to determine whether your resolver
* is new enough to contain a certain feature.
*/
#define __BIND 19960801 /* interface version stamp */
/*
* Define constants based on rfc883
*/
#define PACKETSZ 512 /* maximum packet size */
#define MAXDNAME 1025 /* maximum presentation domain name */
#define MAXCDNAME 255 /* maximum compressed domain name */
#define MAXLABEL 63 /* maximum length of domain label */
#define HFIXEDSZ 12 /* #/bytes of fixed data in header */
#define QFIXEDSZ 4 /* #/bytes of fixed data in query */
#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
#define INT32SZ 4 /* for systems without 32-bit ints */
#define INT16SZ 2 /* for systems without 16-bit ints */
#define INADDRSZ 4 /* IPv4 T_A */
#define IN6ADDRSZ 16 /* IPv6 T_AAAA */
/*
* Internet nameserver port number
*/
#define NAMESERVER_PORT 53
/*
* Currently defined opcodes
*/
#define QUERY 0x0 /* standard query */
#define IQUERY 0x1 /* inverse query */
#define STATUS 0x2 /* nameserver status query */
/*#define xxx 0x3*/ /* 0x3 reserved */
#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
/*
* Currently defined response codes
*/
#define NOERROR 0 /* no error */
#define FORMERR 1 /* format error */
#define SERVFAIL 2 /* server failure */
#define NXDOMAIN 3 /* non existent domain */
#define NOTIMP 4 /* not implemented */
#define REFUSED 5 /* query refused */
/*
* Type values for resources and queries
*/
#define T_A 1 /* host address */
#define T_NS 2 /* authoritative server */
#define T_MD 3 /* mail destination */
#define T_MF 4 /* mail forwarder */
#define T_CNAME 5 /* canonical name */
#define T_SOA 6 /* start of authority zone */
#define T_MB 7 /* mailbox domain name */
#define T_MG 8 /* mail group member */
#define T_MR 9 /* mail rename name */
#define T_NULL 10 /* null resource record */
#define T_WKS 11 /* well known service */
#define T_PTR 12 /* domain name pointer */
#define T_HINFO 13 /* host information */
#define T_MINFO 14 /* mailbox information */
#define T_MX 15 /* mail routing information */
#define T_TXT 16 /* text strings */
#define T_RP 17 /* responsible person */
#define T_AFSDB 18 /* AFS cell database */
#define T_X25 19 /* X_25 calling address */
#define T_ISDN 20 /* ISDN calling address */
#define T_RT 21 /* router */
#define T_NSAP 22 /* NSAP address */
#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
#define T_SIG 24 /* security signature */
#define T_KEY 25 /* security key */
#define T_PX 26 /* X.400 mail mapping */
#define T_GPOS 27 /* geographical position (withdrawn) */
#define T_AAAA 28 /* IP6 Address */
#define T_LOC 29 /* Location Information */
#define T_NXT 30 /* Next Valid Name in Zone */
#define T_EID 31 /* Endpoint identifier */
#define T_NIMLOC 32 /* Nimrod locator */
#define T_SRV 33 /* Server selection */
#define T_ATMA 34 /* ATM Address */
#define T_NAPTR 35 /* Naming Authority PoinTeR */
#define T_OPT 41 /* OPT pseudo-RR, RFC2671 */
/* non standard */
#define T_UINFO 100 /* user (finger) information */
#define T_UID 101 /* user ID */
#define T_GID 102 /* group ID */
#define T_UNSPEC 103 /* Unspecified format (binary data) */
/* Query type values which do not appear in resource records */
#define T_IXFR 251 /* incremental zone transfer */
#define T_AXFR 252 /* transfer zone of authority */
#define T_MAILB 253 /* transfer mailbox records */
#define T_MAILA 254 /* transfer mail agent records */
#define T_ANY 255 /* wildcard match */
/*
* Values for class field
*/
#define C_IN 1 /* the arpa internet */
#define C_CHAOS 3 /* for chaos net (MIT) */
#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
/* Query class values which do not appear in resource records */
#define C_ANY 255 /* wildcard match */
/*
* Flags field of the KEY RR rdata
*/
#define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */
#define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
#define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
#define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
#define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
/* The type bits can also be interpreted independently, as single bits: */
#define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */
#define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */
#define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
#define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */
#define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */
#define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
#define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */
#define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */
#define KEYFLAG_IPSEC 0x0080 /* key is for IPSEC use (host or user)*/
#define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */
#define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */
#define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */
#define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */
#define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
KEYFLAG_RESERVED4 | \
KEYFLAG_RESERVED10| KEYFLAG_RESERVED11)
/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
#define ALGORITHM_MD5RSA 1 /* MD5 with RSA */
#define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */
#define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */
/* Signatures */
/* Size of a mod or exp in bits */
#define MIN_MD5RSA_KEY_PART_BITS 512
#define MAX_MD5RSA_KEY_PART_BITS 2552
/* Total of binary mod and exp, bytes */
#define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
/* Max length of text sig block */
#define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
/*
* EDNS0 Z-field extended flags
*/
#define DNS_MESSAGEEXTFLAG_DO 0x8000U
/*
* Status return codes for T_UNSPEC conversion routines
*/
#define CONV_SUCCESS 0
#define CONV_OVERFLOW (-1)
#define CONV_BADFMT (-2)
#define CONV_BADCKSUM (-3)
#define CONV_BADBUFLEN (-4)
#if !defined(BYTE_ORDER) || \
(BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
BYTE_ORDER != PDP_ENDIAN)
/* you must determine what the correct bit order is for
* your compiler - the next line is an intentional error
* which will force your compiles to bomb until you fix
* the above macros.
*/
error "Undefined or invalid BYTE_ORDER";
#endif
/*
* Structure for query header. The order of the fields is machine- and
* compiler-dependent, depending on the byte/bit order and the layout
* of bit fields. We use bit fields only in int variables, as this
* is all ANSI requires. This requires a somewhat confusing rearrangement.
*/
typedef struct {
unsigned id :16; /* query identification number */
#if BYTE_ORDER == BIG_ENDIAN
/* fields in third byte */
unsigned qr: 1; /* response flag */
unsigned opcode: 4; /* purpose of message */
unsigned aa: 1; /* authoritive answer */
unsigned tc: 1; /* truncated message */
unsigned rd: 1; /* recursion desired */
/* fields in fourth byte */
unsigned ra: 1; /* recursion available */
unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
unsigned ad: 1; /* authentic data from named */
unsigned cd: 1; /* checking disabled by resolver */
unsigned rcode :4; /* response code */
#endif
#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
/* fields in third byte */
unsigned rd :1; /* recursion desired */
unsigned tc :1; /* truncated message */
unsigned aa :1; /* authoritive answer */
unsigned opcode :4; /* purpose of message */
unsigned qr :1; /* response flag */
/* fields in fourth byte */
unsigned rcode :4; /* response code */
unsigned cd: 1; /* checking disabled by resolver */
unsigned ad: 1; /* authentic data from named */
unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
unsigned ra :1; /* recursion available */
#endif
/* remaining bytes */
unsigned qdcount :16; /* number of question entries */
unsigned ancount :16; /* number of answer entries */
unsigned nscount :16; /* number of authority entries */
unsigned arcount :16; /* number of resource entries */
} HEADER;
/*
* Defines for handling compressed domain names
*/
#define INDIR_MASK 0xc0
extern uint16 _getshort (const u_char *);
extern uint32 _getlong (const u_char *);
/*
* Inline versions of get/put short/long. Pointer is advanced.
*
* These macros demonstrate the property of C whereby it can be
* portable or it can be elegant but rarely both.
*/
#define GETSHORT(s, cp) { \
register u_char *t_cp = (u_char *)(cp); \
(s) = ((uint16)t_cp[0] << 8) \
| ((uint16)t_cp[1]) \
; \
(cp) += INT16SZ; \
}
#define GETLONG(l, cp) { \
register u_char *t_cp = (u_char *)(cp); \
(l) = ((uint32)t_cp[0] << 24) \
| ((uint32)t_cp[1] << 16) \
| ((uint32)t_cp[2] << 8) \
| ((uint32)t_cp[3]) \
; \
(cp) += INT32SZ; \
}
#define PUTSHORT(s, cp) { \
register uint16 t_s = (uint16)(s); \
register u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_s >> 8; \
*t_cp = t_s; \
(cp) += INT16SZ; \
}
#define PUTLONG(l, cp) { \
register uint32 t_l = (uint32)(l); \
register u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_l >> 24; \
*t_cp++ = t_l >> 16; \
*t_cp++ = t_l >> 8; \
*t_cp = t_l; \
(cp) += INT32SZ; \
}
#ifdef __cplusplus
}
#endif
#endif /* !_NAMESER_H_ */

View File

@ -1,185 +0,0 @@
/* netdb.h */
#ifndef NETDB_H
#define NETDB_H
#include <netinet/in.h>
#include <errno.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MAXHOSTNAMELEN
#define MAXHOSTNAMELEN 64
#endif
#define HOST_NOT_FOUND 1
#define TRY_AGAIN 2
#define NO_RECOVERY 3
#define NO_DATA 4
// Make h_errno thread-safe
extern int *_h_errnop(void);
#define h_errno (*(_h_errnop()))
struct hostent {
char *h_name;
char **h_aliases;
int h_addrtype;
int h_length;
char **h_addr_list;
};
#define h_addr h_addr_list[0]
struct servent {
char *s_name;
char **s_aliases;
int s_port;
char *s_proto;
};
/*
* Assumption here is that a network number
* fits in an in_addr_t -- probably a poor one.
*/
struct netent {
char *n_name; /* official name of net */
char **n_aliases; /* alias list */
int n_addrtype; /* net address type */
in_addr_t n_net; /* network # */
};
struct protoent {
char *p_name; /* official protocol name */
char **p_aliases; /* alias list */
int p_proto; /* protocol # */
};
struct addrinfo {
int ai_flags; /* input flags */
int ai_family; /* protocol family for socket */
int ai_socktype; /* socket type */
int ai_protocol; /* protocol for socket */
socklen_t ai_addrlen; /* length of socket-address */
struct sockaddr *ai_addr; /* socket-address for socket */
char *ai_canonname; /* canonical name for service location (iff req) */
struct addrinfo *ai_next; /* pointer to next in list */
};
struct hostent *gethostbyname(const char *hostname);
struct hostent *gethostbyaddr(const char *hostname, int len, int type);
struct servent *getservbyname(const char *name, const char *proto);
void herror(const char *);
unsigned long inet_addr(const char *a_addr);
char *inet_ntoa(struct in_addr addr);
int gethostname(char *hostname, size_t hostlen);
/* BE specific, because of lack of UNIX passwd functions */
int getusername(char *username, size_t userlen);
int getpassword(char *password, size_t passlen);
/* These are new! */
struct netent *getnetbyaddr (in_addr_t, int);
struct netent *getnetbyname (const char *);
struct netent *getnetent (void);
struct protoent *getprotoent (void);
struct protoent *getprotobyname (const char *);
struct protoent *getprotobynumber (int);
struct hostent *gethostbyname2 (const char *, int);
struct servent *getservbyport (int, const char *);
int getaddrinfo (const char *, const char *,
const struct addrinfo *,
struct addrinfo **);
void freeaddrinfo (struct addrinfo *);
int getnameinfo (const struct sockaddr *, socklen_t,
char *, size_t, char *, size_t,
int);
void sethostent (int);
void setnetent (int);
void setprotoent (int);
void setservent (int);
void endhostent (void);
void endnetent (void);
void endprotoent (void);
void endservent (void);
#define _PATH_HEQUIV "/etc/hosts.equiv"
#define _PATH_HOSTS "/etc/hosts"
#define _PATH_NETWORKS "/etc/networks"
#define _PATH_PROTOCOLS "/etc/protocols"
#define _PATH_SERVICES "/etc/services"
/*
* Error return codes from gethostbyname() and gethostbyaddr()
* (left in extern int h_errno).
*/
#define NETDB_INTERNAL -1 /* see errno */
#define NETDB_SUCCESS 0 /* no problem */
#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */
#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
#define NO_DATA 4 /* Valid name, no data record of requested type */
#define NO_ADDRESS NO_DATA /* no address, look for MX record */
/* Values for getaddrinfo() and getnameinfo() */
#define AI_PASSIVE 1 /* socket address is intended for bind() */
#define AI_CANONNAME 2 /* request for canonical name */
#define AI_NUMERICHOST 4 /* don't ever try nameservice */
#define AI_EXT 8 /* enable non-portable extensions */
/* valid flags for addrinfo */
#define AI_MASK (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST)
#define NI_NUMERICHOST 1 /* return the host address, not the name */
#define NI_NUMERICSERV 2 /* return the service address, not the name */
#define NI_NOFQDN 4 /* return a short name if in the local domain */
#define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
#define NI_DGRAM 16 /* look up datagram service instead of stream */
#define NI_WITHSCOPEID 32 /* KAME hack: attach scopeid to host portion */
#define NI_MAXHOST MAXHOSTNAMELEN /* max host name returned by getnameinfo */
#define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
/*
* Scope delimit character (KAME hack)
*/
#define SCOPE_DELIMITER '%'
#define EAI_BADFLAGS -1 /* invalid value for ai_flags */
#define EAI_NONAME -2 /* name or service is not known */
#define EAI_AGAIN -3 /* temporary failure in name resolution */
#define EAI_FAIL -4 /* non-recoverable failure in name resolution */
#define EAI_NODATA -5 /* no address associated with name */
#define EAI_FAMILY -6 /* ai_family not supported */
#define EAI_SOCKTYPE -7 /* ai_socktype not supported */
#define EAI_SERVICE -8 /* service not supported for ai_socktype */
#define EAI_ADDRFAMILY -9 /* address family for name not supported */
#define EAI_MEMORY -10 /* memory allocation failure */
#define EAI_SYSTEM -11 /* system error (code indicated in errno) */
#define EAI_BADHINTS -12 /* invalid value for hints */
#define EAI_PROTOCOL -13 /* resolved protocol is unknown */
/*
* Flags for getrrsetbyname()
*/
#define RRSET_VALIDATED 1
/*
* Return codes for getrrsetbyname()
*/
#define ERRSET_SUCCESS 0
#ifdef __cplusplus
}
#endif
#endif /* NETDB_H */

View File

@ -1,358 +0,0 @@
/* $OpenBSD: resolv.h,v 1.7 2001/07/31 22:02:18 jakob Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* 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. Neither the name of the project 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 PROJECT 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 PROJECT 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.
*/
/*
* ++Copyright++ 1983, 1987, 1989, 1993
* -
* 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) 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--
*/
/*
* @(#)resolv.h 8.1 (Berkeley) 6/2/93
* $From: resolv.h,v 8.17 1996/11/26 10:11:20 vixie Exp $
*/
#ifndef _RESOLV_H_
#define _RESOLV_H_
/* #include <kernel/OS.h> */
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* 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
/*
* Resolver configuration file.
* Normally not present, but may contain the address of the
* initial name server(s) to query and the domain search list.
*/
#ifndef _PATH_RESCONF
#define _PATH_RESCONF "/etc/resolv.conf"
#endif
/*
* 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 MAXDNSLUS 4 /* max # of host lookup types */
#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;
uint32 mask;
} sort_list[MAXRESOLVSORT];
char lookups[MAXDNSLUS];
char pad[68]; /* on an i386 this means 512b total */
};
#ifdef INET6
/*
* replacement of __res_state, separated to keep binary compatibility.
*/
struct __res_state_ext {
struct sockaddr_storage nsaddr_list[MAXNS];
struct {
int af; /* address family for addr, mask */
union {
struct in_addr ina;
struct in6_addr in6a;
} addr, mask;
} sort_list[MAXRESOLVSORT];
};
#endif
/*
* 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 trucation 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() */
/* KAME extensions: use higher bit to avoid conflict with ISC use */
#define RES_USE_EDNS0 0x40000000 /* use EDNS0 */
/* DNSSEC extensions: use higher bit to avoid conflict with ISC use */
#define RES_USE_DNSSEC 0x20000000 /* use DNSSEC using OK bit in OPT */
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
/*
* Resolver "pfcode" values. Used by dig.
*/
#define RES_PRF_STATS 0x00000001
/* 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 */
/* hooks are still experimental as of 4.9.2 */
typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
res_sendhookact;
typedef res_sendhookact (*res_send_qhook)(struct sockaddr_in * const *ns,
const uchar **query,
int *querylen,
uchar *ans,
int anssiz,
int *resplen);
typedef res_sendhookact (*res_send_rhook)(const struct sockaddr_in *ns,
const uchar *query,
int querylen,
uchar *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;
#ifdef INET6
extern struct __res_state_ext _res_ext;
#endif
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 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_cdname __p_cdname
#define p_fqnname __p_fqnname
#define p_fqname __p_fqname
#define p_rr __p_rr
#define p_option __p_option
#define p_secstodate __p_secstodate
#define dn_count_labels __dn_count_labels
#define dn_comp __dn_comp
#define res_randomid __res_randomid
#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_opt __res_opt
#ifdef BIND_RES_POSIX3
#define dn_expand __dn_expand
#define res_init __res_init
#define res_query __res_query
#define res_search __res_search
#define res_querydomain __res_querydomain
#define res_mkquery __res_mkquery
#endif
int res_hnok (const char *);
int res_ownok (const char *);
int res_mailok (const char *);
int res_dnok (const char *);
int sym_ston (const struct res_sym *, char *, int *);
const char * sym_ntos (const struct res_sym *, int, int *);
const char * sym_ntop (const struct res_sym *, int, int *);
int b64_ntop (uchar const *, size_t, char *, size_t);
int b64_pton (char const *, uchar *, size_t);
int loc_aton (const char *, uchar *);
const char * loc_ntoa (const uchar *, char *);
int dn_skipname (const uchar *, const uchar *);
void fp_resstat (struct __res_state *, FILE *);
void fp_query (const uchar *, FILE *);
void fp_nquery (const uchar *, int, FILE *);
const char * hostalias (const char *);
void putlong (uint32, uchar *);
void putshort (uint16, uchar *);
const char * p_class (int);
const char * p_time (uint32);
const char * p_type (int);
void p_query (const uchar *);
const uchar * p_cdnname (const uchar *, const uchar *, int, FILE *);
const uchar * p_cdname (const uchar *, const uchar *, FILE *);
const uchar * p_fqnname (const uchar *cp, const uchar *msg,
int, char *, int);
const uchar * p_fqname (const uchar *, const uchar *, FILE *);
const uchar * p_rr (const uchar *, const uchar *, FILE *);
const char * p_option (u_long option);
char * p_secstodate (u_long);
int dn_count_labels (char *);
int dn_comp (const char *, uchar *, int,
uchar **, uchar **);
int dn_expand (const uchar *, const uchar *, const uchar *,
char *, int);
int res_init (void);
uint res_randomid (void);
int res_query (const char *, int, int, uchar *, int);
int res_search (const char *, int, int, uchar *, int);
int res_querydomain (const char *, const char *, int, int,
uchar *, int);
int res_mkquery (int, const char *, int, int, const uchar *, int,
const uchar *, uchar *, int);
int res_send (const uchar *, int, uchar *, int);
int res_isourserver (const struct sockaddr_in *);
int res_nameinquery (const char *, int, int,
const uchar *, const uchar *);
int res_queriesmatch (const uchar *, const uchar *,
const uchar *, const uchar *);
void res_close (void);
#ifdef __cplusplus
}
#endif
#endif /* !_RESOLV_H_ */

View File

@ -1,176 +0,0 @@
/*
* ++Copyright++ 1983, 1990, 1993
* -
* Copyright (c) 1983, 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.
* -
* 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--
*/
#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
/*
* Ascii internet address interpretation routine.
* The value returned is in network order.
*/
in_addr_t
inet_addr(cp)
register const char *cp;
{
struct in_addr val;
if (inet_aton(cp, &val))
return (val.s_addr);
return (INADDR_NONE);
}
/*
* Check whether "cp" is a valid ascii representation
* of an Internet address and convert to a binary address.
* Returns 1 if the address is valid, 0 if not.
* This replaces inet_addr, the return value from which
* cannot distinguish between failure and a local broadcast address.
*/
int
inet_aton(cp, addr)
register const char *cp;
struct in_addr *addr;
{
register in_addr_t val;
register int base, n;
register char c;
u_int parts[4];
register u_int *pp = parts;
c = *cp;
for (;;) {
/*
* Collect number up to ``.''.
* Values are specified as for C:
* 0x=hex, 0=octal, isdigit=decimal.
*/
if (!isdigit(c))
return (0);
val = 0; base = 10;
if (c == '0') {
c = *++cp;
if (c == 'x' || c == 'X')
base = 16, c = *++cp;
else
base = 8;
}
for (;;) {
if (isascii(c) && isdigit(c)) {
val = (val * base) + (c - '0');
c = *++cp;
} else if (base == 16 && isascii(c) && isxdigit(c)) {
val = (val << 4) |
(c + 10 - (islower(c) ? 'a' : 'A'));
c = *++cp;
} else
break;
}
if (c == '.') {
/*
* Internet format:
* a.b.c.d
* a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
if (pp >= parts + 3)
return (0);
*pp++ = val;
c = *++cp;
} else
break;
}
/*
* Check for trailing characters.
*/
if (c != '\0' && (!isascii(c) || !isspace(c)))
return (0);
/*
* Concoct the address according to
* the number of parts specified.
*/
n = pp - parts + 1;
switch (n) {
case 0:
return (0); /* initial nondigit */
case 1: /* a -- 32 bits */
break;
case 2: /* a.b -- 8.24 bits */
if ((val > 0xffffff) || (parts[0] > 0xff))
return (0);
val |= parts[0] << 24;
break;
case 3: /* a.b.c -- 8.8.16 bits */
if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff))
return (0);
val |= (parts[0] << 24) | (parts[1] << 16);
break;
case 4: /* a.b.c.d -- 8.8.8.8 bits */
if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff))
return (0);
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
break;
}
if (addr)
addr->s_addr = htonl(val);
return (1);
}

View File

@ -1,55 +0,0 @@
/*
* 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.
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/*
* Return the local network address portion of an
* internet address; handles class a/b/c network
* number formats.
*/
in_addr_t
inet_lnaof(in)
struct in_addr in;
{
register in_addr_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return ((i)&IN_CLASSA_HOST);
else if (IN_CLASSB(i))
return ((i)&IN_CLASSB_HOST);
else
return ((i)&IN_CLASSC_HOST);
}

View File

@ -1,73 +0,0 @@
/*
* 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.
*/
#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>
/*
* char *
* inet_neta(src, dst, size)
* format an in_addr_t 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(src, dst, size)
in_addr_t src;
char *dst;
size_t size;
{
char *odst = dst;
char *tp;
while (src & 0xffffffff) {
u_char b = (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);
}

View File

@ -1,54 +0,0 @@
/*
* 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.
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/*
* Return the network number from an internet
* address; handles class a/b/c network #'s.
*/
in_addr_t
inet_netof(in)
struct in_addr in;
{
register in_addr_t i = ntohl(in.s_addr);
if (IN_CLASSA(i))
return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
else if (IN_CLASSB(i))
return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
else
return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
}

View File

@ -1,88 +0,0 @@
/*
* 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.
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
/*
* Internet network address interpretation routine.
* The library routines call this routine to interpret
* network numbers.
*/
in_addr_t
inet_network(cp)
register const char *cp;
{
register in_addr_t val, base, n;
register char c;
in_addr_t parts[4], *pp = parts;
register int i;
again:
val = 0; base = 10;
if (*cp == '0')
base = 8, cp++;
if (*cp == 'x' || *cp == 'X')
base = 16, cp++;
while ((c = *cp)) {
if (isdigit(c)) {
val = (val * base) + (c - '0');
cp++;
continue;
}
if (base == 16 && isxdigit(c)) {
val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
cp++;
continue;
}
break;
}
if (*cp == '.') {
if (pp >= parts + 3)
return (INADDR_NONE);
*pp++ = val, cp++;
goto again;
}
if (*cp && !isspace(*cp))
return (INADDR_NONE);
*pp++ = val;
n = pp - parts;
for (val = 0, i = 0; i < 4; i++) {
val <<= 8;
if (i < n)
val |= parts[i] & 0xff;
}
return (val);
}

View File

@ -1,60 +0,0 @@
/*
* 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.
*/
/*
* Convert network-format internet address
* to base 256 d.d.d.d representation.
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
char *
inet_ntoa(in)
struct in_addr in;
{
static char b[18];
register char *p;
p = (char *)&in;
#define UC(b) (((int)b)&0xff)
#ifdef _MWERKS_STDIO_H_
(void)sprintf(b,
"%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
#else
(void)snprintf(b, sizeof(b),
"%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3]));
#endif
return (b);
}

View File

@ -1,184 +0,0 @@
/* 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.
*/
#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>
#include <stdio.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 const char *inet_ntop4 (const u_char *src, char *dst, size_t size);
static const char *inet_ntop6 (const u_char *src, char *dst, size_t size);
/* char *
* inet_ntop(af, src, dst, size)
* convert a network format address to presentation format.
* return:
* pointer to presentation format address (`dst'), or NULL (see errno).
* author:
* Paul Vixie, 1996.
*/
const char *
inet_ntop(af, src, dst, size)
int af;
const void *src;
char *dst;
size_t size;
{
switch (af) {
case AF_INET:
return (inet_ntop4(src, dst, size));
case AF_INET6:
return (inet_ntop6(src, dst, size));
default:
errno = EAFNOSUPPORT;
return (NULL);
}
/* NOTREACHED */
}
/* const char *
* inet_ntop4(src, dst, size)
* format an IPv4 address, more or less like inet_ntoa()
* return:
* `dst' (as a const)
* notes:
* (1) uses no statics
* (2) takes a u_char* not an in_addr as input
* author:
* Paul Vixie, 1996.
*/
static const char *
inet_ntop4(src, dst, size)
const u_char *src;
char *dst;
size_t size;
{
static const char fmt[] = "%u.%u.%u.%u";
char tmp[sizeof "255.255.255.255"];
if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) {
errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
return (dst);
}
/* const char *
* inet_ntop6(src, dst, size)
* convert IPv6 binary address into presentation (printable) format
* author:
* Paul Vixie, 1996.
*/
static const char *
inet_ntop6(src, dst, size)
const u_char *src;
char *dst;
size_t size;
{
/*
* Note that int32_t and int16_t need only be "at least" large enough
* to contain a value of the specified size. On some systems, like
* Crays, there is no such thing as an integer variable with 16 bits.
* Keep this in mind if you think this function should have been coded
* to use pointer overlays. All the world's not a VAX.
*/
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
struct { int base, len; } best, cur;
u_int words[IN6ADDRSZ / INT16SZ];
int i;
/*
* Preprocess:
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
memset(words, '\0', sizeof words);
for (i = 0; i < IN6ADDRSZ; i++)
words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3));
best.base = -1;
cur.base = -1;
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
if (words[i] == 0) {
if (cur.base == -1)
cur.base = i, cur.len = 1;
else
cur.len++;
} else {
if (cur.base != -1) {
if (best.base == -1 || cur.len > best.len)
best = cur;
cur.base = -1;
}
}
}
if (cur.base != -1) {
if (best.base == -1 || cur.len > best.len)
best = cur;
}
if (best.base != -1 && best.len < 2)
best.base = -1;
/*
* Format the result.
*/
tp = tmp;
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
/* Are we inside the best run of 0x00's? */
if (best.base != -1 && i >= best.base &&
i < (best.base + best.len)) {
if (i == best.base)
*tp++ = ':';
continue;
}
/* Are we following an initial run of 0x00s or any real hex? */
if (i != 0)
*tp++ = ':';
/* Is this address an encapsulated IPv4? */
if (i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
return (NULL);
tp += strlen(tp);
break;
}
tp += sprintf(tp, "%x", words[i]);
}
/* Was it a trailing run of 0x00's? */
if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ))
*tp++ = ':';
*tp++ = '\0';
/*
* Check for overflow, copy, and we're done.
*/
if ((size_t)(tp - tmp) > size) {
errno = ENOSPC;
return (NULL);
}
strcpy(dst, tmp);
return (dst);
}

View File

@ -1,212 +0,0 @@
/* 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.
*/
#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(af, src, dst)
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(src, dst)
const char *src;
u_char *dst;
{
static const char digits[] = "0123456789";
int saw_digit, octets, ch;
u_char tmp[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 + (pch - digits);
if (new > 255)
return (0);
if (! saw_digit) {
if (++octets > 4)
return (0);
saw_digit = 1;
}
*tp = new;
} 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, 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(src, dst)
const char *src;
u_char *dst;
{
static const char xdigits_l[] = "0123456789abcdef",
xdigits_u[] = "0123456789ABCDEF";
u_char tmp[IN6ADDRSZ], *tp, *endp, *colonp;
const char *xdigits, *curtok;
int ch, saw_xdigit;
u_int val;
memset((tp = tmp), '\0', IN6ADDRSZ);
endp = tp + 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;
} else if (*src == '\0') {
return (0);
}
if (tp + INT16SZ > endp)
return (0);
*tp++ = (u_char) (val >> 8) & 0xff;
*tp++ = (u_char) val & 0xff;
saw_xdigit = 0;
val = 0;
continue;
}
if (ch == '.' && ((tp + INADDRSZ) <= endp) &&
inet_pton4(curtok, tp) > 0) {
tp += INADDRSZ;
saw_xdigit = 0;
break; /* '\0' was seen by inet_pton4(). */
}
return (0);
}
if (saw_xdigit) {
if (tp + 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 = 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, IN6ADDRSZ);
return (1);
}

View File

@ -1,155 +0,0 @@
/*-
* 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.
*/
#include <sys/types.h>
#include <kernel/OS.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <string.h>
/* States*/
#define NAMING 0
#define GOTONE 1
#define GOTTWO 2
#define RESET 3
/* Inputs */
#define DIGIT (4*0)
#define END (4*1)
#define DELIM (4*2)
#define LETTER (4*3)
void
link_addr(addr, sdl)
register const char *addr;
register struct sockaddr_dl *sdl;
{
register char *cp = sdl->sdl_data;
char *cplim = sdl->sdl_len + (char *)sdl;
register int byte = 0, state = NAMING, newv = 0;
memset((char *)&sdl->sdl_family, 0, sdl->sdl_len - 1);
sdl->sdl_family = AF_LINK;
do {
state &= ~LETTER;
if ((*addr >= '0') && (*addr <= '9')) {
newv = *addr - '0';
} else if ((*addr >= 'a') && (*addr <= 'f')) {
newv = *addr - 'a' + 10;
} else if ((*addr >= 'A') && (*addr <= 'F')) {
newv = *addr - 'A' + 10;
} else if (*addr == 0) {
state |= END;
} else if (state == NAMING &&
(((*addr >= 'A') && (*addr <= 'Z')) ||
((*addr >= 'a') && (*addr <= 'z'))))
state |= LETTER;
else
state |= DELIM;
addr++;
switch (state /* | INPUT */) {
case NAMING | DIGIT:
case NAMING | LETTER:
*cp++ = addr[-1];
continue;
case NAMING | DELIM:
state = RESET;
sdl->sdl_nlen = cp - sdl->sdl_data;
continue;
case GOTTWO | DIGIT:
*cp++ = byte;
/* FALLTHROUGH */
case RESET | DIGIT:
state = GOTONE;
byte = newv;
continue;
case GOTONE | DIGIT:
state = GOTTWO;
byte = newv + (byte << 4);
continue;
default: /* | DELIM */
state = RESET;
*cp++ = byte;
byte = 0;
continue;
case GOTONE | END:
case GOTTWO | END:
*cp++ = byte;
/* FALLTHROUGH */
case RESET | END:
break;
}
break;
} while (cp < cplim);
sdl->sdl_alen = cp - LLADDR(sdl);
newv = cp - (char *)sdl;
if (newv > sizeof(*sdl))
sdl->sdl_len = newv;
return;
}
static char hexlist[] = "0123456789abcdef";
char *
link_ntoa(sdl)
register const struct sockaddr_dl *sdl;
{
static char obuf[64];
register char *out = obuf;
register int i;
register u_char *in = (u_char *)LLADDR(sdl);
u_char *inlim = in + sdl->sdl_alen;
int firsttime = 1;
if (sdl->sdl_nlen) {
memcpy(obuf, sdl->sdl_data, sdl->sdl_nlen);
out += sdl->sdl_nlen;
if (sdl->sdl_alen)
*out++ = ':';
}
while (in < inlim) {
if (firsttime)
firsttime = 0;
else
*out++ = '.';
i = *in++;
if (i > 0xf) {
out[1] = hexlist[i & 0xf];
i >>= 4;
out[0] = hexlist[i];
out += 2;
} else
*out++ = hexlist[i];
}
*out = 0;
return (obuf);
}

View File

@ -1,15 +0,0 @@
/*
** Copyright 2005, Jérôme DUVAL. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <netconfig.h>
_EXPORT char *
_netconfig_find(const char *heading, const char *name, char *value,
int nbytes)
{
printf("_netconfig_find heading:%s, name:%s, value:%s, nbytes:%d\n", heading, name, value, nbytes);
return find_net_setting(NULL, heading, name, value, nbytes);
}

View File

@ -1,12 +0,0 @@
/*
** Copyright 2005, Jérôme DUVAL. All rights reserved.
** Distributed under the terms of the Haiku License.
*/
#include <netdebug.h>
_EXPORT void
_debug_setflags(unsigned flags)
{
}

View File

@ -1,10 +0,0 @@
# Haiku /etc/networks
#
# Internet networks (from nic.ddn.mil)
# 1) The multicast network
BASE-ADDRESS.MCAST.NET 224
loopback 127 loop
# Your subnets follow...

View File

@ -1,60 +0,0 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/select.h>
#include <poll.h>
// -------------------------------
int poll(struct pollfd *fds, nfds_t numfds, int timeout)
{
fd_set read_set;
fd_set write_set;
fd_set exception_set;
nfds_t i;
int n;
int rc;
FD_ZERO(&read_set);
FD_ZERO(&write_set);
FD_ZERO(&exception_set);
n = -1;
for(i = 0; i < numfds; i++) {
if (fds[i].fd < 0)
continue;
if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set);
if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set);
if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set);
if (fds[i].fd > n)
n = fds[i].fd;
};
if (n == -1)
// Hey!? Nothing to poll, in fact!!!
return 0;
if (timeout < 0)
rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
else {
struct timeval tv;
tv.tv_sec = timeout / 1000;
tv.tv_usec = 1000 * (timeout % 1000);
rc = select(n+1, &read_set, &write_set, &exception_set, &tv);
};
if (rc < 0)
return rc;
for(i = 0; i < (nfds_t) n; i++) {
fds[i].revents = 0;
if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN;
if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT;
if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR;
};
return rc;
}

View File

@ -1,110 +0,0 @@
#
# Internet (IP) protocols
#
# Updated based on RFC 1340, Assigned Numbers (July 1992).
# See also http://www.isi.edu/in-notes/iana/assignments/protocol-numbers
#
ip 0 IP # internet protocol, pseudo protocol number
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
ucl 7 UCL # UCL
egp 8 EGP # exterior gateway protocol
igp 9 IGP # any private interior gateway
bbn-rcc-mon 10 BBN-RCC-MON # BBN RCC Monitoring
nvp-ii 11 NVP-II # Network Voice Protocol
pup 12 PUP # PARC universal packet protocol
argus 13 ARGUS # ARGUS
emcon 14 EMCON # EMCON
xnet 15 XNET # Cross Net Debugger
chaos 16 CHAOS # Chaos
udp 17 UDP # user datagram protocol
mux 18MUX# Multiplexing
dcn-meas 19DCN-MEAS# DCN Measurement Subsystems
hmp 20HMP# host monitoring protocol
prm 21PRM# Packet Radio Measurement
xns-idp 22XNS-IDP# Xerox NS IDP
trunk-1 23TRUNK-1# Trunk-1
trunk-2 24TRUNK-2# Trunk-2
leaf-1 25LEAF-1# Leaf-1
leaf-2 26LEAF-2# Leaf-2
rdp 27RDP# "reliable datagram" protocol
irtp 28IRTP# Internet Reliable Transaction
iso-tp4 29ISO-TP4# ISO Transport Protocol class 4
netblt 30NETBLT# Bulk Data Transfer Protocol
mfe-nsp 31MFE-NSP# MFE Network Services Protocol
merit-inp 32MERIT-INP# MERIT Internodal Protocol
sep 33SEP# Sequential Exchange Protocol
3pc 343PC# Third Party Connect Protocol
idpr 35IDPR# Inter-Domain Policy Routing Protocol
xtp 36XTP# Xpress Tranfer Protocol
ddp 37DDP# Datagram Delivery Protocol
idpr-cmtp 38IDPR-CMTP# IDPR Control Message Transport Proto
idpr-cmtp 39IDPR-CMTP# IDPR Control Message Transport
il 40IL# IL Transport Protocol
ipv6 41IPv6# Internet Protocol version 6
sdrp 42SDRP# Source Demand Routing Protocol
sip-sr 43SIP-SR# SIP Source Route
sip-frag 44SIP-FRAG# SIP Fragment
idrp 45IDRP# Inter-Domain Routing Protocol
rsvp 46RSVP# Reservation Protocol
gre 47GRE# General Routing Encapsulation
mhrp 48MHRP# Mobile Host Routing Protocol
bna 49BNA# BNA
esp 50IPSEC-ESP# Encap Security Payload
ah 51IPSEC-AH# Authentication Header
i-nlsp 52I-NLSP# Integrated Net Layer Security TUBA
swipe 53SWIPE# IP with Encryption
nhrp 54NHRP# NBMA Next Hop Resolution Protocol
mobileip 55MOBILEIP# MobileIP encapsulation
skip 57SKIP# SKIP
ipv6-icmp 58IPv6-ICMP# ICMP for IPv6
ipv6-nonxt 59IPv6-NoNxt# No Next Header for IPv6
ipv6-opts 60IPv6-Opts# Destination Options for IPv6
any 61any# host internal protocol
cftp 62CFTP# CFTP
any 63any# local network
sat-expak 64SAT-EXPAK# SATNET and Backroom EXPAK
kryptolan 65KRYPTOLAN# Kryptolan
rvd 66RVD# MIT Remote Virtual Disk Protocol
ippc 67IPPC# Internet Pluribus Packet Core
any 68any# distributed file system
sat-mon 69SAT-MON# SATNET Monitoring
visa 70VISA# VISA Protocol
ipcv 71IPCV# Internet Packet Core Utility
cpnx 72CPNX# Computer Protocol Network Executive
cphb 73CPHB# Computer Protocol Heart Beat
wsn 74WSN# Wang Span Network
pvp 75PVP# Packet Video Protocol
br-sat-mon 76BR-SAT-MON# Backroom SATNET Monitoring
sun-nd 77SUN-ND# SUN ND PROTOCOL-Temporary
wb-mon 78WB-MON# WIDEBAND Monitoring
wb-expak 79WB-EXPAK# WIDEBAND EXPAK
iso-ip 80ISO-IP# ISO Internet Protocol
vmtp 81VMTP# Versatile Message Transport
secure-vmtp 82SECURE-VMTP # SECURE-VMTP
vines 83VINES# VINES
ttp 84TTP# TTP
nsfnet-igp 85NSFNET-IGP# NSFNET-IGP
dgp 86DGP# Dissimilar Gateway Protocol
tcf 87TCF# TCF
igrp 88IGRP# IGRP
ospf 89OSPFIGP# Open Shortest Path First IGP
sprite-rpc 90Sprite-RPC# Sprite RPC Protocol
larp 91LARP# Locus Address Resolution Protocol
mtp 92MTP# Multicast Transport Protocol
ax.25 93AX.25# AX.25 Frames
ipip 94IPIP# Yet Another IP encapsulation
micp 95MICP# Mobile Internetworking Control Pro.
scc-sp 96SCC-SP# Semaphore Communications Sec. Pro.
etherip 97ETHERIP# Ethernet-within-IP Encapsulation
encap 98ENCAP# Yet Another IP encapsulation
any 99any# private encryption scheme
gmtp 100GMTP# GMTP
pim 103PIM# Protocol Independent Multicast
ipcomp 108IPComp# IP Payload Compression Protocol
vrrp 112VRRP# Virtual Router Redundancy Protocol
reserved 255Reserved#

View File

@ -1,499 +0,0 @@
/*
* ++Copyright++ 1985, 1993
* -
* Copyright (c) 1985, 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--
*/
#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <netdb.h> /* for MAXHOSTNAMELEN */
#include <resolv.h>
#include <stdio.h>
#include <ctype.h>
#include <unistd.h>
#include <string.h>
static int dn_find (u_char *exp_dn, u_char *msg,
u_char **dnptrs, u_char **lastdnptr);
/*
* 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(msg, eomorig, comp_dn, exp_dn, length)
const u_char *msg, *eomorig, *comp_dn;
char *exp_dn;
int length;
{
register const u_char *cp;
register char *dn;
register int n, c;
char *eom;
int len = -1, checked = 0;
dn = exp_dn;
cp = comp_dn;
if (length > MAXHOSTNAMELEN-1)
length = MAXHOSTNAMELEN-1;
eom = exp_dn + length;
/*
* fetch next label in domain name
*/
while ((n = *cp++)) {
/*
* Check for indirection
*/
switch (n & INDIR_MASK) {
case 0:
if (dn != exp_dn) {
if (dn >= eom)
return (-1);
*dn++ = '.';
}
if (dn+n >= eom)
return (-1);
checked += n + 1;
while (--n >= 0) {
if (((c = *cp++) == '.') || (c == '\\')) {
if (dn + n + 2 >= eom)
return (-1);
*dn++ = '\\';
}
*dn++ = c;
if (cp >= eomorig) /* out of range */
return (-1);
}
break;
case INDIR_MASK:
if (len < 0)
len = cp - comp_dn + 1;
cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
if (cp < msg || cp >= eomorig) /* out of range */
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 >= eomorig - msg)
return (-1);
break;
default:
return (-1); /* flag error */
}
}
*dn = '\0';
if (len < 0)
len = cp - comp_dn;
return (len);
}
/*
* Compress domain name 'exp_dn' into 'comp_dn'.
* Return the size of the compressed name or -1.
* 'length' is the size of the array pointed to by 'comp_dn'.
* 'dnptrs' is a list 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 arrary 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
dn_comp(exp_dn, comp_dn, length, dnptrs, lastdnptr)
const char *exp_dn;
u_char *comp_dn, **dnptrs, **lastdnptr;
int length;
{
register u_char *cp, *dn;
register int c, l;
u_char **cpp, **lpp, *sp, *eob;
u_char *msg;
dn = (u_char *)exp_dn;
cp = comp_dn;
eob = cp + length;
lpp = cpp = NULL;
if (dnptrs != NULL) {
if ((msg = *dnptrs++) != NULL) {
for (cpp = dnptrs; *cpp != NULL; cpp++)
;
lpp = cpp; /* end of list to search */
}
} else
msg = NULL;
for (c = *dn++; c != '\0'; ) {
/* look to see if we can use pointers */
if (msg != NULL) {
if ((l = dn_find(dn-1, msg, dnptrs, lpp)) >= 0) {
if (cp+1 >= eob)
return (-1);
*cp++ = (l >> 8) | INDIR_MASK;
*cp++ = l % 256;
return (cp - comp_dn);
}
/* not found, save it */
if (lastdnptr != NULL && cpp < lastdnptr-1) {
*cpp++ = cp;
*cpp = NULL;
}
}
sp = cp++; /* save ptr to length byte */
do {
if (c == '.') {
c = *dn++;
break;
}
if (c == '\\') {
if ((c = *dn++) == '\0')
break;
}
if (cp >= eob) {
if (msg != NULL)
*lpp = NULL;
return (-1);
}
*cp++ = c;
} while ((c = *dn++) != '\0');
/* catch trailing '.'s but not '..' */
if ((l = cp - sp - 1) == 0 && c == '\0') {
cp--;
break;
}
if (l <= 0 || l > MAXLABEL) {
if (msg != NULL)
*lpp = NULL;
return (-1);
}
*sp = l;
}
if (cp >= eob) {
if (msg != NULL)
*lpp = NULL;
return (-1);
}
*cp++ = '\0';
return (cp - comp_dn);
}
/*
* Skip over a compressed domain name. Return the size or -1.
*/
int
__dn_skipname(comp_dn, eom)
const u_char *comp_dn, *eom;
{
register const u_char *cp;
register int n;
cp = comp_dn;
while (cp < eom && (n = *cp++)) {
/*
* check for indirection
*/
switch (n & INDIR_MASK) {
case 0: /* normal case, n == len */
cp += n;
continue;
case INDIR_MASK: /* indirection */
cp++;
break;
default: /* illegal type */
return (-1);
}
break;
}
if (cp > eom)
return (-1);
return (cp - comp_dn);
}
static int
mklower(ch)
register int ch;
{
if (isascii(ch) && isupper(ch))
return (tolower(ch));
return (ch);
}
/*
* Search for expanded name from a list of previously compressed names.
* Return the offset from msg if found or -1.
* dnptrs is the pointer to the first name on the list,
* not the pointer to the start of the message.
*/
static int
dn_find(exp_dn, msg, dnptrs, lastdnptr)
u_char *exp_dn, *msg;
u_char **dnptrs, **lastdnptr;
{
register u_char *dn, *cp, **cpp;
register int n;
u_char *sp;
for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
dn = exp_dn;
sp = cp = *cpp;
while ((n = *cp++)) {
/*
* check for indirection
*/
switch (n & INDIR_MASK) {
case 0: /* normal case, n == len */
while (--n >= 0) {
if (*dn == '.')
goto next;
if (*dn == '\\')
dn++;
if (mklower(*dn++) != mklower(*cp++))
goto next;
}
if ((n = *dn++) == '\0' && *cp == '\0')
return (sp - msg);
if (n == '.')
continue;
goto next;
case INDIR_MASK: /* indirection */
cp = msg + (((n & 0x3f) << 8) | *cp);
break;
default: /* illegal type */
return (-1);
}
}
if (*dn == '\0')
return (sp - msg);
next: ;
}
return (-1);
}
/*
* 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(dn)
const char *dn;
{
int pch = PERIOD, ch = *dn++;
while (ch != '\0') {
int nch = *dn++;
if (periodchar(ch)) {
;
} 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);
}
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(dn)
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(dn)
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(dn)
const char *dn;
{
int ch;
while ((ch = *dn++) != '\0')
if (!domainchar(ch))
return (0);
return (1);
}
/*
* Routines to insert/extract short/long's.
*/
uint16 _getshort(const u_char *msgp)
{
uint16 u;
GETSHORT(u, msgp);
return (u);
}
#ifdef NeXT
/*
* nExt machines have some funky library conventions, which we must maintain.
*/
uint16
res_getshort(msgp)
register const u_char *msgp;
{
return (_getshort(msgp));
}
#endif
uint32
_getlong(msgp)
register const u_char *msgp;
{
register uint32 u;
GETLONG(u, msgp);
return (u);
}
void
#if defined(__STDC__) || defined(__cplusplus)
__putshort(register uint16 s, register u_char *msgp) /* must match proto */
#else
__putshort(s, msgp)
register uint16 s;
register u_char *msgp;
#endif
{
PUTSHORT(s, msgp);
}
void
__putlong(l, msgp)
register uint32 l;
register u_char *msgp;
{
PUTLONG(l, msgp);
}

View File

@ -1,107 +0,0 @@
/*
* ++Copyright++ 1995
* -
* Copyright (c) 1995
* 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--
*/
#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 <stdio.h>
#include <ctype.h>
#include <resolv.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
const char *_res_opcodes[] = {
"QUERY",
"IQUERY",
"CQUERYM",
"CQUERYU", /* experimental */
"NOTIFY", /* experimental */
"5",
"6",
"7",
"8",
"UPDATEA",
"UPDATED",
"UPDATEDA",
"UPDATEM",
"UPDATEMA",
"ZONEINIT",
"ZONEREF",
};
const char *_res_resultcodes[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"REFUSED",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"NOCHANGE",
};

File diff suppressed because it is too large Load Diff

View File

@ -1,621 +0,0 @@
/*
* ++Copyright++ 1985, 1989, 1993
* -
* Copyright (c) 1985, 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) 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--
*/
#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 <stdio.h>
#include <ctype.h>
#include <resolv.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
/*-------------------------------------- info about "sortlist" --------------
* Marc Majka 1994/04/16
* Allan Nathanson 1994/10/29 (BIND 4.9.3.x)
*
* NetInfo resolver configuration directory support.
*
* Allow a NetInfo directory to be created in the hierarchy which
* contains the same information as the resolver configuration file.
*
* - The local domain name is stored as the value of the "domain" property.
* - The Internet address(es) of the name server(s) are stored as values
* of the "nameserver" property.
* - The name server addresses are stored as values of the "nameserver"
* property.
* - The search list for host-name lookup is stored as values of the
* "search" property.
* - The sortlist comprised of IP address netmask pairs are stored as
* values of the "sortlist" property. The IP address and optional netmask
* should be separated by a slash (/) or ampersand (&) character.
* - Internal resolver variables can be set from the value of the "options"
* property.
*/
static void res_setoptions (char *, char *);
#ifdef RESOLVSORT
static const char sort_mask[] = "/&";
#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
static uint32 net_mask (struct in_addr);
#endif
/*
* Resolver state default settings.
*/
struct __res_state _res
# if defined(__BIND_RES_TEXT)
= { RES_TIMEOUT, } /* Motorola, et al. */
# endif
;
#ifdef INET6
struct __res_state_ext _res_ext;
#endif /* INET6 */
/*
* 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[BUFSIZ];
int nserv = 0; /* number of nameserver records read from file */
int haveenv = 0;
int havesearch = 0;
size_t len;
char lbuf[80];
#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;
#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.nsaddr.sin_len = sizeof(struct sockaddr_in);
#ifdef INET6
if (sizeof(_res_ext.nsaddr) >= _res.nsaddr.sin_len)
memcpy(&_res_ext.nsaddr, &_res.nsaddr, _res.nsaddr.sin_len);
#endif
_res.nscount = 1;
_res.ndots = 1;
_res.pfcode = 0;
strncpy(_res.lookups, "f", sizeof _res.lookups);
/* Allow user to override the local domain definition */
if ((cp = getenv("LOCALDOMAIN")) != NULL) {
strncpy(_res.defdname, cp, sizeof(_res.defdname));
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) {
strncpy(_res.lookups, "bf", sizeof _res.lookups);
/* read the config file */
buf[0] = '\0';
while (fgets(lbuf, 80, fp) != NULL) {
/* skip lines that are too long or zero length */
len = strlen(lbuf) - 1;
cp = lbuf;
if (len >= sizeof(buf) || len == 0)
continue;
memcpy(buf, cp, len);
buf[len] = '\0';
/* skip comments */
if ((cp = strpbrk(buf, ";#")) != NULL)
*cp = '\0';
if (buf[0] == '\0')
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));
if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
*cp = '\0';
havesearch = 0;
continue;
}
/* lookup types */
if (MATCH(buf, "lookup")) {
char *sp = NULL;
memset(_res.lookups, 0, sizeof _res.lookups);
cp = buf + sizeof("lookup") - 1;
for (n = 0;; cp++) {
if (n == MAXDNSLUS)
break;
if ((*cp == '\0') || (*cp == '\n')) {
if (sp) {
if (*sp=='y' || *sp=='b' || *sp=='f')
_res.lookups[n++] = *sp;
sp = NULL;
}
break;
} else if ((*cp == ' ') || (*cp == '\t') || (*cp == ',')) {
if (sp) {
if (*sp=='y' || *sp=='b' || *sp=='f')
_res.lookups[n++] = *sp;
sp = NULL;
}
} else if (sp == NULL)
sp = cp;
}
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));
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) {
#ifdef INET6
char *q;
struct addrinfo hints, *res;
char pbuf[NI_MAXSERV];
#else
struct in_addr a;
#endif /* INET6 */
cp = buf + sizeof("nameserver") - 1;
while (*cp == ' ' || *cp == '\t')
cp++;
#ifdef INET6
if ((*cp == '\0') || (*cp == '\n'))
continue;
for (q = cp; *q; q++) {
if (isspace(*q)) {
*q = '\0';
break;
}
}
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_NUMERICHOST;
hints.ai_socktype = SOCK_DGRAM;
snprintf(pbuf, sizeof(pbuf), "%d", NAMESERVER_PORT);
res = NULL;
if (getaddrinfo(cp, pbuf, &hints, &res) == 0 &&
res->ai_next == NULL) {
if (res->ai_addrlen <= sizeof(_res_ext.nsaddr_list[nserv])) {
memcpy(&_res_ext.nsaddr_list[nserv], res->ai_addr,
res->ai_addrlen);
} else {
memset(&_res_ext.nsaddr_list[nserv], 0,
sizeof(_res_ext.nsaddr_list[nserv]));
}
if (res->ai_addrlen <= sizeof(_res.nsaddr_list[nserv])) {
memcpy(&_res.nsaddr_list[nserv], res->ai_addr,
res->ai_addrlen);
} else {
memset(&_res.nsaddr_list[nserv], 0,
sizeof(_res.nsaddr_list[nserv]));
}
nserv++;
}
if (res)
freeaddrinfo(res);
#else /* INET6 */
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);
_res.nsaddr_list[nserv].sin_len = sizeof(struct sockaddr_in);
nserv++;
}
#endif /* INET6 */
continue;
}
#ifdef RESOLVSORT
if (MATCH(buf, "sortlist")) {
struct in_addr a;
#ifdef INET6
struct in6_addr a6;
int m, i;
u_char *u;
#endif /* INET6 */
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++ = 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);
}
#ifdef INET6
_res_ext.sort_list[nsort].af = AF_INET;
_res_ext.sort_list[nsort].addr.ina =
_res.sort_list[nsort].addr;
_res_ext.sort_list[nsort].mask.ina.s_addr =
_res.sort_list[nsort].mask;
#endif /* INET6 */
nsort++;
}
#ifdef INET6
else if (inet_pton(AF_INET6, net, &a6) == 1) {
_res_ext.sort_list[nsort].af = AF_INET6;
_res_ext.sort_list[nsort].addr.in6a = a6;
u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a;
*cp++ = n;
net = cp;
while (*cp && *cp != ';' &&
isascii(*cp) && !isspace(*cp))
cp++;
m = n;
n = *cp;
*cp = 0;
switch (m) {
case '/':
m = atoi(net);
break;
case '&':
if (inet_pton(AF_INET6, net, u) == 1) {
m = -1;
break;
}
/*FALLTHRU*/
default:
m = sizeof(struct in6_addr) * NBBY;
break;
}
if (m >= 0) {
for (i = 0; i < sizeof(struct in6_addr); i++) {
if (m <= 0) {
*u = 0;
} else {
m -= NBBY;
*u = (u_char)~0;
if (m < 0)
*u <<= -m;
}
u++;
}
}
nsort++;
}
#endif /* INET6 */
*cp = 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)
{
strncpy(_res.defdname, cp + 1,
sizeof(_res.defdname));
}
/* 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 /* DEBUG */
#endif /* !RFC1535 */
}
// if (issetugid())
// _res.options |= RES_NOALIASES;
// else
if ((cp = getenv("RES_OPTIONS")) != NULL)
res_setoptions(cp, "env");
_res.options |= RES_INIT;
return (0);
}
/* ARGSUSED */
static void
res_setoptions(options, source)
char *options, *source;
{
char *cp = options;
char *endp;
long l;
#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)) {
char *p = cp + sizeof("ndots:") - 1;
l = strtol(p, &endp, 10);
if (l >= 0 && endp != p &&
(*endp = '\0' || isspace(*endp))) {
if (l <= RES_MAXNDOTS)
_res.ndots = l;
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, "insecure1", sizeof("insecure1") - 1)) {
_res.options |= RES_INSECURE1;
} else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) {
_res.options |= RES_INSECURE2;
} else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
_res.options |= RES_USE_EDNS0;
} 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 uint32 net_mask(struct in_addr in) /* XXX - should really use system's version of this */
{
register uint32 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

View File

@ -1,232 +0,0 @@
/*
* ++Copyright++ 1985, 1993
* -
* Copyright (c) 1985, 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--
*/
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <stdio.h>
#include <netdb.h>
#include <resolv.h>
#include <string.h>
/*
* Form all types of queries.
* Returns the size of the result or -1.
*/
/* ARGSUSED */
int
res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
int op; /* opcode of query */
const char *dname; /* domain name */
int class, type; /* class and 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.
*
* A special random number generator is used to create non predictable
* and non repeating ids over a long period. It also avoids reuse
* by switching between two distinct number cycles.
*/
if ((buf == NULL) || (buflen < HFIXEDSZ))
return (-1);
memset(buf, 0, HFIXEDSZ);
hp = (HEADER *) buf;
_res.id = res_randomid();
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(type, cp);
cp += INT16SZ;
__putshort(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(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(type, cp);
cp += INT16SZ;
__putshort(class, cp);
cp += INT16SZ;
__putlong(0, cp);
cp += INT32SZ;
__putshort(datalen, cp);
cp += INT16SZ;
if (datalen) {
memcpy(cp, data, datalen);
cp += datalen;
}
hp->ancount = htons(1);
break;
default:
return (-1);
}
return (cp - buf);
}
/* attach OPT pseudo-RR, as documented in RFC2671 (EDNS0). */
int
res_opt(n0, buf, buflen, anslen)
int n0;
u_char *buf; /* buffer to put query */
int buflen; /* size of buffer */
int anslen; /* answer buffer length */
{
register HEADER *hp;
register u_char *cp;
hp = (HEADER *) buf;
cp = buf + n0;
buflen -= n0;
if (buflen < 1 + RRFIXEDSZ)
return -1;
*cp++ = 0; /* "." */
buflen--;
__putshort(T_OPT, cp); /* TYPE */
cp += INT16SZ;
__putshort(anslen & 0xffff, cp); /* CLASS = UDP payload size */
cp += INT16SZ;
*cp++ = NOERROR; /* extended RCODE */
*cp++ = 0; /* EDNS version */
if (_res.options & RES_USE_DNSSEC) {
#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf(";; res_opt()... ENDS0 DNSSEC OK\n");
#endif /* DEBUG */
__putshort(DNS_MESSAGEEXTFLAG_DO, cp); /* EDNS Z field */
cp += INT16SZ;
} else {
__putshort(0, cp); /* EDNS Z field */
cp += INT16SZ;
}
__putshort(0, cp); /* RDLEN */
cp += INT16SZ;
hp->arcount = htons(ntohs(hp->arcount) + 1);
buflen -= RRFIXEDSZ;
return cp - buf;
}

View File

@ -1,396 +0,0 @@
/*
* ++Copyright++ 1988, 1993
* -
* Copyright (c) 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--
*/
#include <sys/types.h>
#include <sys/param.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 <stdlib.h>
#include <string.h>
#include <unistd.h>
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
#define MAXPACKET 1024
#endif
const char *hostalias (const char *);
extern int res_opt (int, u_char *, int, int);
/*
* 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(name, class, type, answer, anslen)
const char *name; /* domain name */
int class, type; /* class and type of query */
u_char *answer; /* buffer to put answer */
int anslen; /* size of answer buffer */
{
u_char buf[MAXPACKET];
register 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 && ((_res.options & RES_USE_EDNS0) ||
(_res.options & RES_USE_DNSSEC))) {
n = res_opt(n, buf, sizeof(buf), anslen);
}
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(name, class, type, answer, anslen)
const char *name; /* domain name */
int class, type; /* class and type of query */
u_char *answer; /* buffer to put answer */
int anslen; /* size of answer */
{
register 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.
*/
if (!tried_as_is) {
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(name, domain, class, type, answer, anslen)
const char *name, *domain;
int class, type; /* class and type of query */
u_char *answer; /* buffer to put answer */
int anslen; /* size of answer */
{
char nbuf[MAXDNAME*2+1+1];
const char *longname = nbuf;
int n;
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 = strlen(name) - 1;
if (n != (0 - 1) && name[n] == '.' && n < sizeof(nbuf) - 1) {
memcpy(nbuf, name, n);
nbuf[n] = '\0';
} else
longname = name;
} else
sprintf(nbuf, "%.*s.%.*s", MAXDNAME, name, MAXDNAME, domain);
return (res_query(longname, class, type, answer, anslen));
}
const char *
hostalias(name)
register const char *name;
{
register char *cp1, *cp2;
FILE *fp;
char *file;
char buf[BUFSIZ];
static char abuf[MAXDNAME];
size_t len;
if (_res.options & RES_NOALIASES)
return (NULL);
file = getenv("HOSTALIASES");
// if (issetugid() != 0 || file == NULL || (fp = fopen(file, "r")) == NULL)
if (file == NULL || (fp = fopen(file, "r")) == NULL)
return (NULL);
setbuf(fp, NULL);
while ((cp1 = fgets(buf, sizeof(buf), fp)) != NULL) {
// while ((cp1 = fgetln(fp, &len)) != NULL) {
len = strlen(buf);
if (cp1[len-1] == '\n')
len--;
// if (len >= sizeof(buf) || len == 0)
// continue;
// (void)memcpy(buf, cp1, len);
buf[len] = '\0';
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)
;
*cp2 = '\0';
strncpy(abuf, cp1, sizeof(abuf));
fclose(fp);
return (abuf);
}
}
fclose(fp);
return (NULL);
}

View File

@ -1,238 +0,0 @@
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
* All rights reserved.
*
* Theo de Raadt <deraadt@openbsd.org> came up with the idea of using
* such a mathematical system to generate more random (yet non-repeating)
* ids to solve the resolver/named problem. But Niels designed the
* actual system based on the constraints.
*
* 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 Niels Provos.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
*/
/*
* seed = random 15bit
* n = prime, g0 = generator to n,
* j = random so that gcd(j,n-1) == 1
* g = g0^j mod n will be a generator again.
*
* X[0] = random seed.
* X[n] = a*X[n-1]+b mod m is a Linear Congruential Generator
* with a = 7^(even random) mod m,
* b = random with gcd(b,m) == 1
* m = 31104 and a maximal period of m-1.
*
* The transaction id is determined by:
* id[n] = seed xor (g^X[n] mod n)
*
* Effectivly the id is restricted to the lower 15 bits, thus
* yielding two different cycles by toggling the msb on and off.
* This avoids reuse issues caused by reseeding.
*
* The 16 bit space is very small and brute force attempts are
* entirly feasible, we skip a random number of transaction ids
* so that an attacker will not get sequential ids.
*/
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/time.h>
#include <resolv.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
/* arc4random is defined in stdlib.h on OpenBSD, so we'll just forward
* declare the prototype here to stop the compiler moaning.
*/
uint32 arc4random(void);
#define RU_OUT 180 /* Time after wich will be reseeded */
#define RU_MAX 30000 /* Uniq cycle, avoid blackjack prediction */
#define RU_GEN 2 /* Starting generator */
#define RU_N 32749 /* RU_N-1 = 2*2*3*2729 */
#define RU_AGEN 7 /* determine ru_a as RU_AGEN^(2*rand) */
#define RU_M 31104 /* RU_M = 2^7*3^5 - don't change */
#define PFAC_N 3
const static uint16 pfacts[PFAC_N] = {
2,
3,
2729
};
static uint16 ru_x;
static uint16 ru_seed, ru_seed2;
static uint16 ru_a, ru_b;
static uint16 ru_g;
static uint16 ru_counter = 0;
static uint16 ru_msb = 0;
static long ru_reseed;
static uint32 tmp; /* Storage for unused random */
static struct timeval tv;
static uint16 pmod (uint16, uint16, uint16);
static void res_initid (void);
/*
* Do a fast modular exponation, returned value will be in the range
* of 0 - (mod-1)
*/
#ifdef __STDC__
static uint16
pmod(uint16 gen, uint16 exp, uint16 mod)
#else
static uint16
pmod(gen, exp, mod)
uint16 gen, exp, mod;
#endif
{
uint16 s, t, u;
s = 1;
t = gen;
u = exp;
while (u) {
if (u & 1)
s = (s*t) % mod;
u >>= 1;
t = (t*t) % mod;
}
return (s);
}
/*
* Initializes the seed and chooses a suitable generator. Also toggles
* the msb flag. The msb flag is used to generate two distinct
* cycles of random numbers and thus avoiding reuse of ids.
*
* This function is called from res_randomid() when needed, an
* application does not have to worry about it.
*/
static void
res_initid()
{
uint16 j, i;
int noprime = 1;
tmp = arc4random();
ru_x = (tmp & 0xFFFF) % RU_M;
/* 15 bits of random seed */
ru_seed = (tmp >> 16) & 0x7FFF;
tmp = arc4random();
ru_seed2 = tmp & 0x7FFF;
tmp = arc4random();
/* Determine the LCG we use */
ru_b = (tmp & 0xfffe) | 1;
ru_a = pmod(RU_AGEN, (tmp >> 16) & 0xfffe, RU_M);
while (ru_b % 3 == 0)
ru_b += 2;
tmp = arc4random();
j = tmp % RU_N;
tmp = tmp >> 16;
/*
* Do a fast gcd(j,RU_N-1), so we can find a j with
* gcd(j, RU_N-1) == 1, giving a new generator for
* RU_GEN^j mod RU_N
*/
while (noprime) {
for (i=0; i<PFAC_N; i++)
if (j%pfacts[i] == 0)
break;
if (i>=PFAC_N)
noprime = 0;
else
j = (j+1) % RU_N;
}
ru_g = pmod(RU_GEN,j,RU_N);
ru_counter = 0;
gettimeofday(&tv, NULL);
ru_reseed = tv.tv_sec + RU_OUT;
ru_msb = ru_msb == 0x8000 ? 0 : 0x8000;
}
u_int
res_randomid()
{
int i, n;
gettimeofday(&tv, NULL);
if (ru_counter >= RU_MAX || tv.tv_sec > ru_reseed)
res_initid();
if (!tmp)
tmp = arc4random();
/* Skip a random number of ids */
n = tmp & 0x7; tmp = tmp >> 3;
if (ru_counter + n >= RU_MAX)
res_initid();
for (i=0; i<=n; i++)
/* Linear Congruential Generator */
ru_x = (ru_a*ru_x + ru_b) % RU_M;
ru_counter += i;
return (ru_seed ^ pmod(ru_g,ru_seed2 ^ ru_x,RU_N)) | ru_msb;
}
#if 0
void
main(int argc, char **argv)
{
int i, n;
uint16 wert;
res_initid();
printf("Generator: %d\n", ru_g);
printf("Seed: %d\n", ru_seed);
printf("Reseed at %ld\n", ru_reseed);
printf("Ru_X: %d\n", ru_x);
printf("Ru_A: %d\n", ru_a);
printf("Ru_B: %d\n", ru_b);
n = atoi(argv[1]);
for (i=0;i<n;i++) {
wert = res_randomid();
printf("%06d\n", wert);
}
}
#endif

View File

@ -1,883 +0,0 @@
/*
* ++Copyright++ 1985, 1989, 1993
* -
* Copyright (c) 1985, 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) 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--
*/
/* change this to "0"
* if you talk to a lot
* of multi-homed SunOS
* ("broken") name servers.
*/
#define CHECK_SRVR_ADDR 1 /* XXX - should be in options.h */
/*
* Send query to name server and wait for reply.
*/
#include <sys/types.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <stdio.h>
#include <netdb.h>
#include <errno.h>
#include <resolv.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
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 ciruit? */
static int af = 0; /* address family of socket */
#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 char abuf[NI_MAXHOST];
static char pbuf[NI_MAXSERV];
static void Aerror (FILE *, char *, int, struct sockaddr *);
static void Perror (FILE *, char *, int);
static void
Aerror(file, string, error, address)
FILE *file;
char *string;
int error;
struct sockaddr *address;
{
int save = errno;
if (_res.options & RES_DEBUG) {
if (getnameinfo(address, address->sa_len, abuf, sizeof(abuf),
pbuf, sizeof(pbuf),
NI_NUMERICHOST|NI_NUMERICSERV|NI_WITHSCOPEID) != 0) {
strncpy(abuf, "?", sizeof(abuf));
strncpy(pbuf, "?", sizeof(pbuf));
}
fprintf(file, "res_send: %s ([%s].%s): %s\n",
string, abuf, pbuf, strerror(error));
}
errno = save;
}
static void
Perror(file, string, error)
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
static res_send_qhook Qhook = NULL;
static res_send_rhook Rhook = NULL;
void
res_send_setqhook(hook)
res_send_qhook hook;
{
Qhook = hook;
}
void
res_send_setrhook(hook)
res_send_rhook hook;
{
Rhook = hook;
}
#ifdef INET6
static struct sockaddr * get_nsaddr (size_t);
/*
* pick appropriate nsaddr_list for use. see res_init() for initialization.
*/
static struct sockaddr *
get_nsaddr(n)
size_t n;
{
if (!_res.nsaddr_list[n].sin_family) {
/*
* - _res_ext.nsaddr_list[n] holds an address that is larger
* than struct sockaddr, and
* - user code did not update _res.nsaddr_list[n].
*/
return (struct sockaddr *)&_res_ext.nsaddr_list[n];
} else {
/*
* - user code updated _res.nsaddr_list[n], or
* - _res.nsaddr_list[n] has the same content as
* _res_ext.nsaddr_list[n].
*/
return (struct sockaddr *)&_res.nsaddr_list[n];
}
}
#else
#define get_nsaddr(n) ((struct sockaddr *)&_res.nsaddr_list[(n)])
#endif
/* 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(inp)
const struct sockaddr_in *inp;
{
#ifdef INET6
const struct sockaddr_in6 *in6p = (const struct sockaddr_in6 *)inp;
const struct sockaddr_in6 *srv6;
#endif
const struct sockaddr_in *srv;
int ns, ret;
ret = 0;
/* XXX - debug code to see why we fail in this routine! */
printf("inp->sin_family = %d (AF_INET = %d)\n",
inp->sin_family, AF_INET);
switch (inp->sin_family) {
#ifdef INET6
case AF_INET6:
for (ns = 0; ns < _res.nscount; ns++) {
srv6 = (struct sockaddr_in6 *)get_nsaddr(ns);
if (srv6->sin6_family == in6p->sin6_family &&
srv6->sin6_port == in6p->sin6_port &&
srv6->sin6_scope_id == in6p->sin6_scope_id &&
(IN6_IS_ADDR_UNSPECIFIED(&srv6->sin6_addr) ||
IN6_ARE_ADDR_EQUAL(&srv6->sin6_addr,
&in6p->sin6_addr))) {
ret++;
break;
}
}
break;
#endif
case AF_INET:
for (ns = 0; ns < _res.nscount; ns++) {
srv = (struct sockaddr_in *)get_nsaddr(ns);
if (srv->sin_family == inp->sin_family &&
srv->sin_port == inp->sin_port &&
(srv->sin_addr.s_addr == INADDR_ANY ||
srv->sin_addr.s_addr == inp->sin_addr.s_addr)) {
ret++;
break;
}
}
break;
}
return (ret);
}
/* int
* res_nameinquery(name, type, class, buf, eom)
* look for (name,type,class) in the query section of packet (buf,eom)
* returns:
* -1 : format error
* 0 : not found
* >0 : found
* author:
* paul vixie, 29may94
*/
int
res_nameinquery(name, type, class, buf, eom)
const char *name;
register int type, class;
const u_char *buf, *eom;
{
register const u_char *cp = buf + HFIXEDSZ;
int qdcount = ntohs(((HEADER*)buf)->qdcount);
while (qdcount-- > 0) {
char tname[MAXDNAME+1];
register int n, ttype, tclass;
n = dn_expand(buf, eom, cp, tname, sizeof tname);
if (n < 0)
return (-1);
cp += n;
ttype = _getshort(cp); cp += INT16SZ;
tclass = _getshort(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(buf1, eom1, buf2, eom2)
const u_char *buf1, *eom1;
const u_char *buf2, *eom2;
{
register const u_char *cp = buf1 + HFIXEDSZ;
int qdcount = ntohs(((HEADER*)buf1)->qdcount);
if (qdcount != ntohs(((HEADER*)buf2)->qdcount))
return (0);
while (qdcount-- > 0) {
char tname[MAXDNAME+1];
register int n, ttype, tclass;
n = dn_expand(buf1, eom1, cp, tname, sizeof tname);
if (n < 0)
return (-1);
cp += n;
ttype = _getshort(cp); cp += INT16SZ;
tclass = _getshort(cp); cp += INT16SZ;
if (!res_nameinquery(tname, ttype, tclass, buf2, eom2))
return (0);
}
return (1);
}
int
res_send(buf, buflen, ans, anssiz)
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;
register int n;
u_int badns; /* XXX NSMAX can't exceed #/bits in this var */
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
/* errno should have been set by res_init() in this case. */
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 *nsap = get_nsaddr(ns);
uint32 salen;
if (nsap->sa_len)
salen = nsap->sa_len;
#ifdef INET6
else if (nsap->sa_family == AF_INET6)
salen = sizeof(struct sockaddr_in6);
#endif
else if (nsap->sa_family == AF_INET)
salen = sizeof(struct sockaddr_in);
else
salen = 0; /*unknown, die on connect*/
same_ns:
if (badns & (1 << ns)) {
res_close();
goto next_ns;
}
if (Qhook) {
int done = 0, loops = 0;
do {
res_sendhookact act;
act = (*Qhook)((struct sockaddr_in **)&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) &&
getnameinfo(nsap, salen, abuf, sizeof(abuf),
NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) == 0,
(stdout, ";; Querying server (# %d) address = %s\n",
ns + 1, abuf));
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) || (af != nsap->sa_family)) {
if (s >= 0)
res_close();
af = nsap->sa_family;
s = socket(af, SOCK_STREAM, 0);
if (s < 0) {
terrno = errno;
Perror(stderr, "socket(vc)", errno);
#if 0
return (-1);
#else
badns |= (1 << ns);
res_close();
goto next_ns;
#endif
}
errno = 0;
if (connect(s, nsap, salen) < 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;
if ((len -= n) <= 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 = _getshort(ans);
if (resplen > anssiz) {
Dprint(_res.options & RES_DEBUG,
(stdout, ";; response truncated\n")
);
truncated = 1;
len = anssiz;
} else
len = resplen;
cp = ans;
while (len != 0 &&
(n = read(s, (char *)cp, (int)len)) > 0) {
cp += n;
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 = resplen - anssiz;
while (len != 0) {
char junk[PACKETSZ];
n = (len > sizeof(junk)
? sizeof(junk)
: len);
if ((n = read(s, junk, n)) > 0)
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.
*/
struct timeval timeout;
fd_set *dsmaskp;
struct sockaddr_storage from;
int fromlen;
if ((s < 0) || vc || (af != nsap->sa_family)) {
if (vc)
res_close();
af = nsap->sa_family;
s = socket(af, SOCK_DGRAM, 0);
if (s < 0) {
#if !CAN_RECONNECT
bad_dg_sock:
#endif
terrno = errno;
Perror(stderr, "socket(dg)", errno);
#if 0
return (-1);
#else
badns |= (1 << ns);
res_close();
goto next_ns;
#endif
}
#ifdef IPV6_MINMTU
if (af == AF_INET6) {
const int yes = 1;
(void)setsockopt(s, IPPROTO_IPV6,
IPV6_USE_MIN_MTU, &yes,
sizeof(yes));
}
#endif
connected = 0;
}
/*
* 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.options & RES_INSECURE1) &&
(_res.nscount == 1 || (try == 0 && ns == 0))) {
/*
* Connect only if we are sure we won't
* receive a response from another server.
*/
if (!connected) {
if (connect(s, nsap, salen) < 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) {
#if CAN_RECONNECT
#ifdef INET6
/* XXX: any errornous address */
#endif /* INET6 */
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(af, 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
#ifdef IPV6_MINMTU
if (af == AF_INET6) {
const int yes = 1;
(void)setsockopt(s, IPPROTO_IPV6,
IPV6_USE_MIN_MTU, &yes,
sizeof(yes));
}
#endif
connected = 0;
errno = 0;
}
if (sendto(s, (char*)buf, buflen, 0,
nsap, salen) != buflen) {
Aerror(stderr, "sendto", errno, nsap);
badns |= (1 << ns);
res_close();
goto next_ns;
}
}
/*
* Wait for reply
*/
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;
wait:
dsmaskp = (fd_set *)malloc(sizeof(fd_set));
memset((void*)dsmaskp, 0, sizeof(fd_set));
if (dsmaskp == NULL) {
res_close();
goto next_ns;
}
FD_SET(s, dsmaskp);
n = select(s+1, dsmaskp, (fd_set *)NULL,
(fd_set *)NULL, &timeout);
free(dsmaskp);
if (n < 0) {
if (errno == EINTR)
goto wait;
Perror(stderr, "select", errno);
res_close();
goto next_ns;
}
if (n == 0) {
/*
* timeout
*/
Dprint(_res.options & RES_DEBUG,
(stdout, ";; timeout\n"));
gotsomewhere = 1;
res_close();
goto next_ns;
}
errno = 0;
fromlen = sizeof(from);
resplen = 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 (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;
}
/* XXX - We should really be using this section of code, but on my server
* this causes the name lookup to fail as the sin_family returned is 0, and
* thus we fail the res_isourserver check. Not sure if this is specific
* to my server or it's setup, but it's annoying.
* Can other people remove the comment and see if this works for them?
*/
#if 0//CHECK_SRVR_ADDR
if (!(_res.options & RES_INSECURE1) &&
!res_isourserver((struct sockaddr_in *)&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, "%s", ""),
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)((struct sockaddr_in *)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;
af = 0;
}
}

View File

@ -1,15 +0,0 @@
# resolv.conf for Haiku
#
# We lookup in the /etc/hosts file first, then we do a bind lookup
lookup file bind
# if you're having trouble, uncomment the next line
#options debug
# Our local domain
# domain home.net
# List of nameservers as IP addresses
# These are searched in order
nameserver 192.168.0.1

View File

@ -1,180 +0,0 @@
#include <unistd.h>
#include <image.h>
#include <OS.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>
#include <errno.h>
#include "net_stack_driver.h"
#ifndef BONE_VERSION
static int fd_set_count(fd_set * bits, int nbits)
{
int count;
int fd;
count = 0;
for (fd = 0; fd < nbits; fd++)
if (FD_ISSET(fd, bits))
count++;
return count;
}
_EXPORT int select(int nbits, struct fd_set * rbits,
struct fd_set * wbits,
struct fd_set * ebits,
struct timeval * tv)
{
int fd;
int n;
struct stack_driver_args args;
status_t status;
area_id area;
struct r5_selectsync * rss;
#define ROUND_TO_PAGE_SIZE(x) (((x) + (B_PAGE_SIZE) - 1) & ~((B_PAGE_SIZE) - 1))
// We share a area with the fd_set on it with the network stack code.
// The r5_notify_select_event in the net_stack_driver code will fill it and wakeup us
// when a event raise.
area = create_area("r5_selectsync", (void **) &rss,
B_ANY_ADDRESS, ROUND_TO_PAGE_SIZE(sizeof(*rss)), B_NO_LOCK,
B_READ_AREA | B_WRITE_AREA);
if (area < B_OK) {
errno = area;
return -1;
};
// The area is multi-thread protected by a semaphore locker
rss->lock = create_sem(1, "r5_selectsync_lock");
if (rss->lock < B_OK) {
errno = rss->lock;
rss->wakeup = 0;
n = -1;
goto error;
};
// Create the wakeup call semaphore
rss->wakeup = create_sem(0, "r5_selectsync_wakeup");
if (rss->wakeup < B_OK) {
errno = rss->wakeup;
n = -1;
goto error;
};
FD_ZERO(&rss->rbits);
FD_ZERO(&rss->wbits);
FD_ZERO(&rss->ebits);
/* Beware, ugly hacky hack: we pass the area_id of our shared r5_selectsync,
that net_stack_driver should udate directly
*/
args.u.select.sync = (struct selectsync *) area;
/* call, indirectly, net_stack_select() for each event to monitor
* as we are not the vfs, we can't call this device hook ourself, but
* our NET_STACK_SELECT opcode would do it for us...
*/
n = 0;
for (fd = 0; fd < nbits; fd++) {
if (rbits && FD_ISSET(fd, rbits)) {
args.u.select.ref = (fd << 8) | 1;
if (ioctl(fd, NET_STACK_SELECT, &args, sizeof(args)) >= 0)
n++;
};
if (wbits && FD_ISSET(fd, wbits)) {
args.u.select.ref = (fd << 8) | 2;
if (ioctl(fd, NET_STACK_SELECT, &args, sizeof(args)) >= 0)
n++;
};
if (ebits && FD_ISSET(fd, ebits)) {
args.u.select.ref = (fd << 8) | 3;
if (ioctl(fd, NET_STACK_SELECT, &args, sizeof(args)) >= 0)
n++;
};
}
if (n < 1) {
// TODO: maybe we could hack a workaround for select() on file/dev here:
// If no fd handle the NET_STACK_SELECT, assume they're files, so always
// readable and writable?
errno = B_BAD_VALUE;
n = -1;
goto error;
};
// Okay, now wait for our wakeup call.
// Maybe his's already there, even... (when the select event is already raised)
if (tv) {
bigtime_t timeout;
timeout = tv->tv_sec * 1000000LL + tv->tv_usec;
status = acquire_sem_etc(rss->wakeup, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, timeout);
} else
status = acquire_sem(rss->wakeup);
// we don't need it anymore, and we say "select() party is over" that way, too :-)
delete_sem(rss->lock);
delete_sem(rss->wakeup);
rss->lock = rss->wakeup = -1;
// unregister socket event notification
for(fd = 0; fd < nbits; fd++) {
if (rbits && FD_ISSET(fd, rbits)) {
args.u.select.ref = (fd << 8) | 1;
ioctl(fd, NET_STACK_DESELECT, &args, sizeof(args));
};
if (wbits && FD_ISSET(fd, wbits)) {
args.u.select.ref = (fd << 8) | 2;
ioctl(fd, NET_STACK_DESELECT, &args, sizeof(args));
};
if (ebits && FD_ISSET(fd, ebits)) {
args.u.select.ref = (fd << 8) | 3;
ioctl(fd, NET_STACK_DESELECT, &args, sizeof(args));
};
};
// Okay, what the final result?
switch (status) {
case B_OK:
case B_WOULD_BLOCK:
case B_TIMED_OUT: // logicly, 'n' should stay to 0 in this case...
n = 0;
// IMPORTANT: memcpy uses the old R5 fd_bits size (sizeof(unsigned) * 8)!
if (rbits) {
memcpy(rbits, &rss->rbits, sizeof(unsigned) * 8);
n += fd_set_count(rbits, nbits);
};
if (wbits) {
memcpy(wbits, &rss->wbits, sizeof(unsigned) * 8);
n += fd_set_count(wbits, nbits);
};
if (ebits) {
memcpy(ebits, &rss->ebits, sizeof(unsigned) * 8);
n += fd_set_count(ebits, nbits);
};
break;
default:
errno = status;
n = -1;
break;
};
error:
if (rss->lock >= 0)
delete_sem(rss->lock);
if (rss->wakeup >= 0)
delete_sem(rss->wakeup);
delete_area(area);
return n;
}
#endif // !BONE_VERSION

View File

@ -1,260 +0,0 @@
# 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, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1340, ``Assigned Numbers'' (July 1992). Not all ports
# are included, only the more common ones.
#
# from: @(#)services 5.8 (Berkeley) 5/9/91
#
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 # message send protocol
chargen 19/tcp ttytst source
chargen 19/udp ttytst source
ftp-data 20/tcp # default ftp data port
ftp 21/tcp
ssh 22/tcp
ssh 22/udp
telnet 23/tcp
# 24 - private
smtp 25/tcp mail
# 26 - unassigned
time 37/tcp timserver
time 37/udp timserver
rlp 39/udp resource # resource location
nameserver 42/tcp name # IEN 116
whois 43/tcp nicname
domain 53/tcp nameserver # name-domain server
domain 53/udp nameserver
mtp 57/tcp # deprecated
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/udp kerberos-sec # Kerberos 5 UDP
kerberos 88/tcp kerberos-sec # Kerberos 5 TCP
supdup 95/tcp
# 100 - reserved
hostnames 101/tcp hostname # usually from sri-nic
iso-tsap 102/tcp tsap # part of ISODE.
x400 103/tcp # ISO E-mail
x400-snd 104/tcp
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 version 2
pop2 109/udp
pop3 110/tcp # POP version 3
pop3 110/udp
sunrpc 111/tcp portmap rpcbind
sunrpc 111/udp portmap rpcbind
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
epmap 135/tcp # DCE endpoint resolution
epmap 135/udp
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
imap 143/tcp imap2 # Internet Message Access Proto
imap 143/udp imap2 # Internet Message Access Proto
bftp 152/tcp # Background File Transfer Proto
snmp 161/udp # Simple Net Mgmt Proto
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
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 Proto.
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
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
ulistserv 372/tcp # UNIX Listserv
ulistserv 372/udp
svrloc 427/tcp # Server Location
svrloc 427/udp
nnsp 433/tcp usenet # Network News Transfer
https 443/tcp # secure http (SSL)
kpasswd 464/udp # Kerberos 5 password changing
kpasswd 464/tcp # Kerberos 5 password changing
photuris 468/tcp # Photuris Key Management
photuris 468/udp
isakmp 500/udp # ISAKMP key management
kshell 544/tcp krcmd # Kerberos remote shell
ekshell 545/tcp # Kerberos encrypted shell
submission 587/tcp msa # mail message submission
submission 587/udp msa # mail message submission
#
# 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
efs 521/tcp # extended file name server
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
uucp 540/tcp uucpd # uucp daemon
remotefs 556/tcp rfs_server rfs # Brunhoff remote filesystem
kerberos-adm 749/udp # Kerberos 5 kadmin
kerberos-adm 749/tcp # Kerberos 5 kadmin
kerberos-iv 750/udp kdc # Kerberos authentication--udp
kerberos-iv 750/tcp kdc # Kerberos authentication--tcp
kerberos_master 751/udp # Kerberos 4 kadmin
kerberos_master 751/tcp # Kerberos 4 kadmin
krb_prop 754/tcp hprop # Kerberos slave propagation
#
# 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
kpop 1109/tcp # Pop with Kerberos
ingreslock 1524/tcp
ingreslock 1524/udp
prospero-np 1525/tcp # Prospero non-privileged
prospero-np 1525/udp
nfsd 2049/udp nfs # NFS server
nfsd 2049/tcp nfs # NFS server
eklogin 2105/tcp # Kerberos encrypted rlogin
rkinit 2108/tcp # Kerberos remote kinit
kf 2110/tcp # forward credentials
kx 2111/tcp # X over kerberos
kip 2112/tcp # IP over kerberos
kauth 2120/tcp # Remote kauth
krb524 4444/udp # Kerberos 5->4
iprop 2121/tcp # Kerberos incremental propagation
rfe 5002/tcp # Radio Free Ethernet
rfe 5002/udp # Actually uses UDP only
sip 5060/tcp # SIP
sip 5060/udp # SIP
#
#
# Kerberos (Project Athena/MIT) services
# Note that these are for Kerberos v4, and are unofficial. Sites running
# v5 should comment these out and uncomment the v5 entries above.
#
kerberos-sec 88/udp # Kerberos secondary port UDP
kerberos-sec 88/tcp # Kerberos secondary port TCP
klogin 543/tcp # Kerberos authenticated rlogin
kshell 544/tcp krcmd # and remote shell
ekshell 545/tcp # Kerberos encrypted remote shell -kfall
ekshell2 2106/tcp # What U of Colorado @ Boulder uses?
kerberos-adm 749/tcp # Kerberos `kadmin' (v5)
kerberos-iv 750/udp kdc kerberos # Kerberos authentication--udp
kerberos-iv 750/tcp kdc kerberos # Kerberos authentication--tcp
kerberos_master 751/udp kerberos-master # Kerberos authentication
kerberos_master 751/tcp kerberos-master # Kerberos authentication
krb_prop 754/tcp # Kerberos slave propagation
krbupdate 760/tcp kreg # BSD Kerberos registration
kpop 1109/tcp # Pop with Kerberos
eklogin 2105/tcp # Kerberos encrypted rlogin
rkinit 2108/tcp # Kerberos remote kinit
kx 2111/tcp # X over kerberos
kip 2112/tcp # IP over kerberos
kauth 2120/tcp # Remote kauth
#
# AFS Services
#
afs3-fileserver 7000/udp # AFS fileserver
afs3-callback 7001/udp # AFS callback server
afs3-prserver 7002/udp # AFS protection server
afs3-vlserver 7003/udp # AFS volumelocation server
afs3-kaserver 7004/udp # AFS kerberos authentication server
afs3-volser 7005/udp # AFS volume server
afs3-errors 7006/udp # AFS error server ?
afs3-bos 7007/udp # AFS basic over-see server ?
afs3-update 7008/udp # AFS server to server update
afs3-rmtsys 7009/udp # AFS remote cache manager service
#
# Unofficial services
#
supfilesrv 871/tcp # SUP server
rsync 873/tcp # rsync server
cddb 888/tcp # Audio CD Database
supfiledbg 1127/tcp # SUP debugging
datametrics 1645/udp
sa-msg-port 1646/udp
radius 1812/udp # radius authentication
radacct 1813/udp # radius accounting
webster 2627/tcp # Network dictionary
webster 2627/udp
mysql 3306/tcp # MySQL
canna 5680/tcp # Kana->Kanji server
icb 7326/tcp # Internet Citizen's Band
hunt 26740/udp # hunt(6)
#
# Appletalk
#
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

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 1985, 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.
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <resolv.h>
void
sethostent(stayopen)
int stayopen;
{
if ((_res.options & RES_INIT) == 0 && res_init() == -1)
return;
if (stayopen)
_res.options |= RES_STAYOPEN | RES_USEVC;
}
void
endhostent()
{
_res.options &= ~(RES_STAYOPEN | RES_USEVC);
res_close();
}

View File

@ -1,513 +0,0 @@
/* socket.c */
/* This is a very simple little shared library that acts as a wrapper
* for our device/kernel stack!
*/
#include <fcntl.h>
#include <unistd.h>
#include <kernel/OS.h>
#include <iovec.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <netinet/in.h>
#include "net_stack_driver.h"
// Forward declaration of sysctl.h, because it's currently declared under headers/private/kernel/sysctl.h
int sysctl(int *, uint, void *, size_t *, void *, size_t);
static bool g_beos_r5_compatibility = false;
struct beosr5_sockaddr_in {
uint16 sin_family;
uint16 sin_port;
uint32 sin_addr;
char sin_zero[4];
};
static char * stack_driver_path(void);
static void convert_from_beos_r5_sockaddr(struct sockaddr *to, const struct sockaddr *from);
static void convert_to_beos_r5_sockaddr(struct sockaddr *to, const struct sockaddr *from);
static void convert_from_beos_r5_sockopt(int *level, int *optnum);
_EXPORT int socket(int family, int type, int protocol)
{
int sock;
int rv;
struct stack_driver_args args;
sock = open(stack_driver_path(), O_RDWR);
if (sock < 0)
return sock;
/* work around the old Be header values... *
*
* This really sucks...
*
* Basically we've modified the new stack SOCK_ values to be
* start at 10, so if it's below that we're being called by
* an R5 app.
*
* NB
* Of course this places a lot of restrictions on what we can
* do with library replacements and improvements as no other
* component of the "team" can be built using the new
* stack.
*/
if (type < SOCK_DGRAM) {
g_beos_r5_compatibility = true;
/* we have old be types... convert... */
if (type == 1)
type = SOCK_NATIVE_DGRAM;
else if (type == 2)
type = SOCK_NATIVE_STREAM;
if (protocol == 1)
protocol = IPPROTO_UDP;
else if (protocol == 2)
protocol = IPPROTO_TCP;
else if (protocol == 3)
protocol = IPPROTO_ICMP;
/* also convert AF_INET */
if (family == 1)
family = AF_INET;
} else if (type == SOCK_DGRAM)
type = SOCK_NATIVE_DGRAM;
else if (type == SOCK_STREAM)
type = SOCK_NATIVE_STREAM;
args.u.socket.family = family;
args.u.socket.type = type;
args.u.socket.proto = protocol;
rv = ioctl(sock, NET_STACK_SOCKET, &args, sizeof(args));
if (rv < 0) {
close(sock);
return rv;
};
return sock;
}
_EXPORT int bind(int sock, const struct sockaddr *addr, int addrlen)
{
struct sockaddr temp;
struct stack_driver_args args;
if (g_beos_r5_compatibility) {
convert_from_beos_r5_sockaddr(&temp, addr);
addr = &temp;
addrlen = sizeof(struct sockaddr_in);
}
args.u.sockaddr.addr = (struct sockaddr *) addr;
args.u.sockaddr.addrlen = addrlen;
return ioctl(sock, NET_STACK_BIND, &args, sizeof(args));
}
_EXPORT int shutdown(int sock, int how)
{
struct stack_driver_args args;
// make it compatible to our stack (our values are one below)
--how;
args.u.integer = how;
return ioctl(sock, NET_STACK_SHUTDOWN, &args, sizeof(args));
}
_EXPORT int connect(int sock, const struct sockaddr *addr, int addrlen)
{
struct sockaddr temp;
struct stack_driver_args args;
// XXX: HACK! FIXME!
// Our DNS resolver uses the new stack codes, but old apps set R5 compatibility.
// So, resolving an address AFTER the app opens a socket fails because
// connect() thinks we are in compatibility mode and thus translates the
// new style address family into the old style (and sockaddr format).
// So, we check if the address family is our AF_INET (might indicate that we
// are using the new stack mixed with the old one.
// We can to solve this problem by making R5 compatibility socket-specific.
// This would need a new ioctl() for retrieving the socket mode.
if (g_beos_r5_compatibility && addr->sa_family != AF_INET) {
convert_from_beos_r5_sockaddr(&temp, addr);
addr = &temp;
addrlen = sizeof(struct sockaddr_in);
}
args.u.sockaddr.addr = (struct sockaddr *) addr;
args.u.sockaddr.addrlen = addrlen;
return ioctl(sock, NET_STACK_CONNECT, &args, sizeof(args));
}
_EXPORT int listen(int sock, int backlog)
{
struct stack_driver_args args;
args.u.integer = backlog;
return ioctl(sock, NET_STACK_LISTEN, &args, sizeof(args));
}
_EXPORT int accept(int sock, struct sockaddr *addr, int *addrlen)
{
struct sockaddr temp;
struct stack_driver_args args;
int rv;
int new_sock;
void *cookie;
new_sock = open(stack_driver_path(), O_RDWR);
if (new_sock < 0)
return new_sock;
// The network stack driver will need to know to which net_stack_cookie to
// *bind* with the new accepted socket. He can't know himself find out
// the net_stack_cookie of our new_sock file descriptor, the just open() one...
// So, here, we ask him the net_stack_cookie value for our fd... :-)
rv = ioctl(new_sock, NET_STACK_GET_COOKIE, &cookie);
if (rv < 0) {
close(new_sock);
return rv;
};
args.u.accept.cookie = cookie; // this way driver can use the right fd/cookie for the new_sock!
args.u.accept.addr = g_beos_r5_compatibility ? &temp : addr;
args.u.accept.addrlen = g_beos_r5_compatibility ? sizeof(temp) : *addrlen;
rv = ioctl(sock, NET_STACK_ACCEPT, &args, sizeof(args));
if (rv < 0) {
close(new_sock);
return rv;
};
if (g_beos_r5_compatibility) {
convert_to_beos_r5_sockaddr(addr, &temp);
*addrlen = sizeof(struct beosr5_sockaddr_in);
} else
*addrlen = args.u.accept.addrlen;
return new_sock;
}
_EXPORT ssize_t recvfrom(int sock, void *buffer, size_t buflen, int flags,
struct sockaddr *addr, int *addrlen)
{
struct sockaddr temp;
struct msghdr mh;
struct iovec iov;
int rv;
/* XXX - would this be better done as scatter gather? */
mh.msg_name = g_beos_r5_compatibility ? (caddr_t)&temp : (caddr_t)addr;
mh.msg_namelen = g_beos_r5_compatibility ? sizeof(temp) : addrlen ? *addrlen : 0;
mh.msg_flags = flags;
mh.msg_control = NULL;
mh.msg_controllen = 0;
iov.iov_base = buffer;
iov.iov_len = buflen;
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
rv = ioctl(sock, NET_STACK_RECVFROM, &mh, sizeof(mh));
if (rv < 0)
return rv;
if (g_beos_r5_compatibility && addr)
convert_to_beos_r5_sockaddr(addr, &temp);
if (addrlen) {
if (g_beos_r5_compatibility)
*addrlen = sizeof(struct beosr5_sockaddr_in);
else
*addrlen = mh.msg_namelen;
}
return rv;
}
_EXPORT ssize_t sendto(int sock, const void *buffer, size_t buflen, int flags,
const struct sockaddr *addr, int addrlen)
{
struct sockaddr temp;
struct msghdr mh;
struct iovec iov;
// XXX: DNS HACK!
if (g_beos_r5_compatibility && addr->sa_family != AF_INET) {
convert_from_beos_r5_sockaddr(&temp, addr);
addr = &temp;
addrlen = sizeof(struct sockaddr_in);
}
/* XXX - would this be better done as scatter gather? */
mh.msg_name = (caddr_t)addr;
mh.msg_namelen = addrlen;
mh.msg_flags = flags;
mh.msg_control = NULL;
mh.msg_controllen = 0;
iov.iov_base = (caddr_t)buffer;
iov.iov_len = buflen;
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
return ioctl(sock, NET_STACK_SENDTO, &mh, sizeof(mh));
}
/* These need to be adjusted to take account of the MSG_PEEK
* flag, but old R5 doesn't use it...
*/
_EXPORT ssize_t recv(int sock, void *data, size_t datalen, int flags)
{
struct stack_driver_args args;
int rv;
args.u.transfer.data = data;
args.u.transfer.datalen = datalen;
args.u.transfer.flags = flags;
args.u.transfer.addr = NULL;
args.u.transfer.addrlen = 0;
rv = ioctl(sock, NET_STACK_RECV, &args, sizeof(args));
if (rv < 0)
return rv;
return args.u.transfer.datalen;
}
_EXPORT ssize_t send(int sock, const void *data, size_t datalen, int flags)
{
struct stack_driver_args args;
int rv;
args.u.transfer.data = (void *) data;
args.u.transfer.datalen = datalen;
args.u.transfer.flags = flags;
args.u.transfer.addr = NULL;
args.u.transfer.addrlen = 0;
rv = ioctl(sock, NET_STACK_SEND, &args, sizeof(args));
if (rv < 0)
return rv;
return args.u.transfer.datalen;
}
_EXPORT int getsockopt(int sock, int level, int option, void *optval, int *optlen)
{
struct stack_driver_args args;
int rv;
if (g_beos_r5_compatibility && option == 5) { // BeOS R5 SO_FIONREAD
status_t rv;
int temp;
rv = ioctl(sock, FIONREAD, &temp);
*(int*) optval = temp;
*optlen = sizeof(temp);
return rv;
};
if (g_beos_r5_compatibility)
convert_from_beos_r5_sockopt(&level, &option);
args.u.sockopt.level = level;
args.u.sockopt.option = option;
args.u.sockopt.optval = optval;
args.u.sockopt.optlen = *optlen;
rv = ioctl(sock, NET_STACK_GETSOCKOPT, &args, sizeof(args));
if (rv ==0)
*optlen = args.u.sockopt.optlen;
return rv;
}
_EXPORT int setsockopt(int sock, int level, int option, const void *optval, int optlen)
{
struct stack_driver_args args;
/* BeOS R5 uses
* setsockopt(sock, SOL_SOCKET, SO_NONBLOCK, &i, sizeof(i));
* Try to capture that here and the do the correct thing.
*/
if (g_beos_r5_compatibility && option == 3) {
int temp = *(int*) optval;
return ioctl(sock, FIONBIO, &temp);
}
if (g_beos_r5_compatibility)
convert_from_beos_r5_sockopt(&level, &option);
args.u.sockopt.level = level;
args.u.sockopt.option = option;
args.u.sockopt.optval = (void *) optval;
args.u.sockopt.optlen = optlen;
return ioctl(sock, NET_STACK_SETSOCKOPT, &args, sizeof(args));
}
_EXPORT int getpeername(int sock, struct sockaddr *addr, int *addrlen)
{
struct sockaddr temp;
struct stack_driver_args args;
int rv;
args.u.sockaddr.addr = g_beos_r5_compatibility ? &temp : addr;
args.u.sockaddr.addrlen = g_beos_r5_compatibility ? sizeof(temp) : *addrlen;
rv = ioctl(sock, NET_STACK_GETPEERNAME, &args, sizeof(args));
if (rv < 0)
return rv;
if (g_beos_r5_compatibility) {
convert_to_beos_r5_sockaddr(addr, &temp);
*addrlen = sizeof(struct beosr5_sockaddr_in);
} else
*addrlen = args.u.sockaddr.addrlen;
return rv;
}
_EXPORT int getsockname(int sock, struct sockaddr *addr, int *addrlen)
{
struct sockaddr temp;
struct stack_driver_args args;
int rv;
args.u.sockaddr.addr = g_beos_r5_compatibility ? &temp : addr;
args.u.sockaddr.addrlen = g_beos_r5_compatibility ? sizeof(temp) : *addrlen;
rv = ioctl(sock, NET_STACK_GETSOCKNAME, &args, sizeof(args));
if (rv < 0)
return rv;
if (g_beos_r5_compatibility) {
convert_to_beos_r5_sockaddr(addr, &temp);
*addrlen = sizeof(struct beosr5_sockaddr_in);
} else
*addrlen = args.u.sockaddr.addrlen;
return rv;
}
// #pragma mark -
_EXPORT int sysctl (int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
{
int s;
struct sysctl_args sa;
int rv;
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0)
return s;
sa.name = name;
sa.namelen = namelen;
sa.oldp = oldp;
sa.oldlenp = oldlenp;
sa.newp = newp;
sa.newlen = newlen;
rv = ioctl(s, NET_STACK_SYSCTL, &sa, sizeof(sa));
close(s);
return rv;
}
// #pragma mark -
/*
* Private routines
* ----------------
*/
static char * stack_driver_path(void) {
char * path;
// user-defined stack driver path?
path = getenv("NET_STACK_DRIVER_PATH");
if (path)
return path;
// use the default stack driver path
return NET_STACK_DRIVER_PATH;
}
static void convert_from_beos_r5_sockaddr(struct sockaddr *_to, const struct sockaddr *_from)
{
const struct beosr5_sockaddr_in *from = (struct beosr5_sockaddr_in *)_from;
struct sockaddr_in *to = (struct sockaddr_in *)_to;
memset(to, 0, sizeof(*to));
to->sin_len = sizeof(*to);
if (from->sin_family == 1)
to->sin_family = AF_INET;
else
to->sin_family = from->sin_family;
to->sin_port = from->sin_port;
to->sin_addr.s_addr = from->sin_addr;
}
static void convert_to_beos_r5_sockaddr(struct sockaddr *_to, const struct sockaddr *_from)
{
const struct sockaddr_in *from = (struct sockaddr_in *)_from;
struct beosr5_sockaddr_in *to = (struct beosr5_sockaddr_in *)_to;
memset(to, 0, sizeof(*to));
if (from->sin_family == AF_INET)
to->sin_family = 1;
else
to->sin_family = from->sin_family;
to->sin_port = from->sin_port;
to->sin_addr = from->sin_addr.s_addr;
}
static void convert_from_beos_r5_sockopt(int *level, int *optnum)
{
if (*level == 1)
*level = SOL_SOCKET;
switch (*optnum) {
case 1:
*optnum = SO_DEBUG;
break;
case 2:
*optnum = SO_REUSEADDR;
break;
/*
case 3:
*optnum = SO_NONBLOCK;
break;
*/
case 4:
*optnum = SO_REUSEPORT;
break;
/*
case 5:
*optnum = SO_FIONREAD;
break;
*/
};
}

View File

@ -1,38 +0,0 @@
SubDir HAIKU_TOP src kits network compat libsocket ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders net ;
UseHeaders [ FDirName $(HAIKU_TOP) headers legacy network ] : true ;
if $(TARGET_PLATFORM) != haiku {
UseHeaders [ FDirName $(HAIKU_TOP) headers posix ] : true ;
# We need the public network headers also when not compiling for Haiku.
# Unfortunately we get more than we want, namely all POSIX headers.
}
{
# Default libs include BeOS R5 libnet.so, something we don't want here!
LINKFLAGS on libsocket.so = [ on libsocket.so return $(LINKFLAGS) ] -nodefaultlibs ;
}
SharedLibrary libsocket.so :
socket.c
: root
;
# Installation -- in the test directory for the time being
HaikuInstallRelSymLink install-networking
: [ FDirName $(HAIKU_TEST_DIR) kits net lib ]
: libsocket.so
: installed-networking-test ;
HaikuInstallRelSymLink install-userland-networking
: [ FDirName $(HAIKU_TEST_DIR) kits net userland lib ]
: libsocket.so
: installed-userland-networking ;
Package haiku-networkingkit-cvs :
libsocket.so :
# boot home config lib ;
boot home Desktop haiku-networkingkit lib ;

View File

@ -1,370 +0,0 @@
/* socket.c */
/* This is a very simple little shared library that acts as a wrapper
* for our device/kernel stack!
*/
#include <fcntl.h>
#include <unistd.h>
#include <kernel/OS.h>
#include <iovec.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <netinet/in.h>
#include "net_stack_driver.h"
// Forward declaration of sysctl.h, because it's currently declared under headers/private/kernel/sysctl.h
int sysctl(int *, uint, void *, size_t *, void *, size_t);
static char * stack_driver_path(void);
_EXPORT int socket(int family, int type, int protocol)
{
int sock;
int rv;
struct stack_driver_args args;
sock = open(stack_driver_path(), O_RDWR);
if (sock < 0)
return sock;
args.u.socket.family = family;
args.u.socket.type = type;
args.u.socket.proto = protocol;
rv = ioctl(sock, NET_STACK_SOCKET, &args, sizeof(args));
if (rv < 0) {
close(sock);
return rv;
}
return sock;
}
_EXPORT int bind(int sock, const struct sockaddr *addr, int addrlen)
{
struct stack_driver_args args;
args.u.sockaddr.addr = (struct sockaddr *) addr;
args.u.sockaddr.addrlen = addrlen;
return ioctl(sock, NET_STACK_BIND, &args, sizeof(args));
}
_EXPORT int shutdown(int sock, int how)
{
struct stack_driver_args args;
args.u.integer = how;
return ioctl(sock, NET_STACK_SHUTDOWN, &args, sizeof(args));
}
_EXPORT int connect(int sock, const struct sockaddr *addr, int addrlen)
{
struct stack_driver_args args;
args.u.sockaddr.addr = (struct sockaddr *) addr;
args.u.sockaddr.addrlen = addrlen;
return ioctl(sock, NET_STACK_CONNECT, &args, sizeof(args));
}
_EXPORT int listen(int sock, int backlog)
{
struct stack_driver_args args;
args.u.integer = backlog;
return ioctl(sock, NET_STACK_LISTEN, &args, sizeof(args));
}
_EXPORT int accept(int sock, struct sockaddr *addr, int *addrlen)
{
struct stack_driver_args args;
int rv;
int new_sock;
void *cookie;
new_sock = open(stack_driver_path(), O_RDWR);
if (new_sock < 0)
return new_sock;
// The network stack driver will need to know to which net_stack_cookie to
// *bind* with the new accepted socket. He can't know himself find out
// the net_stack_cookie of our new_sock file descriptor, the just open() one...
// So, here, we ask him the net_stack_cookie value for our fd... :-)
rv = ioctl(new_sock, NET_STACK_GET_COOKIE, &cookie);
if (rv < 0) {
close(new_sock);
return rv;
}
args.u.accept.cookie = cookie; // this way driver can use the right fd/cookie for the new_sock!
args.u.accept.addr = addr;
args.u.accept.addrlen = addrlen ? *addrlen : 0;
rv = ioctl(sock, NET_STACK_ACCEPT, &args, sizeof(args));
if (rv < 0) {
close(new_sock);
return rv;
}
*addrlen = args.u.accept.addrlen;
return new_sock;
}
_EXPORT ssize_t recvfrom(int sock, void *buffer, size_t buflen, int flags,
struct sockaddr *addr, int *addrlen)
{
struct msghdr mh;
struct iovec iov;
int rv;
/* XXX - would this be better done as scatter gather? */
mh.msg_name = (caddr_t)addr;
mh.msg_namelen = addrlen ? *addrlen : 0;
mh.msg_flags = flags;
mh.msg_control = NULL;
mh.msg_controllen = 0;
iov.iov_base = buffer;
iov.iov_len = buflen;
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
rv = ioctl(sock, NET_STACK_RECVFROM, &mh, sizeof(mh));
if (rv < 0)
return rv;
if (addrlen)
*addrlen = mh.msg_namelen;
return rv;
}
_EXPORT ssize_t sendto(int sock, const void *buffer, size_t buflen, int flags,
const struct sockaddr *addr, int addrlen)
{
struct msghdr mh;
struct iovec iov;
/* XXX - would this be better done as scatter gather? */
mh.msg_name = (caddr_t)addr;
mh.msg_namelen = addrlen;
mh.msg_flags = flags;
mh.msg_control = NULL;
mh.msg_controllen = 0;
iov.iov_base = (caddr_t)buffer;
iov.iov_len = buflen;
mh.msg_iov = &iov;
mh.msg_iovlen = 1;
return ioctl(sock, NET_STACK_SENDTO, &mh, sizeof(mh));
}
/* These need to be adjusted to take account of the MSG_PEEK
* flag, but old R5 doesn't use it...
*/
_EXPORT ssize_t recv(int sock, void *data, size_t datalen, int flags)
{
struct stack_driver_args args;
int rv;
args.u.transfer.data = data;
args.u.transfer.datalen = datalen;
args.u.transfer.flags = flags;
args.u.transfer.addr = NULL;
args.u.transfer.addrlen = 0;
rv = ioctl(sock, NET_STACK_RECV, &args, sizeof(args));
if (rv < 0)
return rv;
return args.u.transfer.datalen;
}
_EXPORT ssize_t send(int sock, const void *data, size_t datalen, int flags)
{
struct stack_driver_args args;
int rv;
args.u.transfer.data = (void *) data;
args.u.transfer.datalen = datalen;
args.u.transfer.flags = flags;
args.u.transfer.addr = NULL;
args.u.transfer.addrlen = 0;
rv = ioctl(sock, NET_STACK_SEND, &args, sizeof(args));
if (rv < 0)
return rv;
return args.u.transfer.datalen;
}
_EXPORT int getsockopt(int sock, int level, int option, void *optval, int *optlen)
{
struct stack_driver_args args;
int rv;
args.u.sockopt.level = level;
args.u.sockopt.option = option;
args.u.sockopt.optval = optval;
args.u.sockopt.optlen = *optlen;
rv = ioctl(sock, NET_STACK_GETSOCKOPT, &args, sizeof(args));
if (rv ==0)
*optlen = args.u.sockopt.optlen;
return rv;
}
_EXPORT int setsockopt(int sock, int level, int option, const void *optval, int optlen)
{
struct stack_driver_args args;
args.u.sockopt.level = level;
args.u.sockopt.option = option;
args.u.sockopt.optval = (void *) optval;
args.u.sockopt.optlen = optlen;
return ioctl(sock, NET_STACK_SETSOCKOPT, &args, sizeof(args));
}
_EXPORT int getpeername(int sock, struct sockaddr *addr, int *addrlen)
{
struct stack_driver_args args;
int rv;
args.u.sockaddr.addr = addr;
args.u.sockaddr.addrlen = *addrlen;
rv = ioctl(sock, NET_STACK_GETPEERNAME, &args, sizeof(args));
if (rv < 0)
return rv;
*addrlen = args.u.sockaddr.addrlen;
return rv;
}
_EXPORT int getsockname(int sock, struct sockaddr *addr, int *addrlen)
{
struct stack_driver_args args;
int rv;
args.u.sockaddr.addr = addr;
args.u.sockaddr.addrlen = *addrlen;
rv = ioctl(sock, NET_STACK_GETSOCKNAME, &args, sizeof(args));
if (rv < 0)
return rv;
*addrlen = args.u.sockaddr.addrlen;
return rv;
}
_EXPORT int socketpair(int family, int type, int protocol, int socket_vector[2])
{
struct stack_driver_args args;
int rv;
void *cookie;
socket_vector[0] = socket(family, type, protocol);
if (socket_vector[0] < 0) {
return socket_vector[0];
}
socket_vector[1] = socket(family, type, protocol);
if (socket_vector[1] < 0) {
close(socket_vector[0]);
return socket_vector[1];
}
// The network stack driver will need to know to which net_stack_cookie to
// *bind* with the new accepted socket. He can't know himself find out
// the net_stack_cookie of our new_sock file descriptor, the just open() one...
// So, here, we ask him the net_stack_cookie value for our fd... :-)
rv = ioctl(socket_vector[1], NET_STACK_GET_COOKIE, &cookie);
if (rv < 0) {
close(socket_vector[0]);
close(socket_vector[1]);
return rv;
}
args.u.socketpair.cookie = cookie; // this way driver can use the right fd/cookie!
rv = ioctl(socket_vector[0], NET_STACK_SOCKETPAIR, &args, sizeof(args));
if (rv < 0) {
close(socket_vector[0]);
close(socket_vector[1]);
return rv;
}
return rv;
}
// #pragma mark -
_EXPORT int sysctl (int *name, uint namelen, void *oldp, size_t *oldlenp,
void *newp, size_t newlen)
{
int s;
struct sysctl_args sa;
int rv;
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0)
return s;
sa.name = name;
sa.namelen = namelen;
sa.oldp = oldp;
sa.oldlenp = oldlenp;
sa.newp = newp;
sa.newlen = newlen;
rv = ioctl(s, NET_STACK_SYSCTL, &sa, sizeof(sa));
close(s);
return rv;
}
// #pragma mark -
/*
* Private routines
* ----------------
*/
static char * stack_driver_path(void) {
char * path;
// user-defined stack driver path?
path = getenv("NET_STACK_DRIVER_PATH");
if (!path)
path = NET_STACK_DRIVER_PATH;
return path;
}

View File

@ -1,148 +0,0 @@
#!/bin/sh
base=`dirname "$0"`
cd "$base"
function backup()
{
BACKUP="uninstall.zip"
rm -f "$BACKUP"
# Backup BONE system files
zip -yqr "$BACKUP" "/boot/beos/system/add-ons/kernel/network"
zip -yq "$BACKUP" \
"/boot/beos/system/lib/libnet.so" \
"/boot/beos/system/lib/libnetdev.so" \
"/boot/beos/system/lib/libnetapi.so" \
"/boot/beos/system/lib/libsocket.so" \
"/boot/beos/system/lib/libbind.so" \
"/boot/beos/system/lib/libbnetapi.so" \
"/boot/beos/system/lib/libnetconfig.so" \
"/boot/beos/bin/ifconfig" \
"/boot/beos/bin/ping" \
"/boot/beos/bin/dhclient" \
"/boot/beos/bin/dhconfig" \
"/boot/beos/bin/dhcp_client" \
"/boot/beos/bin/dhcpd" \
"/boot/beos/bin/dhcrelay" \
"/boot/beos/bin/dnskeygen" \
"/boot/beos/bin/dnsquery" \
"/boot/beos/bin/ftp" \
"/boot/beos/bin/ftpd" \
"/boot/beos/bin/host" \
"/boot/beos/bin/inetd" \
"/boot/beos/bin/ipalias" \
"/boot/beos/bin/irpd" \
"/boot/beos/bin/named" \
"/boot/beos/bin/pppconfig" \
"/boot/beos/bin/route" \
"/boot/beos/bin/tcpdump" \
"/boot/beos/bin/tcptrace" \
"/boot/beos/bin/telnet" \
"/boot/beos/bin/telnetd" \
"/boot/beos/bin/traceroute"
zip -yqr "$BACKUP" "/boot/beos/system/add-ons/boneyard"
zip -yq "$BACKUP" \
"/boot/beos/preferences/Boneyard" \
"/boot/home/config/be/Preferences/Boneyard"
# Backup network drivers
for file in /boot/beos/system/add-ons/kernel/drivers/dev/net/*
do
f=`basename "$file"`
zip -yq "$BACKUP" "/boot/beos/system/add-ons/kernel/drivers/bin/$f" \
"/boot/beos/system/add-ons/kernel/drivers/dev/net/$f"
done
for file in /boot/home/config/add-ons/kernel/drivers/dev/net/*
do
f=`basename "$file"`
zip -yq "$BACKUP" "/boot/home/config/add-ons/kernel/drivers/bin/$f" \
"/boot/home/config/add-ons/kernel/drivers/dev/net/$f"
done
zip -yqr "$BACKUP" \
"/boot/beos/system/add-ons/kernel/obos_network" \
"/boot/home/config/add-ons/kernel/obos_network"
zip -yq "$BACKUP" \
"/boot/home/config/lib/libnet.so" \
"/boot/home/config/lib/libnetapi.so" \
"/boot/home/config/lib/libbind.so" \
"/boot/home/config/lib/libsocket.so" \
"/boot/home/config/lib/libbind.so" \
"/boot/home/config/bin/arp" \
"/boot/home/config/bin/ifconfig" \
"/boot/home/config/bin/ping" \
"/boot/home/config/bin/ppp_up" \
"/boot/home/config/bin/pppconfig" \
"/boot/home/config/bin/route" \
"/boot/home/config/bin/traceroute" \
"/boot/beos/etc/networks" \
"/boot/beos/etc/protocols" \
"/boot/beos/etc/resolv.conf" \
"/boot/beos/etc/services"
}
# Checking for BONE stack...
if [ -f /boot/beos/system/add-ons/kernel/network/bone_tcp -a \
-c /dev/net/api ]
then
BONE=1
fi
# Checking for Haiku stack...
if [ \( -f /boot/beos/system/add-ons/kernel/obos_network/core -o \
-f /boot/home/config/add-ons/kernel/obos_network/core \) -a \
-c /dev/net/stack ]
then
HAIKU_NETKIT=1
fi
response=`alert "Do you want to backup files before installing Haiku networking kit. \
This will create an uninstall.zip file to restore back your system." \
"Backup & Install" "Install" "Abort - Don't do anything!"`
if [ "$response" = "Backup & Install" ]
then
echo "Backup in progress...";
backup;
response="Install"
elif [ "$response" = "Install" ]
then
response=`alert "No backup will be done.
That means it's up to YOU to ensure that you can restore your system in previous configuration.
We suggest STRONGLY to do it right now before it's too late..." \
"Install" "Abort"`
fi
if [ "$response" != "Install" ]
then
echo "Aborting..."
exit -1
fi
echo "Installing..."
if [ -n "$TTY" ]
then
unzip -d / install.zip
else
response=`alert "Would you like to automatically overwrite existing files, or receive a prompt?" "Overwrite" "Prompt"`
if [ $response == "Overwrite" ]
then
unzip -od / install.zip
alert "Finished installing" "Thanks"
else
if [ -e /boot/beos/apps/Terminal ]
then
terminal=/boot/beos/apps/Terminal
else
terminal=`query Terminal | head -1`
fi
$terminal -t "installer" /bin/sh "$0"
fi
fi