cpukit: Remove libnetworking

Update #3850
This commit is contained in:
Vijay Kumar Banerjee
2021-04-07 16:15:38 -06:00
parent a28eafb2a4
commit 2a13ad389a
358 changed files with 0 additions and 94818 deletions
-42
View File
@@ -1,42 +0,0 @@
/*
* Dummy configuration file
*
* COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems.h>
/* Loopback Network Configuration */
#if defined(RTEMS_NETWORKING)
#include <rtems/rtems_bsdnet.h>
#include <sys/socket.h>
#include <netinet/in.h>
struct rtems_bsdnet_config rtems_bsdnet_config = {
NULL, /* Network interface */
NULL, /* Use fixed network configuration */
0, /* Default network task priority */
0, /* Default mbuf capacity */
0, /* Default mbuf cluster capacity */
"testSystem", /* Host name */
"nowhere.com", /* Domain name */
"127.0.0.1", /* Gateway */
"127.0.0.1", /* Log host */
{"127.0.0.1" }, /* Name server(s) */
{"127.0.0.1" }, /* NTP server(s) */
1, /* sb_efficiency */
0, /* udp_tx_buf_size */
0, /* udp_rx_buf_size */
0, /* tcp_tx_buf_size */
0 /* tcp_rx_buf_size */
};
#endif
-342
View File
@@ -1,342 +0,0 @@
/*
* COPYRIGHT (c) 1989-2007.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <rtems/rtems_bsdnet.h>
#include <sys/socket.h>
#include <net/if.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/sockio.h>
#include <net/route.h>
#include <rtems/monitor.h>
void mon_ifconfig(int argc, char *argv[],
uint32_t command_arg RTEMS_UNUSED,
bool verbose RTEMS_UNUSED)
{
struct sockaddr_in ipaddr;
struct sockaddr_in dstaddr;
struct sockaddr_in netmask;
struct sockaddr_in broadcast;
char *iface;
int f_ip = 0;
int f_ptp = 0;
int f_netmask = 0;
int f_up = 0;
int f_down = 0;
int f_bcast = 0;
int cur_idx;
int rc;
int flags;
memset(&ipaddr, 0, sizeof(ipaddr));
memset(&dstaddr, 0, sizeof(dstaddr));
memset(&netmask, 0, sizeof(netmask));
memset(&broadcast, 0, sizeof(broadcast));
ipaddr.sin_len = sizeof(ipaddr);
ipaddr.sin_family = AF_INET;
dstaddr.sin_len = sizeof(dstaddr);
dstaddr.sin_family = AF_INET;
netmask.sin_len = sizeof(netmask);
netmask.sin_family = AF_INET;
broadcast.sin_len = sizeof(broadcast);
broadcast.sin_family = AF_INET;
cur_idx = 0;
if (argc <= 1) {
/* display all interfaces */
iface = NULL;
cur_idx += 1;
} else {
iface = argv[1];
if (isdigit((unsigned char)*argv[2])) {
if (inet_pton(AF_INET, argv[2], &ipaddr.sin_addr) < 0) {
printf("bad ip address: %s\n", argv[2]);
return;
}
f_ip = 1;
cur_idx += 3;
} else {
cur_idx += 2;
}
}
if ((f_down !=0) && (f_ip != 0)) {
f_up = 1;
}
while(argc > cur_idx) {
if (strcmp(argv[cur_idx], "up") == 0) {
f_up = 1;
if (f_down != 0) {
printf("Can't make interface up and down\n");
}
} else if(strcmp(argv[cur_idx], "down") == 0) {
f_down = 1;
if (f_up != 0) {
printf("Can't make interface up and down\n");
}
} else if(strcmp(argv[cur_idx], "netmask") == 0) {
if ((cur_idx + 1) >= argc) {
printf("No netmask address\n");
return;
}
if (inet_pton(AF_INET, argv[cur_idx+1], &netmask.sin_addr) < 0) {
printf("bad netmask: %s\n", argv[cur_idx]);
return;
}
f_netmask = 1;
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "broadcast") == 0) {
if ((cur_idx + 1) >= argc) {
printf("No broadcast address\n");
return;
}
if (inet_pton(AF_INET, argv[cur_idx+1], &broadcast.sin_addr) < 0) {
printf("bad broadcast: %s\n", argv[cur_idx]);
return;
}
f_bcast = 1;
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "pointopoint") == 0) {
if ((cur_idx + 1) >= argc) {
printf("No pointopoint address\n");
return;
}
if (inet_pton(AF_INET, argv[cur_idx+1], &dstaddr.sin_addr) < 0) {
printf("bad pointopoint: %s\n", argv[cur_idx]);
return;
}
f_ptp = 1;
cur_idx += 1;
} else {
printf("Bad parameter: %s\n", argv[cur_idx]);
return;
}
cur_idx += 1;
}
printf("ifconfig ");
if (iface != NULL) {
printf("%s ", iface);
if (f_ip != 0) {
char str[256];
inet_ntop(AF_INET, &ipaddr.sin_addr, str, 256);
printf("%s ", str);
}
if (f_netmask != 0) {
char str[256];
inet_ntop(AF_INET, &netmask.sin_addr, str, 256);
printf("netmask %s ", str);
}
if (f_bcast != 0) {
char str[256];
inet_ntop(AF_INET, &broadcast.sin_addr, str, 256);
printf("broadcast %s ", str);
}
if (f_ptp != 0) {
char str[256];
inet_ntop(AF_INET, &dstaddr.sin_addr, str, 256);
printf("pointopoint %s ", str);
}
if (f_up != 0) {
printf("up\n");
} else if (f_down != 0) {
printf("down\n");
} else {
printf("\n");
}
}
if ((iface == NULL) || ((f_ip == 0) && (f_down == 0) && (f_up == 0))) {
rtems_bsdnet_show_if_stats();
return;
}
flags = 0;
if (f_netmask) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFNETMASK, &netmask);
if (rc < 0) {
printf("Could not set netmask: %s\n", strerror(errno));
return;
}
}
if (f_bcast) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFBRDADDR, &broadcast);
if (rc < 0) {
printf("Could not set broadcast: %s\n", strerror(errno));
return;
}
}
if (f_ptp) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFDSTADDR, &dstaddr);
if (rc < 0) {
printf("Could not set destination address: %s\n", strerror(errno));
return;
}
flags |= IFF_POINTOPOINT;
}
/* This must come _after_ setting the netmask, broadcast addresses */
if (f_ip) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFADDR, &ipaddr);
if (rc < 0) {
printf("Could not set IP address: %s\n", strerror(errno));
return;
}
}
if (f_up != 0) {
flags |= IFF_UP;
}
if (f_down != 0) {
printf("Warning: taking interfaces down is not supported\n");
}
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFFLAGS, &flags);
if (rc < 0) {
printf("Could not set interface flags: %s\n", strerror(errno));
return;
}
}
void mon_route(int argc, char *argv[],
uint32_t command_arg RTEMS_UNUSED,
bool verbose RTEMS_UNUSED)
{
int cmd;
struct sockaddr_in dst;
struct sockaddr_in gw;
struct sockaddr_in netmask;
int f_host;
int f_gw = 0;
int cur_idx;
int flags;
int rc;
memset(&dst, 0, sizeof(dst));
memset(&gw, 0, sizeof(gw));
memset(&netmask, 0, sizeof(netmask));
dst.sin_len = sizeof(dst);
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = inet_addr("0.0.0.0");
gw.sin_len = sizeof(gw);
gw.sin_family = AF_INET;
gw.sin_addr.s_addr = inet_addr("0.0.0.0");
netmask.sin_len = sizeof(netmask);
netmask.sin_family = AF_INET;
netmask.sin_addr.s_addr = inet_addr("255.255.255.0");
if (argc < 2) {
rtems_bsdnet_show_inet_routes();
return;
}
if (strcmp(argv[1], "add") == 0) {
cmd = RTM_ADD;
} else if (strcmp(argv[1], "del") == 0) {
cmd = RTM_DELETE;
} else {
printf("invalid command: %s\n", argv[1]);
printf("\tit should be 'add' or 'del'\n");
return;
}
if (argc < 3) {
printf("not enough arguments\n");
return;
}
if (strcmp(argv[2], "-host") == 0) {
f_host = 1;
} else if (strcmp(argv[2], "-net") == 0) {
f_host = 0;
} else {
printf("Invalid type: %s\n", argv[1]);
printf("\tit should be '-host' or '-net'\n");
return;
}
if (argc < 4) {
printf("not enough arguments\n");
return;
}
inet_pton(AF_INET, argv[3], &dst.sin_addr);
cur_idx = 4;
while(cur_idx < argc) {
if (strcmp(argv[cur_idx], "gw") == 0) {
if ((cur_idx +1) >= argc) {
printf("no gateway address\n");
return;
}
f_gw = 1;
inet_pton(AF_INET, argv[cur_idx + 1], &gw.sin_addr);
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "netmask") == 0) {
if ((cur_idx +1) >= argc) {
printf("no netmask address\n");
return;
}
f_gw = 1;
inet_pton(AF_INET, argv[cur_idx + 1], &netmask.sin_addr);
cur_idx += 1;
} else {
printf("Unknown argument: %s\n", argv[cur_idx]);
return;
}
cur_idx += 1;
}
flags = RTF_STATIC;
if (f_gw != 0) {
flags |= RTF_GATEWAY;
}
if (f_host != 0) {
flags |= RTF_HOST;
}
rc = rtems_bsdnet_rtrequest(cmd,
(struct sockaddr*) &dst,
(struct sockaddr*) &gw,
(struct sockaddr*) &netmask, flags, NULL);
if (rc < 0) {
printf("Error adding route\n");
}
}
-275
View File
@@ -1,275 +0,0 @@
/*
* IFCONFIG Command Implmentation
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/shell.h>
#include "internal.h"
static const char IFCONFIG_USAGE[] =
"ifconfig [iface]\n"
"ifconfig iface options | addr\n"
" iface: name of the interface\n"
" options: iface \n"
" up: bring the interface up\n"
" down: take the interface down\n"
" netmask addr: network mask\n"
" broadcast addr: boardcast address\n"
" pointopoint addr: destination address for a PTP link\n"
"\n"
" addr: IP address";
static int rtems_shell_main_ifconfig(
int argc,
char *argv[]
)
{
struct sockaddr_in ipaddr;
struct sockaddr_in dstaddr;
struct sockaddr_in netmask;
struct sockaddr_in broadcast;
char *iface = NULL;
int f_ip = 0;
int f_ptp = 0;
int f_netmask = 0;
int f_up = 0;
int f_down = 0;
int f_bcast = 0;
int f_usage = 0;
int cur_idx;
int rc;
int flags;
memset(&ipaddr, 0, sizeof(ipaddr));
memset(&dstaddr, 0, sizeof(dstaddr));
memset(&netmask, 0, sizeof(netmask));
memset(&broadcast, 0, sizeof(broadcast));
ipaddr.sin_len = sizeof(ipaddr);
ipaddr.sin_family = AF_INET;
dstaddr.sin_len = sizeof(dstaddr);
dstaddr.sin_family = AF_INET;
netmask.sin_len = sizeof(netmask);
netmask.sin_family = AF_INET;
broadcast.sin_len = sizeof(broadcast);
broadcast.sin_family = AF_INET;
cur_idx = 0;
if (argc <= 1) {
/* display all interfaces */
iface = NULL;
cur_idx += 1;
} else {
if ( 0 == strcmp( "--help", argv[1] ) ) {
f_usage = 1;
cur_idx += 2;
} else if ( 0 == strcmp( "-help", argv[1] ) ) {
f_usage = 1;
cur_idx += 2;
} else {
iface = argv[1];
if ( argc >= 3 ) {
if (isdigit((unsigned char)*argv[2])) {
if (inet_pton(AF_INET, argv[2], &ipaddr.sin_addr) < 0) {
printf("bad ip address: %s\n", argv[2]);
return 0;
}
f_ip = 1;
cur_idx += 3;
} else {
cur_idx += 2;
}
} else {
cur_idx += 2;
}
}
}
if ((f_down !=0) && (f_ip != 0)) {
f_up = 1;
}
while(argc > cur_idx) {
if (strcmp(argv[cur_idx], "up") == 0) {
f_up = 1;
if (f_down != 0) {
printf("Can't make interface up and down\n");
return -1;
}
} else if(strcmp(argv[cur_idx], "down") == 0) {
f_down = 1;
if (f_up != 0) {
printf("Can't make interface up and down\n");
return -1;
}
} else if(strcmp(argv[cur_idx], "netmask") == 0) {
if ((cur_idx + 1) >= argc) {
printf("No netmask address\n");
return -1;
}
if (inet_pton(AF_INET, argv[cur_idx+1], &netmask.sin_addr) < 0) {
printf("bad netmask: %s\n", argv[cur_idx]);
return -1;
}
f_netmask = 1;
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "broadcast") == 0) {
if ((cur_idx + 1) >= argc) {
printf("No broadcast address\n");
return -1;
}
if (inet_pton(AF_INET, argv[cur_idx+1], &broadcast.sin_addr) < 0) {
printf("bad broadcast: %s\n", argv[cur_idx]);
return -1;
}
f_bcast = 1;
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "pointopoint") == 0) {
if ((cur_idx + 1) >= argc) {
printf("No pointopoint address\n");
return -1;
}
if (inet_pton(AF_INET, argv[cur_idx+1], &dstaddr.sin_addr) < 0) {
printf("bad pointopoint: %s\n", argv[cur_idx]);
return -1;
}
f_ptp = 1;
cur_idx += 1;
} else {
printf("Bad parameter: %s\n", argv[cur_idx]);
return -1;
}
cur_idx += 1;
}
printf("ifconfig ");
if (iface != NULL) {
printf("%s ", iface);
if (f_ip != 0) {
char str[256];
inet_ntop(AF_INET, &ipaddr.sin_addr, str, 256);
printf("%s ", str);
}
if (f_netmask != 0) {
char str[256];
inet_ntop(AF_INET, &netmask.sin_addr, str, 256);
printf("netmask %s ", str);
}
if (f_bcast != 0) {
char str[256];
inet_ntop(AF_INET, &broadcast.sin_addr, str, 256);
printf("broadcast %s ", str);
}
if (f_ptp != 0) {
char str[256];
inet_ntop(AF_INET, &dstaddr.sin_addr, str, 256);
printf("pointopoint %s ", str);
}
if (f_up != 0) {
printf("up\n");
} else if (f_down != 0) {
printf("down\n");
} else {
printf("\n");
}
} else if (f_usage != 0) {
printf ( "\n" );
printf ( IFCONFIG_USAGE );
}
if ( ! f_usage ) {
if ((iface == NULL) || ((f_ip == 0) && (f_down == 0) && (f_up == 0))) {
rtems_bsdnet_show_if_stats();
return 0;
}
}
flags = 0;
if (f_netmask) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFNETMASK, &netmask);
if (rc < 0) {
printf("Could not set netmask: %s\n", strerror(errno));
return -1;
}
}
if (f_bcast) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFBRDADDR, &broadcast);
if (rc < 0) {
printf("Could not set broadcast: %s\n", strerror(errno));
return -1;
}
}
if (f_ptp) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFDSTADDR, &dstaddr);
if (rc < 0) {
printf("Could not set destination address: %s\n", strerror(errno));
return -1;
}
flags |= IFF_POINTOPOINT;
}
/* This must come _after_ setting the netmask, broadcast addresses */
if (f_ip) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFADDR, &ipaddr);
if (rc < 0) {
printf("Could not set IP address: %s\n", strerror(errno));
return -1;
}
}
if (f_up != 0) {
flags |= IFF_UP;
}
if ( ! f_usage ) {
rc = rtems_bsdnet_ifconfig(iface, SIOCSIFFLAGS, &flags);
if (rc < 0) {
printf("Could not set interface flags: %s\n", strerror(errno));
return -1;
}
}
return 0;
}
rtems_shell_cmd_t rtems_shell_IFCONFIG_Command = {
"ifconfig", /* name */
IFCONFIG_USAGE, /* usage */
"network", /* topic */
rtems_shell_main_ifconfig, /* command */
NULL, /* alias */
NULL /* next */
};
-137
View File
@@ -1,137 +0,0 @@
/*
* Network Statistics Shell Command Implmentation
*
* COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#define __need_getopt_newlib
#include <getopt.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/shell.h>
#include "internal.h"
static void netstats_usage(void)
{
printf(
"netstats [-vAimfpcut] where:\n"
" -A print All statistics\n"
" -i print Inet Routes\n"
" -m print MBUF Statistics\n"
" -f print IF Statistics\n"
" -p print IP Statistics\n"
" -c print ICMP Statistics\n"
" -u print UDP Statistics\n"
" -t print TCP Statistics\n"
);
}
static int rtems_shell_main_netstats( /* command */
int argc,
char *argv[]
)
{
int option;
int doAll = 0;
int doInetRoutes = 0;
int doMBUFStats = 0;
int doIFStats = 0;
int doIPStats = 0;
int doICMPStats = 0;
int doUDPStats = 0;
int doTCPStats = 0;
int verbose = 0;
struct getopt_data getopt_reent;
memset(&getopt_reent, 0, sizeof(getopt_data));
while ( (option = getopt_r( argc, argv, "Aimfpcutv", &getopt_reent)) != -1 ) {
switch ((char)option) {
case 'A': doAll = 1; break;
case 'i': doInetRoutes = 1; break;
case 'm': doMBUFStats = 1; break;
case 'f': doIFStats = 1; break;
case 'p': doIPStats = 1; break;
case 'c': doICMPStats = 1; break;
case 'u': doUDPStats = 1; break;
case 't': doTCPStats = 1; break;
case 'v': verbose = 1; break;
case '?':
default:
netstats_usage();
return -1;
}
}
if ( verbose ) {
printf(
"doAll=%d\n"
"doInetRoutes=%d\n"
"doMBUFStats=%d\n"
"doIFStats=%d\n"
"doIPStats=%d\n"
"doICMPStats=%d\n"
"doUDPStats=%d\n"
"doTCPStats=%d\n",
doAll,
doInetRoutes,
doMBUFStats,
doIFStats,
doIPStats,
doICMPStats,
doUDPStats,
doTCPStats
);
}
if ( doInetRoutes == 1 || doAll == 1 ) {
rtems_bsdnet_show_inet_routes();
}
if ( doMBUFStats == 1 || doAll == 1 ) {
rtems_bsdnet_show_mbuf_stats();
}
if ( doIFStats == 1 || doAll == 1 ) {
rtems_bsdnet_show_if_stats();
}
if ( doIPStats == 1 || doAll == 1 ) {
rtems_bsdnet_show_ip_stats();
}
if ( doICMPStats == 1 || doAll == 1 ) {
rtems_bsdnet_show_icmp_stats();
}
if ( doUDPStats == 1 || doAll == 1 ) {
rtems_bsdnet_show_udp_stats();
}
if ( doTCPStats == 1 || doAll == 1 ) {
rtems_bsdnet_show_tcp_stats();
}
return 0;
}
rtems_shell_cmd_t rtems_shell_NETSTATS_Command = {
"netstats", /* name */
"netstats [-Aimfpcutv]", /* usage */
"network", /* topic */
rtems_shell_main_netstats, /* command */
NULL, /* alias */
NULL /* next */
};
File diff suppressed because it is too large Load Diff
-151
View File
@@ -1,151 +0,0 @@
/*
* ROUTE Command Implmentation
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/shell.h>
#include "internal.h"
static int rtems_shell_main_route(
int argc,
char *argv[]
)
{
int cmd;
struct sockaddr_in dst;
struct sockaddr_in gw;
struct sockaddr_in netmask;
int f_host;
int f_gw = 0;
int cur_idx;
int flags;
int rc;
memset(&dst, 0, sizeof(dst));
memset(&gw, 0, sizeof(gw));
memset(&netmask, 0, sizeof(netmask));
dst.sin_len = sizeof(dst);
dst.sin_family = AF_INET;
dst.sin_addr.s_addr = inet_addr("0.0.0.0");
gw.sin_len = sizeof(gw);
gw.sin_family = AF_INET;
gw.sin_addr.s_addr = inet_addr("0.0.0.0");
netmask.sin_len = sizeof(netmask);
netmask.sin_family = AF_INET;
netmask.sin_addr.s_addr = inet_addr("255.255.255.0");
if (argc < 2) {
rtems_bsdnet_show_inet_routes();
return 0;
}
if (strcmp(argv[1], "add") == 0) {
cmd = RTM_ADD;
} else if (strcmp(argv[1], "del") == 0) {
cmd = RTM_DELETE;
} else {
printf("invalid command: %s\n", argv[1]);
printf("\tit should be 'add' or 'del'\n");
return -1;
}
if (argc < 3) {
printf("not enough arguments\n");
return -1;
}
if (strcmp(argv[2], "-host") == 0) {
f_host = 1;
} else if (strcmp(argv[2], "-net") == 0) {
f_host = 0;
} else {
printf("Invalid type: %s\n", argv[1]);
printf("\tit should be '-host' or '-net'\n");
return -1;
}
if (argc < 4) {
printf("not enough arguments\n");
return -1;
}
inet_pton(AF_INET, argv[3], &dst.sin_addr);
cur_idx = 4;
while(cur_idx < argc) {
if (strcmp(argv[cur_idx], "gw") == 0) {
if ((cur_idx +1) >= argc) {
printf("no gateway address\n");
return -1;
}
f_gw = 1;
inet_pton(AF_INET, argv[cur_idx + 1], &gw.sin_addr);
cur_idx += 1;
} else if(strcmp(argv[cur_idx], "netmask") == 0) {
if ((cur_idx +1) >= argc) {
printf("no netmask address\n");
return -1;
}
f_gw = 1;
inet_pton(AF_INET, argv[cur_idx + 1], &netmask.sin_addr);
cur_idx += 1;
} else {
printf("Unknown argument\n");
return -1;
}
cur_idx += 1;
}
flags = RTF_STATIC;
if (f_gw != 0) {
flags |= RTF_GATEWAY;
}
if (f_host != 0) {
flags |= RTF_HOST;
}
rc = rtems_bsdnet_rtrequest(
cmd,
(struct sockaddr *)&dst,
(struct sockaddr *)&gw,
(struct sockaddr *)&netmask,
flags,
NULL
);
if (rc < 0) {
printf("Error adding route\n");
}
return 0;
}
rtems_shell_cmd_t rtems_shell_ROUTE_Command = {
"route", /* name */
"TBD", /* usage */
"network", /* topic */
rtems_shell_main_route, /* command */
NULL, /* alias */
NULL /* next */
};
-68
View File
@@ -1,68 +0,0 @@
This is a snapshot of my attempt to fit the FreeBSD networking code into
RTEMS. Things seem to be working!
Things that need to be done:
1) More documentation!
2) Figure out what's still not working :-)
3) Rationalize the include files. Right now I have a special
hack in the Makefile to ensure that I pick up the FreeBSD versions
of the include files that are duplicated between RTEMS
and FreeBSD.
The network device driver source should move to the BSP source tree.
4) Have a look at all the FIXME comments.
5) Go through and make sure that all the source files are
free of undesired copyright restrictions.
Initial Changes
===============
19-AUG-1998 snapshot
- Pulled BOOTP initialization out of rtems_glue. Applications which
don't used BOOTP are now about 5k smaller.
- Loopback interface is not installed by default, rather it is
attached like any other interface. Saves about 0.5 kbytes.
- Add rtems_bsdnet_show_if_stats();
- Moved test programs from below freebsd directory.
18-AUG-1998 snapshot
- Removed some include files that were already part of RTEMS.
- Cleaned up machine/types.h to prepare for inclusion in RTEMS source.
- Added syslog library routines -- much simpler than KA9Q version.
Sockets can be shared among tasks (as long as the send is
protected by a mutex) so there's no need for a Syslog Daemon.
16-AUG-1998 snapshot
- Table-driven configuration (networkconfig.h).
- Cleaned up rtems_bsdnet.h.
- BOOTP now retries properly -- Note to Joel:
The dichotomy between RTEMS and UNIX error codes is
a real pain!
14-AUG-1998 snapshot
- Added dummy getprotobyname() and getprotobynum() functions.
- Added socket ioctl.
- Added application-level entry to manipulate routing tables.
- Added non-BOOTP network initialization.
13-AUG-1998 snapshot
- Changed some BOOTP addresses from sockaddr_in to inaddr;
- Get DNS information from BOOTP reply.
- Got DNS lookups working.
Bloatware comes to RTEMS -- invoking gethostbyname() drags in
and extra 40 kbytes of code!
- Added hostname lookup program.
12-AUG-1998 snapshot
- Added startup delay to network initialization.
- More statistic-printing routines.
- Added TFTP driver and test program
- Modified TFTP test program to use networkconfig.h.
- Removed unused include files.
- Added from ftp://ftp.ca.FreeBSD.ORG/pub/FreeBSD/FreeBSD-current/src/lib/libc/net.
11-AUG-1998 snapshot.
- Added getpeername()
- Added M68k versions of IP checksum code
- Added TCP timing program to snapshot.
02-AUG-1998 snapshot.
-450
View File
@@ -1,450 +0,0 @@
/*
* 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.
*/
/*
* 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.
*/
/*
* From: Id: nameser.h,v 8.16 1998/02/06 00:35:58 halley Exp
* $FreeBSD: src/include/arpa/nameser.h,v 1.16 2002/03/23 17:24:55 imp Exp $
*/
#ifndef _ARPA_NAMESER_H_
#define _ARPA_NAMESER_H_
#define BIND_4_COMPAT
#include <sys/types.h>
#include <sys/cdefs.h>
/*
* 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 (__NAMESER > 19931104)". do not
* compare for equality; rather, use it to determine whether your libnameser.a
* is new enough to contain a certain feature.
*/
/* XXXRTH I made this bigger than __BIND in 4.9.5 T6B */
#define __NAMESER 19961001 /* New interface version stamp. */
/*
* Define constants based on RFC 883, RFC 1034, RFC 1035
*/
#define NS_PACKETSZ 512 /* maximum packet size */
#define NS_MAXDNAME 1025 /* maximum domain name */
#define NS_MAXCDNAME 255 /* maximum compressed domain name */
#define NS_MAXLABEL 63 /* maximum length of domain label */
#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */
#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */
#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
#define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */
#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */
#define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */
#define NS_INADDRSZ 4 /* IPv4 T_A */
#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */
#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */
#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */
/*
* These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord()
* in synch with it.
*/
typedef enum __ns_sect {
ns_s_qd = 0, /* Query: Question. */
ns_s_zn = 0, /* Update: Zone. */
ns_s_an = 1, /* Query: Answer. */
ns_s_pr = 1, /* Update: Prerequisites. */
ns_s_ns = 2, /* Query: Name servers. */
ns_s_ud = 2, /* Update: Update. */
ns_s_ar = 3, /* Query|Update: Additional records. */
ns_s_max = 4
} ns_sect;
/*
* This is a message handle. It is caller allocated and has no dynamic data.
* This structure is intended to be opaque to all but ns_parse.c, thus the
* leading _'s on the member names. Use the accessor functions, not the _'s.
*/
typedef struct __ns_msg {
const u_char *_msg, *_eom;
u_int16_t _id, _flags, _counts[ns_s_max];
const u_char *_sections[ns_s_max];
ns_sect _sect;
int _rrnum;
const u_char *_ptr;
} ns_msg;
/* Private data structure - do not use from outside library. */
struct _ns_flagdata { int mask, shift; };
extern struct _ns_flagdata _ns_flagdata[];
/* Accessor macros - this is part of the public interface. */
#define ns_msg_getflag(handle, flag) ( \
((handle)._flags & _ns_flagdata[flag].mask) \
>> _ns_flagdata[flag].shift \
)
#define ns_msg_id(handle) ((handle)._id + 0)
#define ns_msg_base(handle) ((handle)._msg + 0)
#define ns_msg_end(handle) ((handle)._eom + 0)
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
/*
* This is a parsed record. It is caller allocated and has no dynamic data.
*/
typedef struct __ns_rr {
char name[NS_MAXDNAME]; /* XXX need to malloc */
u_int16_t type;
u_int16_t rr_class;
u_int32_t ttl;
u_int16_t rdlength;
const u_char *rdata;
} ns_rr;
/* Accessor macros - this is part of the public interface. */
#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
#define ns_rr_type(rr) ((rr).type + 0)
#define ns_rr_class(rr) ((rr).rr_class + 0)
#define ns_rr_ttl(rr) ((rr).ttl + 0)
#define ns_rr_rdlen(rr) ((rr).rdlength + 0)
#define ns_rr_rdata(rr) ((rr).rdata + 0)
/*
* These don't have to be in the same order as in the packet flags word,
* and they can even overlap in some cases, but they will need to be kept
* in synch with ns_parse.c:ns_flagdata[].
*/
typedef enum __ns_flag {
ns_f_qr, /* Question/Response. */
ns_f_opcode, /* Operation code. */
ns_f_aa, /* Authoritative Answer. */
ns_f_tc, /* Truncation occurred. */
ns_f_rd, /* Recursion Desired. */
ns_f_ra, /* Recursion Available. */
ns_f_z, /* MBZ. */
ns_f_ad, /* Authentic Data (DNSSEC). */
ns_f_cd, /* Checking Disabled (DNSSEC). */
ns_f_rcode, /* Response code. */
ns_f_max
} ns_flag;
/*
* Currently defined opcodes.
*/
typedef enum __ns_opcode {
ns_o_query = 0, /* Standard query. */
ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */
ns_o_status = 2, /* Name server status query (unsupported). */
/* Opcode 3 is undefined/reserved. */
ns_o_notify = 4, /* Zone change notification. */
ns_o_update = 5, /* Zone update message. */
ns_o_max = 6
} ns_opcode;
/*
* Currently defined response codes.
*/
typedef enum __ns_rcode {
ns_r_noerror = 0, /* No error occurred. */
ns_r_formerr = 1, /* Format error. */
ns_r_servfail = 2, /* Server failure. */
ns_r_nxdomain = 3, /* Name error. */
ns_r_notimpl = 4, /* Unimplemented. */
ns_r_refused = 5, /* Operation refused. */
/* these are for BIND_UPDATE */
ns_r_yxdomain = 6, /* Name exists */
ns_r_yxrrset = 7, /* RRset exists */
ns_r_nxrrset = 8, /* RRset does not exist */
ns_r_notauth = 9, /* Not authoritative for zone */
ns_r_notzone = 10, /* Zone of record different from zone section */
ns_r_max = 11
} ns_rcode;
/* BIND_UPDATE */
typedef enum __ns_update_operation {
ns_uop_delete = 0,
ns_uop_add = 1,
ns_uop_max = 2
} ns_update_operation;
/*
* This RR-like structure is particular to UPDATE.
*/
struct ns_updrec {
struct ns_updrec *r_prev; /* prev record */
struct ns_updrec *r_next; /* next record */
u_int8_t r_section; /* ZONE/PREREQUISITE/UPDATE */
char * r_dname; /* owner of the RR */
u_int16_t r_class; /* class number */
u_int16_t r_type; /* type number */
u_int32_t r_ttl; /* time to live */
u_char * r_data; /* rdata fields as text string */
u_int16_t r_size; /* size of r_data field */
int r_opcode; /* type of operation */
/* following fields for private use by the resolver/server routines */
struct ns_updrec *r_grpnext; /* next record when grouped */
struct databuf *r_dp; /* databuf to process */
struct databuf *r_deldp; /* databuf's deleted/overwritten */
u_int16_t r_zone; /* zone number on server */
};
typedef struct ns_updrec ns_updrec;
/*
* Currently defined type values for resources and queries.
*/
typedef enum __ns_type {
ns_t_a = 1, /* Host address. */
ns_t_ns = 2, /* Authoritative server. */
ns_t_md = 3, /* Mail destination. */
ns_t_mf = 4, /* Mail forwarder. */
ns_t_cname = 5, /* Canonical name. */
ns_t_soa = 6, /* Start of authority zone. */
ns_t_mb = 7, /* Mailbox domain name. */
ns_t_mg = 8, /* Mail group member. */
ns_t_mr = 9, /* Mail rename name. */
ns_t_null = 10, /* Null resource record. */
ns_t_wks = 11, /* Well known service. */
ns_t_ptr = 12, /* Domain name pointer. */
ns_t_hinfo = 13, /* Host information. */
ns_t_minfo = 14, /* Mailbox information. */
ns_t_mx = 15, /* Mail routing information. */
ns_t_txt = 16, /* Text strings. */
ns_t_rp = 17, /* Responsible person. */
ns_t_afsdb = 18, /* AFS cell database. */
ns_t_x25 = 19, /* X_25 calling address. */
ns_t_isdn = 20, /* ISDN calling address. */
ns_t_rt = 21, /* Router. */
ns_t_nsap = 22, /* NSAP address. */
ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */
ns_t_sig = 24, /* Security signature. */
ns_t_key = 25, /* Security key. */
ns_t_px = 26, /* X.400 mail mapping. */
ns_t_gpos = 27, /* Geographical position (withdrawn). */
ns_t_aaaa = 28, /* Ip6 Address. */
ns_t_loc = 29, /* Location Information. */
ns_t_nxt = 30, /* Next domain (security). */
ns_t_eid = 31, /* Endpoint identifier. */
ns_t_nimloc = 32, /* Nimrod Locator. */
ns_t_srv = 33, /* Server Selection. */
ns_t_atma = 34, /* ATM Address */
ns_t_naptr = 35, /* Naming Authority PoinTeR */
ns_t_opt = 41, /* OPT pseudo-RR, RFC2761 */
/* Query type values which do not appear in resource records. */
ns_t_ixfr = 251, /* Incremental zone transfer. */
ns_t_axfr = 252, /* Transfer zone of authority. */
ns_t_mailb = 253, /* Transfer mailbox records. */
ns_t_maila = 254, /* Transfer mail agent records. */
ns_t_any = 255, /* Wildcard match. */
ns_t_max = 65536
} ns_type;
/*
* Values for class field
*/
typedef enum __ns_class {
ns_c_in = 1, /* Internet. */
/* Class 2 unallocated/unsupported. */
ns_c_chaos = 3, /* MIT Chaos-net. */
ns_c_hs = 4, /* MIT Hesiod. */
/* Query class values which do not appear in resource records */
ns_c_none = 254, /* for prereq. sections in update requests */
ns_c_any = 255, /* Wildcard match. */
ns_c_max = 65536
} ns_class;
/*
* Flags field of the KEY RR rdata
*/
#define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */
#define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
#define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
#define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
/* The type bits can also be interpreted independently, as single bits: */
#define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */
#define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */
#define NS_KEY_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
#define NS_KEY_RESERVED3 0x1000 /* reserved - must be zero */
#define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */
#define NS_KEY_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
#define NS_KEY_ENTITY 0x0200 /* key is assoc. with entity eg host */
#define NS_KEY_ZONEKEY 0x0100 /* key is zone key */
#define NS_KEY_IPSEC 0x0080 /* key is for IPSEC (host or user)*/
#define NS_KEY_EMAIL 0x0040 /* key is for email (MIME security) */
#define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */
#define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */
#define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */
#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED3 | \
NS_KEY_RESERVED4 | \
NS_KEY_RESERVED10 | \
NS_KEY_RESERVED11 )
/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
#define NS_ALG_MD5RSA 1 /* MD5 with RSA */
#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */
#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */
/* Signatures */
#define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */
#define NS_MD5RSA_MAX_BITS 2552
/* Total of binary mod and exp */
#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)
/* Max length of text sig block */
#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4)
/* Offsets into SIG record rdata to find various values */
#define NS_SIG_TYPE 0 /* Type flags */
#define NS_SIG_ALG 2 /* Algorithm */
#define NS_SIG_LABELS 3 /* How many labels in name */
#define NS_SIG_OTTL 4 /* Original TTL */
#define NS_SIG_EXPIR 8 /* Expiration time */
#define NS_SIG_SIGNED 12 /* Signature time */
#define NS_SIG_FOOT 16 /* Key footprint */
#define NS_SIG_SIGNER 18 /* Domain name of who signed it */
/* How RR types are represented as bit-flags in NXT records */
#define NS_NXT_BITS 8
#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS)))
/*
* Inline versions of get/put short/long. Pointer is advanced.
*/
#define NS_GET16(s, cp) { \
register u_char *t_cp = (u_char *)(cp); \
(s) = ((u_int16_t)t_cp[0] << 8) \
| ((u_int16_t)t_cp[1]) \
; \
(cp) += NS_INT16SZ; \
}
#define NS_GET32(l, cp) { \
register u_char *t_cp = (u_char *)(cp); \
(l) = ((u_int32_t)t_cp[0] << 24) \
| ((u_int32_t)t_cp[1] << 16) \
| ((u_int32_t)t_cp[2] << 8) \
| ((u_int32_t)t_cp[3]) \
; \
(cp) += NS_INT32SZ; \
}
#define NS_PUT16(s, cp) { \
register u_int16_t t_s = (u_int16_t)(s); \
register u_char *t_cp = (u_char *)(cp); \
*t_cp++ = t_s >> 8; \
*t_cp = t_s; \
(cp) += NS_INT16SZ; \
}
#define NS_PUT32(l, cp) { \
register u_int32_t t_l = (u_int32_t)(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) += NS_INT32SZ; \
}
/*
* ANSI C identifier hiding.
*/
#define ns_get16 __ns_get16
#define ns_get32 __ns_get32
#define ns_put16 __ns_put16
#define ns_put32 __ns_put32
#define ns_initparse __ns_initparse
#define ns_parserr __ns_parserr
#define ns_sprintrr __ns_sprintrr
#define ns_sprintrrf __ns_sprintrrf
#define ns_format_ttl __ns_format_ttl
#define ns_parse_ttl __ns_parse_ttl
#define ns_name_ntop __ns_name_ntop
#define ns_name_pton __ns_name_pton
#define ns_name_unpack __ns_name_unpack
#define ns_name_pack __ns_name_pack
#define ns_name_compress __ns_name_compress
#define ns_name_uncompress __ns_name_uncompress
__BEGIN_DECLS
u_int ns_get16(const u_char *);
u_long ns_get32(const u_char *);
void ns_put16(u_int, u_char *);
void ns_put32(u_long, u_char *);
int ns_initparse(const u_char *, int, ns_msg *);
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
int ns_sprintrr(const ns_msg *, const ns_rr *,
const char *, const char *, char *, size_t);
int ns_sprintrrf(const u_char *, size_t, const char *,
ns_class, ns_type, u_long, const u_char *,
size_t, const char *, const char *,
char *, size_t);
int ns_format_ttl(u_long, char *, size_t);
int ns_parse_ttl(const char *, u_long *);
int ns_name_ntop(const u_char *, char *, size_t);
int ns_name_pton(const char *, u_char *, size_t);
int ns_name_unpack(const u_char *, const u_char *,
const u_char *, u_char *, size_t);
int ns_name_pack(const u_char *, u_char *, int,
const u_char **, const u_char **);
int ns_name_uncompress(const u_char *, const u_char *,
const u_char *, char *, size_t);
int ns_name_compress(const char *, u_char *, size_t,
const u_char **, const u_char **);
int ns_name_skip(const u_char **, const u_char *);
__END_DECLS
#ifdef BIND_4_COMPAT
#include <arpa/nameser_compat.h>
#endif
#endif /* !_ARPA_NAMESER_H_ */
-193
View File
@@ -1,193 +0,0 @@
/* Copyright (c) 1983, 1989
* 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.
*/
/*
* from nameser.h 8.1 (Berkeley) 6/2/93
* From: Id: nameser_compat.h,v 8.9 1998/03/20 23:25:10 halley Exp
*/
#ifndef _ARPA_NAMESER_COMPAT_
#define _ARPA_NAMESER_COMPAT_
#define __BIND 19950621 /* (DEAD) interface version stamp. */
#include <sys/endian.h>
#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;
#define PACKETSZ NS_PACKETSZ
#define MAXDNAME NS_MAXDNAME
#define MAXCDNAME NS_MAXCDNAME
#define MAXLABEL NS_MAXLABEL
#define HFIXEDSZ NS_HFIXEDSZ
#define QFIXEDSZ NS_QFIXEDSZ
#define RRFIXEDSZ NS_RRFIXEDSZ
#define INT32SZ NS_INT32SZ
#define INT16SZ NS_INT16SZ
#define INADDRSZ NS_INADDRSZ
#define IN6ADDRSZ NS_IN6ADDRSZ
#define INDIR_MASK NS_CMPRSFLGS
#define NAMESERVER_PORT NS_DEFAULTPORT
#define S_ZONE ns_s_zn
#define S_PREREQ ns_s_pr
#define S_UPDATE ns_s_ud
#define S_ADDT ns_s_ar
#define QUERY ns_o_query
#define IQUERY ns_o_iquery
#define STATUS ns_o_status
#define NS_NOTIFY_OP ns_o_notify
#define NS_UPDATE_OP ns_o_update
#define NOERROR ns_r_noerror
#define FORMERR ns_r_formerr
#define SERVFAIL ns_r_servfail
#define NXDOMAIN ns_r_nxdomain
#define NOTIMP ns_r_notimpl
#define REFUSED ns_r_refused
#define YXDOMAIN ns_r_yxdomain
#define YXRRSET ns_r_yxrrset
#define NXRRSET ns_r_nxrrset
#define NOTAUTH ns_r_notauth
#define NOTZONE ns_r_notzone
#define DELETE ns_uop_delete
#define ADD ns_uop_add
#define T_A ns_t_a
#define T_NS ns_t_ns
#define T_MD ns_t_md
#define T_MF ns_t_mf
#define T_CNAME ns_t_cname
#define T_SOA ns_t_soa
#define T_MB ns_t_mb
#define T_MG ns_t_mg
#define T_MR ns_t_mr
#define T_NULL ns_t_null
#define T_WKS ns_t_wks
#define T_PTR ns_t_ptr
#define T_HINFO ns_t_hinfo
#define T_MINFO ns_t_minfo
#define T_MX ns_t_mx
#define T_TXT ns_t_txt
#define T_RP ns_t_rp
#define T_AFSDB ns_t_afsdb
#define T_X25 ns_t_x25
#define T_ISDN ns_t_isdn
#define T_RT ns_t_rt
#define T_NSAP ns_t_nsap
#define T_NSAP_PTR ns_t_nsap_ptr
#define T_SIG ns_t_sig
#define T_KEY ns_t_key
#define T_PX ns_t_px
#define T_GPOS ns_t_gpos
#define T_AAAA ns_t_aaaa
#define T_LOC ns_t_loc
#define T_NXT ns_t_nxt
#define T_EID ns_t_eid
#define T_NIMLOC ns_t_nimloc
#define T_SRV ns_t_srv
#define T_ATMA ns_t_atma
#define T_NAPTR ns_t_naptr
#define T_IXFR ns_t_ixfr
#define T_AXFR ns_t_axfr
#define T_MAILB ns_t_mailb
#define T_MAILA ns_t_maila
#define T_ANY ns_t_any
#define C_IN ns_c_in
#define C_CHAOS ns_c_chaos
#define C_HS ns_c_hs
/* BIND_UPDATE */
#define C_NONE ns_c_none
#define C_ANY ns_c_any
#define GETSHORT NS_GET16
#define GETLONG NS_GET32
#define PUTSHORT NS_PUT16
#define PUTLONG NS_PUT32
#endif /* _ARPA_NAMESER_COMPAT_ */
-1
View File
@@ -1 +0,0 @@
/* intentionally empty file */
-206
View File
@@ -1,206 +0,0 @@
/* $NetBSD: mii.h,v 1.9 2001/05/31 03:07:14 thorpej Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer. All rights reserved.
*
* Modification to match BSD/OS 3.0 MII interface by Jason R. Thorpe,
* Numerical Aerospace Simulation Facility, NASA Ames Research Center.
*
* 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 Manuel Bouyer.
* 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.
*
* $FreeBSD: /repoman/r/ncvs/src/sys/dev/mii/mii.h,v 1.4 2002/04/29 11:57:28 phk Exp $
*/
#ifndef _DEV_MII_MII_H_
#define _DEV_MII_MII_H_
/*
* Registers common to all PHYs.
*/
#define MII_NPHY 32 /* max # of PHYs per MII */
/*
* MII commands, used if a device must drive the MII lines
* manually.
*/
#define MII_COMMAND_START 0x01
#define MII_COMMAND_READ 0x02
#define MII_COMMAND_WRITE 0x01
#define MII_COMMAND_ACK 0x02
#define MII_BMCR 0x00 /* Basic mode control register (rw) */
#define BMCR_RESET 0x8000 /* reset */
#define BMCR_LOOP 0x4000 /* loopback */
#define BMCR_SPEED0 0x2000 /* speed selection (LSB) */
#define BMCR_AUTOEN 0x1000 /* autonegotiation enable */
#define BMCR_PDOWN 0x0800 /* power down */
#define BMCR_ISO 0x0400 /* isolate */
#define BMCR_STARTNEG 0x0200 /* restart autonegotiation */
#define BMCR_FDX 0x0100 /* Set duplex mode */
#define BMCR_CTEST 0x0080 /* collision test */
#define BMCR_SPEED1 0x0040 /* speed selection (MSB) */
#define BMCR_S10 0x0000 /* 10 Mb/s */
#define BMCR_S100 BMCR_SPEED0 /* 100 Mb/s */
#define BMCR_S1000 BMCR_SPEED1 /* 1000 Mb/s */
#define BMCR_SPEED(x) ((x) & (BMCR_SPEED0|BMCR_SPEED1))
#define MII_BMSR 0x01 /* Basic mode status register (ro) */
#define BMSR_100T4 0x8000 /* 100 base T4 capable */
#define BMSR_100TXFDX 0x4000 /* 100 base Tx full duplex capable */
#define BMSR_100TXHDX 0x2000 /* 100 base Tx half duplex capable */
#define BMSR_10TFDX 0x1000 /* 10 base T full duplex capable */
#define BMSR_10THDX 0x0800 /* 10 base T half duplex capable */
#define BMSR_100T2FDX 0x0400 /* 100 base T2 full duplex capable */
#define BMSR_100T2HDX 0x0200 /* 100 base T2 half duplex capable */
#define BMSR_EXTSTAT 0x0100 /* Extended status in register 15 */
#define BMSR_MFPS 0x0040 /* MII Frame Preamble Suppression */
#define BMSR_ACOMP 0x0020 /* Autonegotiation complete */
#define BMSR_RFAULT 0x0010 /* Link partner fault */
#define BMSR_ANEG 0x0008 /* Autonegotiation capable */
#define BMSR_LINK 0x0004 /* Link status */
#define BMSR_JABBER 0x0002 /* Jabber detected */
#define BMSR_EXTCAP 0x0001 /* Extended capability */
/*
* Note that the EXTSTAT bit indicates that there is extended status
* info available in register 15, but 802.3 section 22.2.4.3 also
* states that that all 1000 Mb/s capable PHYs will set this bit to 1.
*/
#if 0
#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX|BMSR_10TFDX| \
BMSR_10THDX|BMSR_ANEG)
#else
/* NetBSD uses: */
#define BMSR_MEDIAMASK (BMSR_100T4|BMSR_100TXFDX|BMSR_100TXHDX| \
BMSR_10TFDX|BMSR_10THDX|BMSR_100T2FDX|BMSR_100T2HDX)
#endif
/*
* Convert BMSR media capabilities to ANAR bits for autonegotiation.
* Note the shift chopps off the BMSR_ANEG bit.
*/
#define BMSR_MEDIA_TO_ANAR(x) (((x) & BMSR_MEDIAMASK) >> 6)
#define MII_PHYIDR1 0x02 /* ID register 1 (ro) */
#define MII_PHYIDR2 0x03 /* ID register 2 (ro) */
#define IDR2_OUILSB 0xfc00 /* OUI LSB */
#define IDR2_MODEL 0x03f0 /* vendor model */
#define IDR2_REV 0x000f /* vendor revision */
#define MII_OUI(id1, id2) (((id1) << 6) | ((id2) >> 10))
#define MII_MODEL(id2) (((id2) & IDR2_MODEL) >> 4)
#define MII_REV(id2) ((id2) & IDR2_REV)
#define MII_ANAR 0x04 /* Autonegotiation advertisement (rw) */
/* section 28.2.4.1 and 37.2.6.1 */
#define ANAR_NP 0x8000 /* Next page (ro) */
#define ANAR_ACK 0x4000 /* link partner abilities acknowledged (ro) */
#define ANAR_RF 0x2000 /* remote fault (ro) */
#define ANAR_FC 0x0400 /* local device supports PAUSE */
#define ANAR_T4 0x0200 /* local device supports 100bT4 */
#define ANAR_TX_FD 0x0100 /* local device supports 100bTx FD */
#define ANAR_TX 0x0080 /* local device supports 100bTx */
#define ANAR_10_FD 0x0040 /* local device supports 10bT FD */
#define ANAR_10 0x0020 /* local device supports 10bT */
#define ANAR_CSMA 0x0001 /* protocol selector CSMA/CD */
#define ANAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */
#define ANAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */
#define ANAR_X_PAUSE_NONE (0 << 7)
#define ANAR_X_PAUSE_SYM (1 << 7)
#define ANAR_X_PAUSE_ASYM (2 << 7)
#define ANAR_X_PAUSE_TOWARDS (3 << 7)
#define MII_ANLPAR 0x05 /* Autonegotiation lnk partner abilities (rw) */
/* section 28.2.4.1 and 37.2.6.1 */
#define ANLPAR_NP 0x8000 /* Next page (ro) */
#define ANLPAR_ACK 0x4000 /* link partner accepted ACK (ro) */
#define ANLPAR_RF 0x2000 /* remote fault (ro) */
#define ANLPAR_FC 0x0400 /* link partner supports PAUSE */
#define ANLPAR_T4 0x0200 /* link partner supports 100bT4 */
#define ANLPAR_TX_FD 0x0100 /* link partner supports 100bTx FD */
#define ANLPAR_TX 0x0080 /* link partner supports 100bTx */
#define ANLPAR_10_FD 0x0040 /* link partner supports 10bT FD */
#define ANLPAR_10 0x0020 /* link partner supports 10bT */
#define ANLPAR_CSMA 0x0001 /* protocol selector CSMA/CD */
#define ANLPAR_X_FD 0x0020 /* local device supports 1000BASE-X FD */
#define ANLPAR_X_HD 0x0040 /* local device supports 1000BASE-X HD */
#define ANLPAR_X_PAUSE_MASK (3 << 7)
#define ANLPAR_X_PAUSE_NONE (0 << 7)
#define ANLPAR_X_PAUSE_SYM (1 << 7)
#define ANLPAR_X_PAUSE_ASYM (2 << 7)
#define ANLPAR_X_PAUSE_TOWARDS (3 << 7)
#define MII_ANER 0x06 /* Autonegotiation expansion (ro) */
/* section 28.2.4.1 and 37.2.6.1 */
#define ANER_MLF 0x0010 /* multiple link detection fault */
#define ANER_LPNP 0x0008 /* link parter next page-able */
#define ANER_NP 0x0004 /* next page-able */
#define ANER_PAGE_RX 0x0002 /* Page received */
#define ANER_LPAN 0x0001 /* link parter autoneg-able */
#define MII_ANNP 0x07 /* Autonegotiation next page */
/* section 28.2.4.1 and 37.2.6.1 */
#define MII_ANLPRNP 0x08 /* Autonegotiation link partner rx next page */
/* section 32.5.1 and 37.2.6.1 */
/* This is also the 1000baseT control register */
#define MII_100T2CR 0x09 /* 100base-T2 control register */
#define GTCR_TEST_MASK 0xe000 /* see 802.3ab ss. 40.6.1.1.2 */
#define GTCR_MAN_MS 0x1000 /* enable manual master/slave control */
#define GTCR_ADV_MS 0x0800 /* 1 = adv. master, 0 = adv. slave */
#define GTCR_PORT_TYPE 0x0400 /* 1 = DCE, 0 = DTE (NIC) */
#define GTCR_ADV_1000TFDX 0x0200 /* adv. 1000baseT FDX */
#define GTCR_ADV_1000THDX 0x0100 /* adv. 1000baseT HDX */
/* This is also the 1000baseT status register */
#define MII_100T2SR 0x0a /* 100base-T2 status register */
#define GTSR_MAN_MS_FLT 0x8000 /* master/slave config fault */
#define GTSR_MS_RES 0x4000 /* result: 1 = master, 0 = slave */
#define GTSR_LRS 0x2000 /* local rx status, 1 = ok */
#define GTSR_RRS 0x1000 /* remove rx status, 1 = ok */
#define GTSR_LP_1000TFDX 0x0800 /* link partner 1000baseT FDX capable */
#define GTSR_LP_1000THDX 0x0400 /* link partner 1000baseT HDX capable */
#define GTSR_LP_ASM_DIR 0x0200 /* link partner asym. pause dir. capable */
#define GTSR_IDLE_ERR 0x00ff /* IDLE error count */
#define MII_EXTSR 0x0f /* Extended status register */
#define EXTSR_1000XFDX 0x8000 /* 1000X full-duplex capable */
#define EXTSR_1000XHDX 0x4000 /* 1000X half-duplex capable */
#define EXTSR_1000TFDX 0x2000 /* 1000T full-duplex capable */
#define EXTSR_1000THDX 0x1000 /* 1000T half-duplex capable */
#define EXTSR_MEDIAMASK (EXTSR_1000XFDX|EXTSR_1000XHDX| \
EXTSR_1000TFDX|EXTSR_1000THDX)
#endif /* _DEV_MII_MII_H_ */
-125
View File
@@ -1,125 +0,0 @@
## In contrast to the other headers.am files, this file must be maintained by
## hand.
include_HEADERS += libnetworking/ifaddrs.h
include_HEADERS += libnetworking/librtemsNfs.h
include_HEADERS += libnetworking/loop.h
include_HEADERS += libnetworking/resolv.h
include_arpa_HEADERS += libnetworking/arpa/nameser.h
include_arpa_HEADERS += libnetworking/arpa/nameser_compat.h
include_dev_mii_HEADERS += libnetworking/dev/mii/mii.h
include_machine_HEADERS += libnetworking/machine/_align.h
include_machine_HEADERS += libnetworking/machine/_kernel_if.h
include_machine_HEADERS += libnetworking/machine/_kernel_lock.h
include_machine_HEADERS += libnetworking/machine/_kernel_socket.h
include_machine_HEADERS += libnetworking/machine/cpu.h
include_machine_HEADERS += libnetworking/machine/cpufunc.h
include_machine_HEADERS += libnetworking/machine/in_cksum.h
include_machine_HEADERS += libnetworking/machine/limits.h
include_machine_HEADERS += libnetworking/machine/vmparam.h
include_net_HEADERS += libnetworking/net/bpf.h
include_net_HEADERS += libnetworking/net/ethernet.h
include_net_HEADERS += libnetworking/net/if_arp.h
include_net_HEADERS += libnetworking/net/if_dl.h
include_net_HEADERS += libnetworking/net/if_llc.h
include_net_HEADERS += libnetworking/net/if_media.h
include_net_HEADERS += libnetworking/net/if_ppp.h
include_net_HEADERS += libnetworking/net/if_pppvar.h
include_net_HEADERS += libnetworking/net/if_types.h
include_net_HEADERS += libnetworking/net/if_var.h
include_net_HEADERS += libnetworking/net/netisr.h
include_net_HEADERS += libnetworking/net/ppp_comp.h
include_net_HEADERS += libnetworking/net/ppp_defs.h
include_net_HEADERS += libnetworking/net/radix.h
include_net_HEADERS += libnetworking/net/raw_cb.h
include_net_HEADERS += libnetworking/net/route.h
include_net_HEADERS += libnetworking/net/slcompress.h
include_netinet_HEADERS += libnetworking/netinet/icmp_var.h
include_netinet_HEADERS += libnetworking/netinet/if_ether.h
include_netinet_HEADERS += libnetworking/netinet/igmp.h
include_netinet_HEADERS += libnetworking/netinet/igmp_var.h
include_netinet_HEADERS += libnetworking/netinet/in_pcb.h
include_netinet_HEADERS += libnetworking/netinet/in_systm.h
include_netinet_HEADERS += libnetworking/netinet/in_var.h
include_netinet_HEADERS += libnetworking/netinet/ip.h
include_netinet_HEADERS += libnetworking/netinet/ip_fw.h
include_netinet_HEADERS += libnetworking/netinet/ip_icmp.h
include_netinet_HEADERS += libnetworking/netinet/ip_mroute.h
include_netinet_HEADERS += libnetworking/netinet/ip_var.h
include_netinet_HEADERS += libnetworking/netinet/tcp_debug.h
include_netinet_HEADERS += libnetworking/netinet/tcp_fsm.h
include_netinet_HEADERS += libnetworking/netinet/tcp_seq.h
include_netinet_HEADERS += libnetworking/netinet/tcp_timer.h
include_netinet_HEADERS += libnetworking/netinet/tcp_var.h
include_netinet_HEADERS += libnetworking/netinet/tcpip.h
include_netinet_HEADERS += libnetworking/netinet/udp.h
include_netinet_HEADERS += libnetworking/netinet/udp_var.h
include_nfs_HEADERS += libnetworking/nfs/nfsproto.h
include_nfs_HEADERS += libnetworking/nfs/rpcv2.h
include_nfs_HEADERS += libnetworking/nfs/xdr_subs.h
include_nfsclient_HEADERS += libnetworking/nfsclient/nfsargs.h
include_nfsclient_HEADERS += libnetworking/nfsclient/nfsdiskless.h
include_rpc_HEADERS += libnetworking/rpc/auth.h
include_rpc_HEADERS += libnetworking/rpc/auth_unix.h
include_rpc_HEADERS += libnetworking/rpc/clnt.h
include_rpc_HEADERS += libnetworking/rpc/clnt_soc.h
include_rpc_HEADERS += libnetworking/rpc/clnt_stat.h
include_rpc_HEADERS += libnetworking/rpc/pmap_clnt.h
include_rpc_HEADERS += libnetworking/rpc/pmap_prot.h
include_rpc_HEADERS += libnetworking/rpc/pmap_rmt.h
include_rpc_HEADERS += libnetworking/rpc/rpc.h
include_rpc_HEADERS += libnetworking/rpc/rpc_com.h
include_rpc_HEADERS += libnetworking/rpc/rpc_msg.h
include_rpc_HEADERS += libnetworking/rpc/rpcent.h
include_rpc_HEADERS += libnetworking/rpc/svc.h
include_rpc_HEADERS += libnetworking/rpc/svc_auth.h
include_rpc_HEADERS += libnetworking/rpc/svc_soc.h
include_rpc_HEADERS += libnetworking/rpc/types.h
include_rpc_HEADERS += libnetworking/rpc/xdr.h
include_rtems_HEADERS += libnetworking/rtems/bootp.h
include_rtems_HEADERS += libnetworking/rtems/dhcp.h
include_rtems_HEADERS += libnetworking/rtems/mkrootfs.h
include_rtems_HEADERS += libnetworking/rtems/rtems_bsdnet.h
include_rtems_HEADERS += libnetworking/rtems/rtems_bsdnet_internal.h
include_rtems_HEADERS += libnetworking/rtems/rtems_dhcp_failsafe.h
include_rtems_HEADERS += libnetworking/rtems/rtems_mii_ioctl.h
include_rtems_HEADERS += libnetworking/rtems/rtems_netdb.h
include_rtems_HEADERS += libnetworking/rtems/rtems_netinet_in.h
include_rtems_HEADERS += libnetworking/rtems/rtems_syscall.h
include_rtems_bsdnet_HEADERS += libnetworking/rtems/bsdnet/_types.h
include_rtems_bsdnet_HEADERS += libnetworking/rtems/bsdnet/servers.h
include_sys_HEADERS += libnetworking/sys/callout.h
include_sys_HEADERS += libnetworking/sys/conf.h
include_sys_HEADERS += libnetworking/sys/domain.h
include_sys_HEADERS += libnetworking/sys/kernel.h
include_sys_HEADERS += libnetworking/sys/libkern.h
include_sys_HEADERS += libnetworking/sys/linker_set.h
include_sys_HEADERS += libnetworking/sys/malloc.h
include_sys_HEADERS += libnetworking/sys/mbuf.h
include_sys_HEADERS += libnetworking/sys/mount.h
include_sys_HEADERS += libnetworking/sys/proc.h
include_sys_HEADERS += libnetworking/sys/protosw.h
include_sys_HEADERS += libnetworking/sys/reboot.h
include_sys_HEADERS += libnetworking/sys/resourcevar.h
include_sys_HEADERS += libnetworking/sys/selinfo.h
include_sys_HEADERS += libnetworking/sys/signalvar.h
include_sys_HEADERS += libnetworking/sys/socketvar.h
include_sys_HEADERS += libnetworking/sys/sysctl.h
include_sys_HEADERS += libnetworking/sys/systm.h
include_sys_HEADERS += libnetworking/sys/ucred.h
include_vm_HEADERS += libnetworking/vm/vm.h
include_vm_HEADERS += libnetworking/vm/vm_extern.h
include_vm_HEADERS += libnetworking/vm/vm_kern.h
include_vm_HEADERS += libnetworking/vm/vm_param.h
-56
View File
@@ -1,56 +0,0 @@
/* $FreeBSD: src/include/ifaddrs.h,v 1.3 2003/11/14 18:53:22 bms Exp $ */
/*
* Copyright (c) 1995, 1999
* Berkeley Software Design, Inc. 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.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
*
* BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
*/
#ifndef _IFADDRS_H_
#define _IFADDRS_H_
struct ifaddrs {
struct ifaddrs *ifa_next;
char *ifa_name;
u_int ifa_flags;
struct sockaddr *ifa_addr;
struct sockaddr *ifa_netmask;
struct sockaddr *ifa_dstaddr;
void *ifa_data;
};
/*
* This may have been defined in <net/if.h>. Note that if <net/if.h> is
* to be included it must be included before this header file.
*/
#ifndef ifa_broadaddr
#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
#endif
#include <sys/cdefs.h>
__BEGIN_DECLS
extern int getifaddrs(struct ifaddrs **);
extern void freeifaddrs(struct ifaddrs *);
__END_DECLS
#endif
-384
View File
@@ -1,384 +0,0 @@
#include <machine/rtems-bsd-kernel-space.h>
/*-
* Copyright (c) 1982, 1986, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Mike Karels at Berkeley Software Design, Inc.
*
* Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
* project, to make these variables more userfriendly.
*
* 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.
* 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.
*
* @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
* $FreeBSD: src/sys/kern/kern_mib.c,v 1.74 2005/02/28 21:42:56 wes Exp $
*/
#ifndef __rtems__
#include "opt_posix.h"
#endif
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/sysctl.h>
#include <sys/proc.h>
#ifndef __rtems__
#include <sys/lock.h>
#include <sys/mutex.h>
#include <sys/jail.h>
#include <sys/smp.h>
#endif
#include <sys/unistd.h>
#ifdef __rtems__
char machine[] = "SET ME";
char osrelease[] = RTEMS_VERSION;
char ostype[] = "RTEMS";
#endif
SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
"Sysctl internal magic");
SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0,
"High kernel, proc, limits &c");
#ifndef __rtems__
SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0,
"Virtual memory");
SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW, 0,
"File system");
#endif
SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW, 0,
"Network, (see socket.h)");
#ifndef __rtems__
SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW, 0,
"Debugging");
SYSCTL_NODE(_debug, OID_AUTO, sizeof, CTLFLAG_RW, 0,
"Sizeof various things");
SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW, 0,
"hardware");
SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
"machine dependent");
SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW, 0,
"user-level");
SYSCTL_NODE(, CTL_P1003_1B, p1003_1b, CTLFLAG_RW, 0,
"p1003_1b, (see p1003_1b.h)");
SYSCTL_NODE(, OID_AUTO, compat, CTLFLAG_RW, 0,
"Compatibility code");
SYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0,
"Security");
#ifdef REGRESSION
SYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0,
"Regression test MIB");
#endif
SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD,
kern_ident, 0, "Kernel identifier");
#endif /* __rtems__ */
SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD,
osrelease, 0, "Operating system release");
SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD,
0, BSD, "Operating system revision");
#ifndef __rtems__
SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
version, 0, "Kernel version");
#endif
SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD,
ostype, 0, "Operating system type");
#ifndef __rtems__
extern int osreldate;
SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD,
&osreldate, 0, "Operating system release date");
SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD,
&maxproc, 0, "Maximum number of processes");
SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
&maxprocperuid, 0, "Maximum processes allowed per userid");
SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RD,
&maxusers, 0, "Hint for kernel tuning");
SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD,
0, ARG_MAX, "Maximum bytes of argument to execve(2)");
SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD,
0, _POSIX_VERSION, "Version of POSIX attempting to comply to");
SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD,
0, NGROUPS_MAX, "Maximum number of groups a user can belong to");
SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD,
0, 1, "Whether job control is available");
#ifdef _POSIX_SAVED_IDS
SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
0, 1, "Whether saved set-group/user ID is available");
#else
SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
0, 0, "Whether saved set-group/user ID is available");
#endif
char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */
SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
kernelname, sizeof kernelname, "Name of kernel file booted");
#ifdef SMP
SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
&mp_ncpus, 0, "Number of active CPUs");
#else
SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
0, 1, "Number of active CPUs");
#endif
SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD,
0, BYTE_ORDER, "System byte order");
SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD,
0, PAGE_SIZE, "System memory page size");
static int
sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
{
u_long val;
val = ctob(physmem);
return (sysctl_handle_long(oidp, &val, 0, req));
}
SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
0, 0, sysctl_hw_physmem, "LU", "");
static int
sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
{
u_long val;
val = ctob(physmem - cnt.v_wire_count);
return (sysctl_handle_long(oidp, &val, 0, req));
}
SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
0, 0, sysctl_hw_usermem, "LU", "");
SYSCTL_ULONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
static char machine_arch[] = MACHINE_ARCH;
SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
machine_arch, 0, "System architecture");
char hostname[MAXHOSTNAMELEN];
static int
sysctl_hostname(SYSCTL_HANDLER_ARGS)
{
struct prison *pr;
char tmphostname[MAXHOSTNAMELEN];
int error;
pr = req->td->td_ucred->cr_prison;
if (pr != NULL) {
if (!jail_set_hostname_allowed && req->newptr)
return (EPERM);
/*
* Process is in jail, so make a local copy of jail
* hostname to get/set so we don't have to hold the jail
* mutex during the sysctl copyin/copyout activities.
*/
mtx_lock(&pr->pr_mtx);
bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
mtx_unlock(&pr->pr_mtx);
error = sysctl_handle_string(oidp, tmphostname,
sizeof pr->pr_host, req);
if (req->newptr != NULL && error == 0) {
/*
* Copy the locally set hostname to the jail, if
* appropriate.
*/
mtx_lock(&pr->pr_mtx);
bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
mtx_unlock(&pr->pr_mtx);
}
} else
error = sysctl_handle_string(oidp,
hostname, sizeof hostname, req);
return (error);
}
SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON,
0, 0, sysctl_hostname, "A", "Hostname");
static int regression_securelevel_nonmonotonic = 0;
#ifdef REGRESSION
SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
&regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
#endif
int securelevel = -1;
struct mtx securelevel_mtx;
MTX_SYSINIT(securelevel_lock, &securelevel_mtx, "securelevel mutex lock",
MTX_DEF);
static int
sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
{
struct prison *pr;
int error, level;
pr = req->td->td_ucred->cr_prison;
/*
* If the process is in jail, return the maximum of the global and
* local levels; otherwise, return the global level.
*/
if (pr != NULL) {
mtx_lock(&pr->pr_mtx);
level = imax(securelevel, pr->pr_securelevel);
mtx_unlock(&pr->pr_mtx);
} else
level = securelevel;
error = sysctl_handle_int(oidp, &level, 0, req);
if (error || !req->newptr)
return (error);
/*
* Permit update only if the new securelevel exceeds the
* global level, and local level if any.
*/
if (pr != NULL) {
mtx_lock(&pr->pr_mtx);
if (!regression_securelevel_nonmonotonic &&
(level < imax(securelevel, pr->pr_securelevel))) {
mtx_unlock(&pr->pr_mtx);
return (EPERM);
}
pr->pr_securelevel = level;
mtx_unlock(&pr->pr_mtx);
} else {
mtx_lock(&securelevel_mtx);
if (!regression_securelevel_nonmonotonic &&
(level < securelevel)) {
mtx_unlock(&securelevel_mtx);
return (EPERM);
}
securelevel = level;
mtx_unlock(&securelevel_mtx);
}
return (error);
}
SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
"I", "Current secure level");
char domainname[MAXHOSTNAMELEN];
SYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
&domainname, sizeof(domainname), "Name of the current YP/NIS domain");
u_long hostid;
SYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
/*
* This is really cheating. These actually live in the libc, something
* which I'm not quite sure is a good idea anyway, but in order for
* getnext and friends to actually work, we define dummies here.
*/
SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
"", 0, "PATH that finds all the standard utilities");
SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
0, 0, "Max ibase/obase values in bc(1)");
SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
0, 0, "Max array size in bc(1)");
SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
0, 0, "Max scale value in bc(1)");
SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
0, 0, "Max string length in bc(1)");
SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
0, 0, "Max length (bytes) of a text-processing utility's input line");
SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
0, 0, "Maximum number of repeats of a regexp permitted");
SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
0, 0,
"The version of POSIX 1003.2 with which the system attempts to comply");
SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
0, 0, "Whether C development supports the C bindings option");
SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
0, 0, "Whether system supports the C development utilities option");
SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
0, 0, "");
SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
0, 0, "Whether system supports FORTRAN development utilities");
SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
0, 0, "Whether system supports FORTRAN runtime utilities");
SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
0, 0, "Whether system supports creation of locales");
SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
0, 0, "Whether system supports software development utilities");
SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
0, 0, "Whether system supports the user portability utilities");
SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
0, 0, "Min Maximum number of streams a process may have open at one time");
SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
0, 0, "Min Maximum number of types supported for timezone names");
#include <sys/vnode.h>
SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
0, sizeof(struct vnode), "sizeof(struct vnode)");
SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
0, sizeof(struct proc), "sizeof(struct proc)");
#include <sys/conf.h>
SYSCTL_INT(_debug_sizeof, OID_AUTO, cdev, CTLFLAG_RD,
0, sizeof(struct cdev), "sizeof(struct cdev)");
#include <sys/bio.h>
#include <sys/buf.h>
SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
0, sizeof(struct bio), "sizeof(struct bio)");
SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
0, sizeof(struct buf), "sizeof(struct buf)");
#include <sys/user.h>
SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
#endif /* __rtems__ */
-157
View File
@@ -1,157 +0,0 @@
#include <machine/rtems-bsd-kernel-space.h>
/*
* Copyright (c) 1982, 1986, 1991, 1993
* The Regents of the University of California. All rights reserved.
* (c) UNIX System Laboratories, Inc.
* All or some portions of this file are derived from material licensed
* to the University of California by American Telephone and Telegraph
* Co. or Unix System Laboratories, Inc. and are reproduced herein with
* the permission of UNIX System Laboratories, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. 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.
*
* @(#)kern_subr.c 8.3 (Berkeley) 1/21/94
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/malloc.h>
#include <sys/queue.h>
#include <sys/uio.h>
int
uiomove(void *cp, int n, struct uio *uio)
{
register struct iovec *iov;
u_int cnt;
int error;
#ifdef DIAGNOSTIC
if (uio->uio_rw != UIO_READ && uio->uio_rw != UIO_WRITE)
panic("uiomove: mode");
#endif
while (n > 0 && uio->uio_resid) {
iov = uio->uio_iov;
cnt = iov->iov_len;
if (cnt == 0) {
uio->uio_iov++;
uio->uio_iovcnt--;
continue;
}
if (cnt > n)
cnt = n;
switch (uio->uio_segflg) {
case UIO_USERSPACE:
if (uio->uio_rw == UIO_READ)
error = copyout(cp, iov->iov_base, cnt);
else
error = copyin(iov->iov_base, cp, cnt);
if (error)
return (error);
break;
case UIO_SYSSPACE:
if (uio->uio_rw == UIO_READ)
bcopy((caddr_t)cp, iov->iov_base, cnt);
else
bcopy(iov->iov_base, (caddr_t)cp, cnt);
break;
case UIO_NOCOPY:
break;
}
iov->iov_base += cnt;
iov->iov_len -= cnt;
uio->uio_resid -= cnt;
uio->uio_offset += cnt;
cp += cnt;
n -= cnt;
}
return (0);
}
/*
* General routine to allocate a hash table.
*/
void *
hashinit(elements, type, hashmask)
int elements, type;
u_long *hashmask;
{
long hashsize;
LIST_HEAD(generic, generic) *hashtbl;
int i;
if (elements <= 0)
panic("hashinit: bad elements");
for (hashsize = 1; hashsize <= elements; hashsize <<= 1)
continue;
hashsize >>= 1;
hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, M_WAITOK);
for (i = 0; i < hashsize; i++)
LIST_INIT(&hashtbl[i]);
*hashmask = hashsize - 1;
return (hashtbl);
}
#define NPRIMES 27
static int primes[] = { 1, 13, 31, 61, 127, 251, 509, 761, 1021, 1531, 2039,
2557, 3067, 3583, 4093, 4603, 5119, 5623, 6143, 6653,
7159, 7673, 8191, 12281, 16381, 24571, 32749 };
/*
* General routine to allocate a prime number sized hash table.
*/
void *
phashinit(elements, type, nentries)
int elements, type;
u_long *nentries;
{
long hashsize;
LIST_HEAD(generic, generic) *hashtbl;
int i;
if (elements <= 0)
panic("phashinit: bad elements");
for (i = 1, hashsize = primes[1]; hashsize <= elements;) {
i++;
if (i == NPRIMES)
break;
hashsize = primes[i];
}
hashsize = primes[i - 1];
hashtbl = malloc((u_long)hashsize * sizeof(*hashtbl), type, M_WAITOK);
for (i = 0; i < hashsize; i++)
LIST_INIT(&hashtbl[i]);
*nentries = hashsize;
return (hashtbl);
}
File diff suppressed because it is too large Load Diff
-220
View File
@@ -1,220 +0,0 @@
#include <machine/rtems-bsd-kernel-space.h>
/*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
*/
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/protosw.h>
#include <sys/domain.h>
#include <sys/mbuf.h>
#include <sys/kernel.h>
#include <sys/systm.h>
/*
* System initialization
*
* Note: domain initialization wants to take place on a per domain basis
* as a result of traversing a linker set. Most likely, each domain
* want to call a registration function rather than being handled here
* in domaininit(). Probably this will look like:
*
* SYSINIT(unique, SI_SUB_PROTO_DOMAI, SI_ORDER_ANY, domain_add, xxx)
*
* Where 'xxx' is replaced by the address of a parameter struct to be
* passed to the doamin_add() function.
*/
#if !defined(__rtems__)
static int x_save_spl; /* used by kludge*/
static void kludge_splimp(void *);
static void kludge_splx(void *);
void domaininit(void *);
SYSINIT(splimp, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, kludge_splimp, &x_save_spl)
SYSINIT(domain, SI_SUB_PROTO_DOMAIN, SI_ORDER_FIRST, domaininit, NULL)
SYSINIT(splx, SI_SUB_PROTO_END, SI_ORDER_FIRST, kludge_splx, &x_save_spl)
#endif
static void pffasttimo(void *);
static void pfslowtimo(void *);
struct domain *domains;
#define ADDDOMAIN(x) { \
__CONCAT(x,domain.dom_next) = domains; \
domains = &__CONCAT(x,domain); \
}
/* ARGSUSED*/
void
domaininit(void *dummy)
{
register struct domain *dp;
register struct protosw *pr;
/* - not in our sources
#ifdef ISDN
ADDDOMAIN(isdn);
#endif
*/
for (dp = domains; dp; dp = dp->dom_next) {
if (dp->dom_init)
(*dp->dom_init)();
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++){
#ifdef PRU_OLDSTYLE
/* See comments in uipc_socket2.c. */
if (pr->pr_usrreqs == 0 && pr->pr_ousrreq)
pr->pr_usrreqs = &pru_oldstyle;
#endif
if (pr->pr_init)
(*pr->pr_init)();
}
}
if (max_linkhdr < 16) /* XXX */
max_linkhdr = 16;
max_hdr = max_linkhdr + max_protohdr;
max_datalen = MHLEN - max_hdr;
timeout(pffasttimo, (void *)0, 1);
timeout(pfslowtimo, (void *)0, 1);
}
#if !defined(__rtems__)
/*
* The following two operations are kludge code. Most likely, they should
* be done as a "domainpreinit()" for the first function and then rolled
* in as the last act of "domaininit()" for the second.
*
* In point of fact, it is questionable why other initialization prior
* to this does not also take place at splimp by default.
*/
static void
kludge_splimp(void *udata)
{
int *savesplp = udata;
*savesplp = splimp();
}
static void
kludge_splx(void *udata)
{
int *savesplp = udata;
splx( *savesplp);
}
#endif /* !defined(__rtems__) */
struct protosw *
pffindtype(int family, int type)
{
register struct domain *dp;
register struct protosw *pr;
for (dp = domains; dp; dp = dp->dom_next)
if (dp->dom_family == family)
goto found;
return (0);
found:
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_type && pr->pr_type == type)
return (pr);
return (0);
}
struct protosw *
pffindproto(int family, int protocol, int type)
{
register struct domain *dp;
register struct protosw *pr;
struct protosw *maybe = 0;
if (family == 0)
return (0);
for (dp = domains; dp; dp = dp->dom_next)
if (dp->dom_family == family)
goto found;
return (0);
found:
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) {
if ((pr->pr_protocol == protocol) && (pr->pr_type == type))
return (pr);
if (type == SOCK_RAW && pr->pr_type == SOCK_RAW &&
pr->pr_protocol == 0 && maybe == (struct protosw *)0)
maybe = pr;
}
return (maybe);
}
void
pfctlinput(int cmd, struct sockaddr *sa)
{
register struct domain *dp;
register struct protosw *pr;
for (dp = domains; dp; dp = dp->dom_next)
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_ctlinput)
(*pr->pr_ctlinput)(cmd, sa, (void *)0);
}
static void
pfslowtimo(void *arg)
{
register struct domain *dp;
register struct protosw *pr;
for (dp = domains; dp; dp = dp->dom_next)
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_slowtimo)
(*pr->pr_slowtimo)();
timeout(pfslowtimo, (void *)0, hz/2);
}
static void
pffasttimo(void *arg)
{
register struct domain *dp;
register struct protosw *pr;
for (dp = domains; dp; dp = dp->dom_next)
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_fasttimo)
(*pr->pr_fasttimo)();
timeout(pffasttimo, (void *)0, hz/5);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-1
View File
@@ -1 +0,0 @@
Sources from application-level (as opposed to kernel-level) libraries.
-48
View File
@@ -1,48 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdb.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
static const struct protoent prototab[] = {
{ "ip", NULL, IPPROTO_IP },
{ "icmp", NULL, IPPROTO_ICMP },
{ "tcp", NULL, IPPROTO_TCP },
{ "udp", NULL, IPPROTO_UDP },
};
/*
* Dummy version of BSD getprotobyname()
*/
struct protoent *
getprotobyname_static (const char *name)
{
int i;
for (i = 0 ; i < (sizeof prototab / sizeof prototab[0]) ; i++) {
if (strcmp (name, prototab[i].p_name) == 0)
return (struct protoent *) &prototab[i];
}
return NULL;
}
/*
* Dummy version of BSD getprotobynumber()
*/
struct protoent *
getprotobynumber_static (int proto)
{
int i;
for (i = 0 ; i < (sizeof prototab / sizeof prototab[0]) ; i++) {
if (proto == prototab[i].p_proto)
return (struct protoent *) &prototab[i];
}
return NULL;
}
-219
View File
@@ -1,219 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* Synchronize with an NTP server
*
* This program may be distributed and used for any purpose.
* I ask only that you:
* 1. Leave this author information intact.
* 2. Document any changes you make.
*
* W. Eric Norum
* Canadian Light Source
* University of Saskatchewan
* Saskatoon, Saskatchewan, CANADA
* eric@cls.usask.ca
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h> /* close */
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <limits.h>
#include <rtems.h>
#include <rtems/rtems_bsdnet.h>
#include <rtems/error.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <rtems/bsdnet/servers.h>
/*
* RTEMS base: 1988, January 1
* UNIX base: 1970, January 1
* NTP base: 1900, January 1
*/
#define UNIX_BASE_TO_NTP_BASE (uint32_t)(((70UL*365UL)+17UL) * (24UL*60UL*60UL))
struct ntpPacket {
struct ntpPacketSmall ntp;
char authenticator[96];
};
static int
processPacket (struct ntpPacketSmall *p, int state, void *unused)
{
time_t tbuf;
struct tm *lt;
rtems_time_of_day rt;
rtems_interval ticks_per_second;
if ( state )
return 0;
ticks_per_second = rtems_clock_get_ticks_per_second();
tbuf = ntohl (p->transmit_timestamp.integer) - UNIX_BASE_TO_NTP_BASE - rtems_bsdnet_timeoffset;
lt = gmtime (&tbuf);
rt.year = lt->tm_year + 1900;
rt.month = lt->tm_mon + 1;
rt.day = lt->tm_mday;
rt.hour = lt->tm_hour;
rt.minute = lt->tm_min;
rt.second = lt->tm_sec;
rt.ticks = ntohl (p->transmit_timestamp.fraction) / (ULONG_MAX / ticks_per_second);
if (rt.ticks >= ticks_per_second)
rt.ticks = ticks_per_second - 1;
rtems_clock_set (&rt);
return 0;
}
static int
getServerTimespec(struct ntpPacketSmall *p, int state, void *usr_data)
{
struct timespec *ts = usr_data;
unsigned long long tmp;
if ( 0 == state ) {
ts->tv_sec = ntohl( p->transmit_timestamp.integer );
ts->tv_sec -= rtems_bsdnet_timeoffset + UNIX_BASE_TO_NTP_BASE;
tmp = 1000000000 * (unsigned long long)ntohl(p->transmit_timestamp.fraction);
ts->tv_nsec = (unsigned long) (tmp>>32);
}
return 0;
}
int rtems_bsdnet_ntp_retry_count = 5;
int rtems_bsdnet_ntp_timeout_secs = 5;
int rtems_bsdnet_ntp_bcast_timeout_secs = 80;
static int
tryServer (int i, int s, rtems_bsdnet_ntp_callback_t callback, void *usr_data)
{
int l = 0;
struct timeval tv;
socklen_t farlen;
struct sockaddr_in farAddr;
struct ntpPacketSmall packet;
if (i < 0)
tv.tv_sec = rtems_bsdnet_ntp_bcast_timeout_secs;
else
tv.tv_sec = rtems_bsdnet_ntp_timeout_secs;
tv.tv_usec = 0;
if (setsockopt (s, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof tv) < 0) {
fprintf (stderr, "rtems_bsdnet_get_ntp() Can't set socket receive timeout: %s\n", strerror (errno));
close (s);
return -1;
}
if (i >= 0) {
memset (&farAddr, 0, sizeof farAddr);
farAddr.sin_family = AF_INET;
farAddr.sin_port = htons (123);
farAddr.sin_addr = rtems_bsdnet_ntpserver[i];
memset (&packet, 0, sizeof packet);
packet.li_vn_mode = (3 << 3) | 3; /* NTP version 3, client */
if ( callback( &packet, 1, usr_data ) )
return -1;
l = sendto (s, &packet, sizeof packet, 0, (struct sockaddr *)&farAddr, sizeof farAddr);
if (l != sizeof packet) {
fprintf (stderr, "rtems_bsdnet_get_ntp() Can't send: %s\n", strerror (errno));
return -1;
}
} else {
if ( callback( &packet, -1, usr_data ) )
return -1;
}
farlen = sizeof farAddr;
i = recvfrom (s, &packet, sizeof packet, 0, (struct sockaddr *)&farAddr, &farlen);
if (i == 0)
fprintf (stderr, "rtems_bsdnet_get_ntp() Unexpected EOF");
if (i < 0) {
if ((errno == EWOULDBLOCK) || (errno == EAGAIN))
return -1;
fprintf (stderr, "rtems_bsdnet_get_ntp() Can't receive: %s\n", strerror (errno));
}
if ( i >= sizeof packet &&
(((packet.li_vn_mode & (0x7 << 3)) == (3 << 3)) ||
((packet.li_vn_mode & (0x7 << 3)) == (4 << 3))) &&
((packet.transmit_timestamp.integer != 0) || (packet.transmit_timestamp.fraction != 0)) &&
0 == callback( &packet, 0 , usr_data) )
return 0;
return -1;
}
int rtems_bsdnet_get_ntp(int sock, rtems_bsdnet_ntp_callback_t callback, void *usr_data)
{
int s = -1;
int i;
int retry;
struct sockaddr_in myAddr;
int reuseFlag;
int ret;
if ( !callback )
callback = getServerTimespec;
if ( sock < 0 ) {
s = socket (AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
fprintf (stderr, "rtems_bsdnet_get_ntp() Can't create socket: %s\n", strerror (errno));
return -1;
}
reuseFlag = 1;
if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char *)&reuseFlag, sizeof reuseFlag) < 0) {
fprintf (stderr, "rtems_bsdnet_get_ntp() Can't set socket reuse: %s\n", strerror (errno));
close (s);
return -1;
}
memset (&myAddr, 0, sizeof myAddr);
myAddr.sin_family = AF_INET;
myAddr.sin_port = htons (123);
myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0) {
fprintf (stderr, "rtems_bsdnet_get_ntp() Can't bind socket: %s\n", strerror (errno));
close (s);
return -1;
}
sock = s;
}
ret = -1;
for (retry = 0 ; (ret == -1) && (retry < rtems_bsdnet_ntp_retry_count) ; retry++) {
/*
* If there's no server we just have to wait
* and hope that there's an NTP broadcast
* server out there somewhere.
*/
if (rtems_bsdnet_ntpserver_count <= 0) {
ret = tryServer (-1, sock, callback, usr_data);
}
else {
for (i = 0 ; (ret == -1) && (i < rtems_bsdnet_ntpserver_count) ; i++) {
ret = tryServer (i, sock, callback, usr_data);
}
}
}
if ( s >= 0 )
close (s);
return ret;
}
int
rtems_bsdnet_synchronize_ntp (int interval, rtems_task_priority priority)
{
if (interval != 0) {
fprintf (stderr, "Daemon-mode note yet supported.\n");
errno = EINVAL;
return -1;
}
return rtems_bsdnet_get_ntp( -1, processPacket, 0);
}
-170
View File
@@ -1,170 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* RTEMS version of syslog and associated routines
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/thread.h>
#include <stdio.h>
#include <stdarg.h>
#include <errno.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <unistd.h>
static int LogStatus = LOG_CONS;
static const char *LogTag = "syslog";
static int LogFacility = LOG_USER;
static int LogMask = 0xff;
static int LogFd = -1;
static rtems_recursive_mutex LogSemaphore =
RTEMS_RECURSIVE_MUTEX_INITIALIZER("syslog");
extern struct in_addr rtems_bsdnet_log_host_address;
#define SYSLOG_PORT 514
void
syslog (int pri, const char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
vsyslog (pri, fmt, ap);
va_end (ap);
}
/*
* FIXME: Should cbuf be static? It could be if we put the mutex
* around the entire body of this routine. Then we wouldn't
* have to worry about blowing stacks with a local variable
* that large. Could make cbuf bigger, too.
*/
void
vsyslog (int pri, const char *fmt, va_list ap)
{
int cnt;
char *msgp, cbuf[200];
int sent;
if (pri & ~(LOG_PRIMASK|LOG_FACMASK)) {
syslog (LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID,
"syslog: unknown facility/priority: %#x", pri);
pri &= LOG_PRIMASK|LOG_FACMASK;
}
if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
return;
if ((pri & LOG_FACMASK) == 0)
pri |= LogFacility;
cnt = snprintf (cbuf, sizeof (cbuf), "<%d>", pri);
msgp = cbuf + (cnt < sizeof (cbuf) ? cnt : sizeof (cbuf) - 1);
if (LogTag && cnt < sizeof (cbuf) - 1)
cnt += snprintf (cbuf + cnt, sizeof (cbuf) - cnt, "%s", LogTag);
if (LogStatus & LOG_PID && cnt < sizeof (cbuf) - 1) {
rtems_id tid;
rtems_task_ident (RTEMS_SELF, 0, &tid);
cnt += snprintf (cbuf + cnt, sizeof (cbuf) - cnt, "[%#lx]", (unsigned long)tid);
}
if (LogTag && cnt < sizeof (cbuf) - 1)
cnt += snprintf (cbuf + cnt, sizeof (cbuf) - cnt, ": ");
cnt += vsnprintf (cbuf + cnt, sizeof (cbuf) - cnt, fmt, ap);
if (cnt > sizeof (cbuf) - 1)
cnt = sizeof (cbuf) - 1;
while (cnt > 0 && cbuf[cnt-1] == '\n')
cbuf[--cnt] = '\0';
if (LogStatus & LOG_PERROR)
printf ("%s\n", cbuf);
/*
* Grab the mutex
*/
sent = 0;
if ((rtems_bsdnet_log_host_address.s_addr != INADDR_ANY)
&& (LogFd >= 0)) {
/*
* Set the destination address/port
*/
struct sockaddr_in farAddress;
farAddress.sin_family = AF_INET;
farAddress.sin_port = htons (SYSLOG_PORT);
farAddress.sin_addr = rtems_bsdnet_log_host_address;
memset (farAddress.sin_zero, '\0', sizeof farAddress.sin_zero);
rtems_recursive_mutex_lock (&LogSemaphore);
/*
* Send the message
*/
if (sendto (LogFd, cbuf, cnt, 0, (struct sockaddr *)&farAddress, sizeof farAddress) >= 0)
sent = 1;
rtems_recursive_mutex_unlock (&LogSemaphore);
}
if (!sent && (LogStatus & LOG_CONS) && !(LogStatus & LOG_PERROR))
printf ("%s\n", msgp);
}
void
openlog (const char *ident, int logstat, int logfac)
{
struct sockaddr_in myAddress;
if (ident != NULL)
LogTag = ident;
LogStatus = logstat;
if (logfac != 0 && (logfac & ~LOG_FACMASK) == 0)
LogFacility = logfac;
/*
* Create the socket
*/
if ((LogFd = socket (AF_INET, SOCK_DGRAM, 0)) < 0) {
printf ("Can't create syslog socket: %d\n", errno);
return;
}
/*
* Bind socket to name
*/
myAddress.sin_family = AF_INET;
myAddress.sin_addr.s_addr = INADDR_ANY;
myAddress.sin_port = htons (SYSLOG_PORT);;
memset (myAddress.sin_zero, '\0', sizeof myAddress.sin_zero);
if (bind (LogFd, (struct sockaddr *)&myAddress, sizeof (myAddress)) < 0) {
close (LogFd);
LogFd = -1;
printf ("Can't bind syslog socket: %d\n", errno);
return;
}
}
void
closelog(void)
{
if (LogFd >= 0) {
close (LogFd);
LogFd = -1;
}
}
int
setlogmask (int pmask)
{
int omask;
omask = LogMask;
if (pmask != 0)
LogMask = pmask;
return (omask);
}
-318
View File
@@ -1,318 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* Copyright (c) 1996, 1998 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Portions Copyright (c) 1995 by International Business Machines, Inc.
*
* International Business Machines, Inc. (hereinafter called IBM) grants
* permission under its copyrights to use, copy, modify, and distribute this
* Software with or without fee, provided that the above copyright notice and
* all paragraphs of this notice appear in all copies, and that the name of IBM
* not be used in connection with the marketing of any product incorporating
* the Software or modifications thereof, without specific, written prior
* permission.
*
* To the extent it has a right to do so, IBM grants an immunity from suit
* under its patents, if any, for the use, sale or manufacture of products to
* the extent that such products are used for performing Domain Name System
* dynamic updates in TCP/IP networks by means of the Software. No immunity is
* granted for any product per se or for any other function of any product.
*
* THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
* DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
* IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <ctype.h>
#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define Assert(Cond) if (!(Cond)) abort()
static const char Base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
The following encoding technique is taken from RFC 1521 by Borenstein
and Freed. It is reproduced here in a slightly edited form for
convenience.
A 65-character subset of US-ASCII is used, enabling 6 bits to be
represented per printable character. (The extra 65th character, "=",
is used to signify a special processing function.)
The encoding process represents 24-bit groups of input bits as output
strings of 4 encoded characters. Proceeding from left to right, a
24-bit input group is formed by concatenating 3 8-bit input groups.
These 24 bits are then treated as 4 concatenated 6-bit groups, each
of which is translated into a single digit in the base64 alphabet.
Each 6-bit group is used as an index into an array of 64 printable
characters. The character referenced by the index is placed in the
output string.
Table 1: The Base64 Alphabet
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
Special processing is performed if fewer than 24 bits are available
at the end of the data being encoded. A full encoding quantum is
always completed at the end of a quantity. When fewer than 24 input
bits are available in an input group, zero bits are added (on the
right) to form an integral number of 6-bit groups. Padding at the
end of the data is performed using the '=' character.
Since all base64 input is an integral number of octets, only the
-------------------------------------------------
following cases can arise:
(1) the final quantum of encoding input is an integral
multiple of 24 bits; here, the final unit of encoded
output will be an integral multiple of 4 characters
with no "=" padding,
(2) the final quantum of encoding input is exactly 8 bits;
here, the final unit of encoded output will be two
characters followed by two "=" padding characters, or
(3) the final quantum of encoding input is exactly 16 bits;
here, the final unit of encoded output will be three
characters followed by one "=" padding character.
*/
int
b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
size_t datalength = 0;
u_char input[3];
u_char output[4];
size_t i;
while (2 < srclength) {
input[0] = *src++;
input[1] = *src++;
input[2] = *src++;
srclength -= 3;
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
output[3] = input[2] & 0x3f;
Assert(output[0] < 64);
Assert(output[1] < 64);
Assert(output[2] < 64);
Assert(output[3] < 64);
if (datalength + 4 > targsize)
return (-1);
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
target[datalength++] = Base64[output[2]];
target[datalength++] = Base64[output[3]];
}
/* Now we worry about padding. */
if (0 != srclength) {
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
for (i = 0; i < srclength; i++)
input[i] = *src++;
output[0] = input[0] >> 2;
output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
Assert(output[0] < 64);
Assert(output[1] < 64);
Assert(output[2] < 64);
if (datalength + 4 > targsize)
return (-1);
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
if (srclength == 1)
target[datalength++] = Pad64;
else
target[datalength++] = Base64[output[2]];
target[datalength++] = Pad64;
}
if (datalength >= targsize)
return (-1);
target[datalength] = '\0'; /* Returned value doesn't count \0. */
return (datalength);
}
/* skips all whitespace anywhere.
converts characters, four at a time, starting at (or after)
src from base - 64 numbers into three 8 bit bytes in the target area.
it returns the number of data bytes stored at the target, or -1 on error.
*/
int
b64_pton(
char const *src,
u_char *target,
size_t targsize)
{
int tarindex, state, ch;
char *pos;
state = 0;
tarindex = 0;
while ((ch = *src++) != '\0') {
if (isspace(ch)) /* Skip whitespace anywhere. */
continue;
if (ch == Pad64)
break;
pos = strchr(Base64, ch);
if (pos == 0) /* A non-base64 character. */
return (-1);
switch (state) {
case 0:
if (target) {
if ((size_t)tarindex >= targsize)
return (-1);
target[tarindex] = (pos - Base64) << 2;
}
state = 1;
break;
case 1:
if (target) {
if ((size_t)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 ((size_t)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 ((size_t)tarindex >= targsize)
return (-1);
target[tarindex] |= (pos - Base64);
}
tarindex++;
state = 0;
break;
default:
abort();
}
}
/*
* We are done decoding Base-64 chars. Let's see if we ended
* on a byte boundary, and/or with erroneous trailing characters.
*/
if (ch == Pad64) { /* We got a pad char. */
ch = *src++; /* Skip it, get next. */
switch (state) {
case 0: /* Invalid = in first position */
case 1: /* Invalid = in second position */
return (-1);
case 2: /* Valid, means one byte of info */
/* Skip any number of spaces. */
for ((void)NULL; ch != '\0'; ch = *src++)
if (!isspace(ch))
break;
/* Make sure there is another trailing = sign. */
if (ch != Pad64)
return (-1);
ch = *src++; /* Skip the = */
/* Fall through to "single trailing =" case. */
/* FALLTHROUGH */
case 3: /* Valid, means two bytes of info */
/*
* We know this char is an =. Is there anything but
* whitespace after it?
*/
for ((void)NULL; ch != '\0'; ch = *src++)
if (!isspace(ch))
return (-1);
/*
* Now make sure for cases 2 and 3 that the "extra"
* bits that slopped past the last full byte were
* zeros. If we don't check them, they become a
* subliminal channel.
*/
if (target && target[tarindex] != 0)
return (-1);
}
} else {
/*
* We ended by seeing the end of the string. Make sure we
* have no partial bytes lying around.
*/
if (state != 0)
return (-1);
}
return (tarindex);
}
-76
View File
@@ -1,76 +0,0 @@
.\" Copyright (c) 1983, 1991, 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.
.\"
.\" @(#)byteorder.3 8.1 (Berkeley) 6/4/93
.\"
.Dd June 4, 1993
.Dt BYTEORDER 3
.Os BSD 4.2
.Sh NAME
.Nm htonl ,
.Nm htons ,
.Nm ntohl ,
.Nm ntohs
.Nd convert values between host and network byte order
.Sh SYNOPSIS
.Fd #include <sys/param.h>
.Ft u_long
.Fn htonl "u_long hostlong"
.Ft u_short
.Fn htons "u_short hostshort"
.Ft u_long
.Fn ntohl "u_long netlong"
.Ft u_short
.Fn ntohs "u_short netshort"
.Sh DESCRIPTION
These routines convert 16 and 32 bit quantities between network
byte order and host byte order.
On machines which have a byte order which is the same as the network
order, routines are defined as null macros.
.Pp
These routines are most often used in conjunction with Internet
addresses and ports as returned by
.Xr gethostbyname 3
and
.Xr getservent 3 .
.Sh SEE ALSO
.Xr gethostbyname 3 ,
.Xr getservent 3
.Sh HISTORY
The
.Nm byteorder
functions appeared in
.Bx 4.2 .
.Sh BUGS
On the
.Tn VAX
bytes are handled backwards from most everyone else in
the world. This is not expected to be fixed in the near future.
-192
View File
@@ -1,192 +0,0 @@
.\" Copyright (c) 1995
.\" Bill Paul <wpaul@ctr.columbia.edu>. 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 Bill Paul.
.\" 4. Neither the name of the author nor the names of any co-contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY Bill Paul 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.
.\"
.\"
.Dd April 12, 1995
.Dt ETHERS 3
.Os FreeBSD 2.1
.Sh NAME
.Nm ethers ,
.Nm ether_line ,
.Nm ether_aton ,
.Nm ether_ntoa ,
.Nm ether_ntohost ,
.Nm ether_hostton
.Nd Ethernet address conversion and lookup routines
.Sh SYNOPSIS
.Fd #include <sys/types.h>
.Fd #include <sys/socket.h>
.Fd #include <net/ethernet.h>
.Ft int
.Fn ether_line "char *l" "struct ether_addr *e" "char *hostname"
.Ft struct ether_addr *
.Fn ether_aton "char *a"
.Ft char *
.Fn ether_ntoa "struct ether_addr *n"
.Ft int
.Fn ether_ntohost "char *hostname" "struct ether_addr *e"
.Ft int
.Fn ether_hostton "char *hostname" "struct ether_addr *e"
.Sh DESCRIPTION
These functions operate on ethernet addresses using an
.Ar ether_addr
structure, which is defined in the header file
.Aq Pa netinet/if_ether.h :
.Bd -literal -offset indent
/*
* The number of bytes in an ethernet (MAC) address.
*/
#define ETHER_ADDR_LEN 6
/*
* Structure of a 48-bit Ethernet address.
*/
struct ether_addr {
u_char octet[ETHER_ADDR_LEN];
};
.Ed
.Pp
The function
.Fn ether_line
scans
.Ar l ,
an
.Tn ASCII
string in
.Xr ethers 5
format and sets
.Ar e
to the ethernet address specified in the string and
.Ar h
to the hostname. This function is used to parse lines from
.Pa /etc/ethers
into their component parts.
.Pp
The
.Fn ether_aton
function converts an
.Tn ASCII
representation of an ethernet address into an
.Ar ether_addr
structure. Likewise,
.Fn ether_ntoa
converts an ethernet address specified as an
.Ar ether_addr
structure into an
.Tn ASCII
string.
.Pp
The
.Fn ether_ntohost
and
.Fn ether_hostton
functions map ethernet addresses to their corresponding hostnames
as specified in the
.Pa /etc/ethers
database.
.Fn ether_ntohost
converts from ethernet address to hostname, and
.Fn ether_hostton
converts from hostname to ethernet address.
.Sh RETURN VALUES
.Fn ether_line
returns zero on success and non-zero if it was unable to parse
any part of the supplied line
.Ar l .
It returns the extracted ethernet address in the supplied
.Ar ether_addr
structure
.Ar e
and the hostname in the supplied string
.Ar h .
.Pp
On success,
.Fn ether_ntoa
returns a pointer to a string containing an
.Tn ASCII
representation of an ethernet address. If it is unable to convert
the supplied
.Ar ether_addr
structure, it returns a
.Dv NULL
pointer. Likewise,
.Fn ether_aton
returns a pointer to an
.Ar ether_addr
structure on success and a
.Dv NULL
pointer on failure.
.Pp
The
.Fn ether_ntohost
and
.Fn ether_hostton
functions both return zero on success or non-zero if they were
unable to find a match in the
.Pa /etc/ethers
database.
.Sh NOTES
The user must insure that the hostname strings passed to the
the
.Fn ether_line ,
.Fn ether_ntohost
and
.Fn ether_hostton
functions are large enough to contain the returned hostnames.
.Sh NIS INTERACTION
If the
.Pa /etc/ethers
contains a line with a single + in it, the
.Fn ether_ntohost
and
.Fn ether_hostton
functions will attempt to consult the NIS
.Pa ethers.byname
and
.Pa ethers.byaddr
maps in addition to the data in the
.Pa /etc/ethers
file.
.Sh SEE ALSO
.Xr yp 4 ,
.Xr ethers 5
.Sh BUGS
.Pp
The
.Fn ether_aton
and
.Fn ether_ntoa
functions returns values that are stored in static memory areas
which may be overwritten the next time they are called.
.Sh HISTORY
This particular implementation of the
.Nm ethers
library functions were written for and first appeared in
.Fx 2.1 .
File diff suppressed because it is too large Load Diff
-349
View File
@@ -1,349 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*-
* Copyright (c) 1985, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* -
* --Copyright--
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <rtems/rtems_netdb.h>
#include <stdio.h>
#include <stdlib.h> /* realloc, malloc, free */
#include <ctype.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <arpa/nameser.h> /* XXX */
#include <resolv.h> /* XXX */
#include <sys/fcntl.h>
#define MAXALIASES 35
static struct hostent host;
static char *host_aliases[MAXALIASES];
static char hostbuf[BUFSIZ+1];
static FILE *hostf = NULL;
static u_char host_addr[16]; /* IPv4 or IPv6 */
static char *h_addr_ptrs[2];
static int stayopen = 0;
#ifdef _THREAD_SAFE
static char* hostmap = NULL;
static unsigned int hostlen = 0;
static char *cur;
#endif
void
_sethosthtent(int f)
{
if (!hostf)
hostf = fopen(_PATH_HOSTS, "r" );
else
rewind(hostf);
stayopen = f;
}
void
_endhosthtent(void)
{
if (hostf && !stayopen) {
(void) fclose(hostf);
hostf = NULL;
}
}
struct hostent *
gethostent(void)
{
char *p;
register char *cp, **q;
int af, len;
if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
h_errno = NETDB_INTERNAL;
return (NULL);
}
again:
if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
h_errno = HOST_NOT_FOUND;
return (NULL);
}
if (*p == '#')
goto again;
if (!(cp = strpbrk(p, "#\n")))
goto again;
*cp = '\0';
if (!(cp = strpbrk(p, " \t")))
goto again;
*cp++ = '\0';
if (inet_pton(AF_INET6, p, host_addr) > 0) {
af = AF_INET6;
len = IN6ADDRSZ;
} else if (inet_pton(AF_INET, p, host_addr) > 0) {
if (_res.options & RES_USE_INET6) {
_map_v4v6_address((char*)host_addr, (char*)host_addr);
af = AF_INET6;
len = IN6ADDRSZ;
} else {
af = AF_INET;
len = INADDRSZ;
}
} else {
goto again;
}
h_addr_ptrs[0] = (char *)host_addr;
h_addr_ptrs[1] = NULL;
host.h_addr_list = h_addr_ptrs;
host.h_length = len;
host.h_addrtype = af;
while (*cp == ' ' || *cp == '\t')
cp++;
host.h_name = cp;
q = host.h_aliases = host_aliases;
if ((cp = strpbrk(cp, " \t")) != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &host_aliases[MAXALIASES - 1])
*q++ = cp;
if ((cp = strpbrk(cp, " \t")) != NULL)
*cp++ = '\0';
}
*q = NULL;
h_errno = NETDB_SUCCESS;
return (&host);
}
struct hostent *
_gethostbyhtname(
const char *name,
int af)
{
register struct hostent *p;
register char **cp;
sethostent(0);
while ((p = gethostent()) != NULL) {
if (p->h_addrtype != af)
continue;
if (strcasecmp(p->h_name, name) == 0)
break;
for (cp = p->h_aliases; *cp != 0; cp++)
if (strcasecmp(*cp, name) == 0)
goto found;
}
found:
endhostent();
return (p);
}
struct hostent *
_gethostbyhtaddr(
const char *addr,
int len,
int af)
{
register struct hostent *p;
sethostent(0);
while ((p = gethostent()) != NULL)
if (p->h_addrtype == af && !bcmp(p->h_addr, addr, len))
break;
endhostent();
return (p);
}
#ifdef _THREAD_SAFE
int
gethostent_r(
struct hostent *pe,
char *buf,
size_t len,
struct hostent **result,
int *h_errnop)
{
char *dest;
char* last;
char* max=buf+len;
int aliasidx;
int curlen;
int rv;
if (pe == NULL || buf == NULL || result == NULL || h_errnop == NULL) {
if (h_errnop != NULL) {
*h_errnop = NETDB_INTERNAL;
}
return EINVAL;
}
*result = NULL;
*h_errnop = NETDB_INTERNAL;
rv = -1;
if (!hostf) {
rv = ENOENT;
return rv;
}
fseek(hostf,0,SEEK_END);
curlen=ftell(hostf);
fseek(hostf,0,SEEK_SET);
if (curlen > hostlen) {
if (hostmap) {
hostmap = realloc(hostmap,curlen);
}
else {
hostmap = malloc(curlen);
}
}
hostlen = curlen;
if (hostmap) {
if (fread(hostmap,hostlen,1,hostf) != hostlen) {
hostmap=0; goto error;
}
cur=hostmap;
}
last=hostmap+hostlen;
again:
if ((size_t)len<sizeof(struct hostent)+11*sizeof(char*)) goto nospace;
dest=buf;
pe->h_name=0;
pe->h_aliases=(char**)dest; pe->h_aliases[0]=0; dest+=10*sizeof(char*);
pe->h_addr_list=(char**)dest; dest+=2*sizeof(char**);
if (cur>=last) {
rv = ERANGE;
return rv;
}
if (*cur=='#' || *cur=='\n') goto parseerror;
/* first, the ip number */
pe->h_name=cur;
while (cur<last && !isspace((unsigned char)*cur)) cur++;
if (cur>=last) {
rv = ERANGE;
return rv;
}
if (*cur=='\n') goto parseerror;
{
char save=*cur;
*cur=0;
pe->h_addr_list[0]=dest;
pe->h_addr_list[1]=0;
if (max-dest<16) goto nospace;
if (inet_pton(AF_INET6,pe->h_name,dest)>0) {
pe->h_addrtype=AF_INET6;
pe->h_length=16;
dest+=16;
} else if (inet_pton(AF_INET,pe->h_name,dest)>0) {
pe->h_addrtype=AF_INET;
pe->h_length=4;
dest+=4;
} else {
*cur=save;
goto parseerror;
}
*cur=save;
}
++cur;
/* now the aliases */
for (aliasidx=0;aliasidx<9;++aliasidx) {
while (cur<last && isblank((unsigned char)*cur)) ++cur;
pe->h_aliases[aliasidx]=cur;
while (cur<last && !isspace((unsigned char)*cur)) ++cur;
{
char *from=pe->h_aliases[aliasidx];
int len=cur-from;
if (max-dest<len+2) goto nospace;
pe->h_aliases[aliasidx]=dest;
memmove(dest,from,(size_t)(cur-from));
dest+=len;
*dest=0; ++dest;
}
if (*cur=='\n') { ++cur; ++aliasidx; break; }
if (cur>=last || !isblank((unsigned char)*cur)) break;
cur++;
}
pe->h_aliases[aliasidx]=0;
pe->h_name=pe->h_aliases[0];
pe->h_aliases++;
*result = pe;
*h_errnop = 0;
rv = 0;
return rv;
parseerror:
while (cur<last && *cur!='\n') cur++;
cur++;
goto again;
nospace:
rv=ERANGE;
goto __error;
error:
rv=ENOMEM;
__error:
if (hostmap!=NULL) free(hostmap);
hostmap=NULL;
return rv;
}
#endif
-304
View File
@@ -1,304 +0,0 @@
.\" Copyright (c) 1983, 1987, 1991, 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.
.\"
.\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95
.\"
.Dd May 25, 1995
.Dt GETHOSTBYNAME 3
.Os BSD 4.2
.Sh NAME
.Nm gethostbyname ,
.Nm gethostbyname2 ,
.Nm gethostbyaddr ,
.Nm gethostent ,
.Nm sethostent ,
.Nm endhostent ,
.Nm herror ,
.Nm hstrerror
.Nd get network host entry
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Vt extern int h_errno;
.Ft struct hostent *
.Fn gethostbyname "const char *name"
.Ft struct hostent *
.Fn gethostbyname2 "const char *name" "int af"
.Ft struct hostent *
.Fn gethostbyaddr "const char *addr" "int len" "int type"
.Ft struct hostent *
.Fn gethostent void
.Ft void
.Fn sethostent "int stayopen"
.Ft void
.Fn endhostent void
.Ft void
.Fn herror "const char *string"
.Ft const char *
.Fn hstrerror "int err"
.Sh DESCRIPTION
The
.Fn gethostbyname ,
.Fn gethostbyname2
and
.Fn gethostbyaddr
functions
each return a pointer to an object with the
following structure describing an internet host
referenced by name or by address, respectively.
This structure contains either the information obtained from the name server,
.Xr named 8 ,
or broken-out fields from a line in
.Pa /etc/hosts .
If the local name server is not running these routines do a lookup in
.Pa /etc/hosts .
.Bd -literal
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
};
#define h_addr h_addr_list[0] /* address, for backward compatibility */
.Ed
.Pp
The members of this structure are:
.Bl -tag -width h_addr_list
.It Fa h_name
Official name of the host.
.It Fa h_aliases
A NULL-terminated array of alternate names for the host.
.It Fa h_addrtype
The type of address being returned; usually
.Dv AF_INET .
.It Fa h_length
The length, in bytes, of the address.
.It Fa h_addr_list
A NULL-terminated array of network addresses for the host.
Host addresses are returned in network byte order.
.It Fa h_addr
The first address in
.Fa h_addr_list ;
this is for backward compatibility.
.El
.Pp
When using the nameserver,
.Fn gethostbyname
and
.Fn gethostbyname
will search for the named host in the current domain and its parents
unless the name ends in a dot.
If the name contains no dot, and if the environment variable
.Dq Ev HOSTALIASES
contains the name of an alias file, the alias file will first be searched
for an alias matching the input name.
See
.Xr hostname 7
for the domain search procedure and the alias file format.
.Pp
The
.Fn gethostbyname2
function is an evolution of
.Fn gethostbyname
which is intended to allow lookups in address families other than
.Dv AF_INET ,
for example
.Dv AF_INET6 .
Currently the
.Fa af
argument must be specified as
.Dv AF_INET
else the function will return
.Dv NULL
after having set
.Va h_errno
to
.Dv NETDB_INTERNAL
.Pp
The
.Fn sethostent
function
may be used to request the use of a connected
.Tn TCP
socket for queries.
If the
.Fa stayopen
flag is non-zero,
this sets the option to send all queries to the name server using
.Tn TCP
and to retain the connection after each call to
.Fn gethostbyname ,
.Fn gethostbyname2
or
.Fn gethostbyaddr .
Otherwise, queries are performed using
.Tn UDP
datagrams.
.Pp
The
.Fn endhostent
function
closes the
.Tn TCP
connection.
.Pp
The
.Fn herror
function writes a message to the diagnostic output consisting of the
string parameter
.Fa s ,
the constant string ": ", and a message corresponding to the value of
.Va h_errno .
.Pp
The
.Fn hstrerror
function returns a string which is the message text corresponding to the
value of the
.Fa err
parameter.
.Sh FILES
.Bl -tag -width /etc/resolv.conf -compact
.It Pa /etc/hosts
.It Pa /etc/host.conf
.It Pa /etc/resolv.conf
.El
.Sh DIAGNOSTICS
Error return status from
.Fn gethostbyname ,
.Fn gethostbyname2
and
.Fn gethostbyaddr
is indicated by return of a null pointer.
The external integer
.Va h_errno
may then be checked to see whether this is a temporary failure
or an invalid or unknown host.
The routine
.Fn herror
can be used to print an error message describing the failure.
If its argument
.Fa string
is
.Pf non Dv -NULL ,
it is printed, followed by a colon and a space.
The error message is printed with a trailing newline.
.Pp
The variable
.Va h_errno
can have the following values:
.Bl -tag -width HOST_NOT_FOUND
.It Dv HOST_NOT_FOUND
No such host is known.
.It Dv TRY_AGAIN
This is usually a temporary error
and means that the local server did not receive
a response from an authoritative server.
A retry at some later time may succeed.
.It Dv NO_RECOVERY
Some unexpected server failure was encountered.
This is a non-recoverable error.
.It Dv NO_DATA
The requested name is valid but does not have an IP address;
this is not a temporary error.
This means that the name is known to the name server but there is no address
associated with this name.
Another type of request to the name server using this domain name
will result in an answer;
for example, a mail-forwarder may be registered for this domain.
.El
.Sh SEE ALSO
.Xr resolver 3 ,
.Xr hosts 5 ,
.Xr hostname 7 ,
.Xr named 8
.Sh CAVEAT
The
.Fn gethostent
function
is defined, and
.Fn sethostent
and
.Fn endhostent
are redefined,
when
.Xr libc 3
is built to use only the routines to lookup in
.Pa /etc/hosts
and not the name server.
.Pp
The
.Fn gethostent
function
reads the next line of
.Pa /etc/hosts ,
opening the file if necessary.
.Pp
The
.Fn sethostent
function
opens and/or rewinds the file
.Pa /etc/hosts .
If the
.Fa stayopen
argument is non-zero,
the file will not be closed after each call to
.Fn gethostbyname ,
.Fn gethostbyname2
or
.Fn gethostbyaddr .
.Pp
The
.Fn endhostent
function
closes the file.
.Sh HISTORY
The
.Fn herror
function appeared in
.Bx 4.3 .
The
.Fn endhostent ,
.Fn gethostbyaddr ,
.Fn gethostbyname ,
.Fn gethostent ,
and
.Fn sethostent
functions appeared in
.Bx 4.2 .
The
.Fn gethostbyname2
function first appeared in bind-4.9.4.
.Sh BUGS
These functions use static data storage;
if the data is needed for future use, it should be
copied before any subsequent calls overwrite it.
Only the Internet
address format is currently understood.
-144
View File
@@ -1,144 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*-
* Copyright (c) 1994, Garrett Wollman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <rtems/rtems_netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#ifdef YP
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#endif
#define MAXALIASES 35
#define MAXADDRS 35
#ifdef YP
static char *host_aliases[MAXALIASES];
static char hostaddr[MAXADDRS];
static char *host_addrs[2];
#endif /* YP */
static struct hostent *
_gethostbynis(
const char *name,
char *map,
int af)
{
#ifdef YP
register char *cp, **q;
char *result;
int resultlen;
static struct hostent h;
static char *domain = (char *)NULL;
static char ypbuf[YPMAXRECORD + 2];
switch(af) {
case AF_INET:
break;
default:
case AF_INET6:
errno = EAFNOSUPPORT;
return NULL;
}
if (domain == (char *)NULL)
if (yp_get_default_domain (&domain))
return ((struct hostent *)NULL);
if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
return ((struct hostent *)NULL);
/* avoid potential memory leak */
bcopy((char *)result, (char *)&ypbuf, resultlen);
ypbuf[resultlen] = '\0';
free(result);
result = (char *)&ypbuf;
if ((cp = index(result, '\n')))
*cp = '\0';
cp = strpbrk(result, " \t");
*cp++ = '\0';
h.h_addr_list = host_addrs;
h.h_addr = hostaddr;
*((u_long *)h.h_addr) = inet_addr(result);
h.h_length = sizeof(u_long);
h.h_addrtype = AF_INET;
while (*cp == ' ' || *cp == '\t')
cp++;
h.h_name = cp;
q = h.h_aliases = host_aliases;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &host_aliases[MAXALIASES - 1])
*q++ = cp;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
*q = NULL;
return (&h);
#else
return (NULL);
#endif /* YP */
}
struct hostent *
_gethostbynisname(
const char *name,
int af)
{
return _gethostbynis(name, "hosts.byname", af);
}
struct hostent *
_gethostbynisaddr(
const char *addr,
int len,
int af)
{
return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr", af);
}
-447
View File
@@ -1,447 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*-
* Copyright (c) 1994, Garrett Wollman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <rtems/rtems_netdb.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#include <arpa/nameser.h> /* XXX hack for _res */
#include <resolv.h> /* XXX hack for _res */
#define _PATH_HOSTCONF "/etc/host.conf"
enum service_type {
SERVICE_NONE = 0,
SERVICE_BIND,
SERVICE_HOSTS,
SERVICE_NIS };
#define SERVICE_MAX SERVICE_NIS
static struct {
const char *name;
enum service_type type;
} service_names[] = {
{ "hosts", SERVICE_HOSTS },
{ "/etc/hosts", SERVICE_HOSTS },
{ "hosttable", SERVICE_HOSTS },
{ "htable", SERVICE_HOSTS },
{ "bind", SERVICE_BIND },
{ "dns", SERVICE_BIND },
{ "domain", SERVICE_BIND },
{ "yp", SERVICE_NIS },
{ "yellowpages", SERVICE_NIS },
{ "nis", SERVICE_NIS },
{ 0, SERVICE_NONE }
};
static enum service_type service_order[SERVICE_MAX + 1];
static int service_done = 0;
static enum service_type
get_service_name(const char *name) {
int i;
for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
if(!strcasecmp(name, service_names[i].name)) {
return service_names[i].type;
}
}
return SERVICE_NONE;
}
static void
init_services(void)
{
char *cp, *p, buf[BUFSIZ];
register int cc = 0;
FILE *fd;
if ((fd = (FILE *)fopen(_PATH_HOSTCONF, "r")) == NULL) {
/* make some assumptions */
service_order[0] = SERVICE_BIND;
service_order[1] = SERVICE_HOSTS;
service_order[2] = SERVICE_NONE;
} else {
while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
if(buf[0] == '#')
continue;
p = buf;
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
;
if (cp == NULL)
continue;
do {
if (isalpha((unsigned char)cp[0])) {
service_order[cc] = get_service_name(cp);
if(service_order[cc] != SERVICE_NONE)
cc++;
}
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
;
} while(cp != NULL && cc < SERVICE_MAX);
}
service_order[cc] = SERVICE_NONE;
fclose(fd);
}
service_done = 1;
}
struct hostent *
gethostbyname(const char *name)
{
struct hostent *hp;
if (_res.options & RES_USE_INET6) { /* XXX */
hp = gethostbyname2(name, AF_INET6); /* XXX */
if (hp) /* XXX */
return (hp); /* XXX */
} /* XXX */
return (gethostbyname2(name, AF_INET));
}
struct hostent *
gethostbyname2(const char *name, int type)
{
struct hostent *hp = 0;
int nserv = 0;
if (!service_done)
init_services();
while (!hp) {
switch (service_order[nserv]) {
case SERVICE_NONE:
return NULL;
case SERVICE_HOSTS:
hp = _gethostbyhtname(name, type);
break;
case SERVICE_BIND:
hp = _gethostbydnsname(name, type);
break;
case SERVICE_NIS:
hp = _gethostbynisname(name, type);
break;
}
nserv++;
}
return hp;
}
int gethostbyaddr_r(const void *addr, socklen_t len, int type,
struct hostent *ret, char *buf, size_t buflen,
struct hostent **result, int *h_errnop)
{
#warning "implement a proper gethostbyaddr_r"
*result = gethostbyaddr( addr, len, type );
if ( *result )
return 0;
return -1;
}
struct hostent *
gethostbyaddr(const void *addr, socklen_t len, int type)
{
struct hostent *hp = 0;
int nserv = 0;
if (!service_done)
init_services();
while (!hp) {
switch (service_order[nserv]) {
case SERVICE_NONE:
return 0;
case SERVICE_HOSTS:
hp = _gethostbyhtaddr(addr, len, type);
break;
case SERVICE_BIND:
hp = _gethostbydnsaddr(addr, len, type);
break;
case SERVICE_NIS:
hp = _gethostbynisaddr(addr, len, type);
break;
}
nserv++;
}
return hp;
}
void
sethostent(int stayopen)
{
_sethosthtent(stayopen);
_sethostdnsent(stayopen);
}
void
endhostent(void)
{
_endhosthtent();
_endhostdnsent();
}
#ifdef _THREAD_SAFE
/* return length of decoded data or -1 */
static int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest,
unsigned int maxlen,unsigned char* behindpacket) {
unsigned char *tmp;
unsigned char *max=dest+maxlen;
unsigned char *after=packet+offset;
int ok=0;
for (tmp=after; maxlen>0&&*tmp; ) {
if (tmp>=behindpacket) return -1;
if ((*tmp>>6)==3) { /* goofy DNS decompression */
unsigned int ofs=((unsigned int)(*tmp&0x3f)<<8)|*(tmp+1);
if (ofs>=(unsigned int)offset) return -1; /* RFC1035: "pointer to a _prior_ occurrance" */
if (after<tmp+2) after=tmp+2;
tmp=packet+ofs;
ok=0;
} else {
unsigned int duh;
if (dest+*tmp+1>max) return -1;
if (tmp+*tmp+1>=behindpacket) return -1;
for (duh=*tmp; duh>0; --duh)
*dest++=*++tmp;
*dest++='.'; ok=1;
++tmp;
if (tmp>after) { after=tmp; if (!*tmp) ++after; }
}
}
if (ok) --dest;
*dest=0;
return after-packet;
}
static int __dns_gethostbyx_r(
const char* name,
struct hostent* result,
char *buf, size_t buflen,
struct hostent **RESULT,
int *h_errnop,
int lookfor)
{
int names,ips;
unsigned char *cur;
unsigned char *max;
unsigned char inpkg[1500];
char* tmp;
int size;
if (lookfor==1) {
result->h_addrtype=AF_INET;
result->h_length=4;
} else {
result->h_addrtype=AF_INET6;
result->h_length=16;
}
result->h_aliases=(char**)(buf+8*sizeof(char*));
result->h_addr_list=(char**)buf;
result->h_aliases[0]=0;
cur=(unsigned char*)buf+16*sizeof(char*);
max=(unsigned char*)buf+buflen;
names=ips=0;
if ((size=res_query(name,C_IN,lookfor,inpkg,512))<0) {
invalidpacket:
*h_errnop=HOST_NOT_FOUND;
return -1;
}
{
tmp=(char*)inpkg+12;
{
char Name[257];
unsigned short q=((unsigned short)inpkg[4]<<8)+inpkg[5];
while (q>0) {
if (tmp>(char*)inpkg+size) goto invalidpacket;
while (*tmp) { tmp+=*tmp+1; if (tmp>(char*)inpkg+size) goto invalidpacket; }
tmp+=5;
--q;
}
if (tmp>(char*)inpkg+size) goto invalidpacket;
q=((unsigned short)inpkg[6]<<8)+inpkg[7];
if (q<1) goto nodata;
while (q>0) {
int decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),(unsigned char*)Name,256,inpkg+size);
if (decofs<0) break;
tmp=(char*)inpkg+decofs;
--q;
if (tmp[0]!=0 || tmp[1]!=lookfor || /* TYPE != A */
tmp[2]!=0 || tmp[3]!=1) { /* CLASS != IN */
if (tmp[1]==5) { /* CNAME */
tmp+=10;
decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),(unsigned char*)Name,256,inpkg+size);
if (decofs<0) break;
tmp=(char*)inpkg+decofs;
} else
break;
continue;
}
tmp+=10; /* skip type, class, TTL and length */
{
int slen;
if (lookfor==1 || lookfor==28) /* A or AAAA*/ {
slen=strlen(Name);
if (cur+slen+8+(lookfor==28?12:0)>=max) { *h_errnop=NO_RECOVERY; return -1; }
} else if (lookfor==12) /* PTR */ {
decofs=__dns_decodename(inpkg,(size_t)(tmp-(char*)inpkg),(unsigned char*)Name,256,inpkg+size);
if (decofs<0) break;
tmp=(char*)inpkg+decofs;
slen=strlen(Name);
} else
slen=strlen(Name);
strcpy((char*)cur,Name);
if (names==0)
result->h_name=(char*)cur;
else
result->h_aliases[names-1]=(char*)cur;
result->h_aliases[names]=0;
if (names<8) ++names;
/* cur+=slen+1; */
cur+=(slen|3)+1;
result->h_addr_list[ips++] = (char*)cur;
if (lookfor==1) /* A */ {
*(int*)cur=*(int*)tmp;
cur+=4;
result->h_addr_list[ips]=0;
} else if (lookfor==28) /* AAAA */ {
{
int k;
for (k=0; k<16; ++k) cur[k]=tmp[k];
}
cur+=16;
result->h_addr_list[ips]=0;
}
}
/* puts(Name); */
}
}
}
if (!names) {
nodata:
*h_errnop=NO_DATA;
return -1;
}
*h_errnop=0;
*RESULT=result;
return 0;
}
int gethostbyname_r(const char* name,
struct hostent* result,
char *buf,
size_t buflen,
struct hostent **RESULT,
int *h_errnop)
{
uintptr_t current = (uintptr_t) buf;
uintptr_t end = current + buflen;
size_t L=strlen(name);
*RESULT = NULL;
*h_errnop = 0;
result->h_name = (char *) current;
current += L + 1;
if (current > end) { *h_errnop = ERANGE; return 1; }
strcpy(result->h_name, name);
current += sizeof(char **);
current -= current & (sizeof(char **) - 1);
result->h_addr_list = (char **) current;
current += 2 * sizeof(char **);
result->h_aliases = (char **) current;
current += sizeof(char **);
if (current > end) { *h_errnop = ERANGE; return 1; }
result->h_addr_list [0]= (char *) current;
current += 16;
result->h_addr_list [1] = NULL;
result->h_aliases [0] = NULL;
if (current > end) { *h_errnop = ERANGE; return 1; }
if (inet_pton(AF_INET,name,result->h_addr_list[0])) {
result->h_addrtype=AF_INET;
result->h_length=4;
*RESULT=result;
return 0;
} else if (inet_pton(AF_INET6,name,result->h_addr_list[0])) {
result->h_addrtype=AF_INET6;
result->h_length=16;
*RESULT=result;
return 0;
}
{
struct hostent* r;
struct hostent* he_buf = (struct hostent *)buf;
char *work_buf = buf + sizeof(struct hostent);
size_t remain_len = buflen - sizeof(struct hostent);
int he_errno;
sethostent(0);
while (gethostent_r(he_buf, work_buf, remain_len, &r, &he_errno) == 0) {
int i;
if (r->h_addrtype==AF_INET && !strcasecmp(r->h_name,name)) { /* found it! */
found:
memmove(result,r,sizeof(struct hostent));
*RESULT=result;
endhostent();
return 0;
}
for (i=0; i<16; ++i) {
if (r->h_aliases[i]) {
if (!strcasecmp(r->h_aliases[i],name)) goto found;
} else break;
}
}
endhostent();
}
return __dns_gethostbyx_r(name,result,buf+L,buflen-L,RESULT,h_errnop,1);
}
#endif
-421
View File
@@ -1,421 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/* $KAME: getifaddrs.c,v 1.9 2001/08/20 02:31:20 itojun Exp $ */
/*
* Copyright (c) 1995, 1999
* Berkeley Software Design, Inc. 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.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
*
* BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp
*/
/*
* NOTE: SIOCGIFCONF case is not LP64 friendly. it also does not perform
* try-and-error for region size.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#ifdef NET_RT_IFLIST
#include <sys/param.h>
#include <net/route.h>
#include <sys/sysctl.h>
#include <net/if_dl.h>
#endif
#include <errno.h>
#include <ifaddrs.h>
#include <stdlib.h>
#include <string.h>
#if !defined(AF_LINK)
#define SA_LEN(sa) sizeof(struct sockaddr)
#endif
#if !defined(SA_LEN)
#define SA_LEN(sa) (sa)->sa_len
#endif
#define SALIGN (sizeof(long) - 1)
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1))
#ifndef ALIGNBYTES
/*
* On systems with a routing socket, ALIGNBYTES should match the value
* that the kernel uses when building the messages.
*/
#define ALIGNBYTES XXX
#endif
#ifndef ALIGN
#define ALIGN(p) (((u_long)(p) + ALIGNBYTES) &~ ALIGNBYTES)
#endif
#if _BSDI_VERSION >= 199701
#define HAVE_IFM_DATA
#endif
#if _BSDI_VERSION >= 199802
/* ifam_data is very specific to recent versions of bsdi */
#define HAVE_IFAM_DATA
#endif
#if defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
#define HAVE_IFM_DATA
#endif
#define MAX_SYSCTL_TRY 5
int
getifaddrs(struct ifaddrs **pif)
{
int icnt = 1;
int dcnt = 0;
int ncnt = 0;
#ifdef NET_RT_IFLIST
int ntry = 0;
int mib[6];
size_t needed;
char *buf;
char *next;
struct ifaddrs *cif = 0;
char *p, *p0;
struct rt_msghdr *rtm;
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
struct sockaddr_dl *dl;
struct sockaddr *sa;
struct ifaddrs *ifa, *ift;
u_short idx = 0;
#else /* NET_RT_IFLIST */
char buf[1024];
int m, sock;
struct ifconf ifc;
struct ifreq *ifr;
struct ifreq *lifr;
#endif /* NET_RT_IFLIST */
int i;
size_t len, alen;
char *data;
char *names;
#ifdef NET_RT_IFLIST
mib[0] = CTL_NET;
mib[1] = PF_ROUTE;
mib[2] = 0; /* protocol */
mib[3] = 0; /* wildcard address family */
mib[4] = NET_RT_IFLIST;
mib[5] = 0; /* no flags */
do {
/*
* We'll try to get addresses several times in case that
* the number of addresses is unexpectedly increased during
* the two sysctl calls. This should rarely happen, but we'll
* try to do our best for applications that assume success of
* this library (which should usually be the case).
* Portability note: since FreeBSD does not add margin of
* memory at the first sysctl, the possibility of failure on
* the second sysctl call is a bit higher.
*/
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
return (-1);
if ((buf = malloc(needed)) == NULL)
return (-1);
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
free(buf);
return (-1);
}
free(buf);
buf = NULL;
}
} while (buf == NULL);
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)(void *)next;
if (rtm->rtm_version != RTM_VERSION)
continue;
switch (rtm->rtm_type) {
case RTM_IFINFO:
ifm = (struct if_msghdr *)(void *)rtm;
if (ifm->ifm_addrs & RTA_IFP) {
idx = ifm->ifm_index;
++icnt;
dl = (struct sockaddr_dl *)(void *)(ifm + 1);
dcnt += SA_RLEN((struct sockaddr *)(void*)dl) +
ALIGNBYTES;
#ifdef HAVE_IFM_DATA
dcnt += sizeof(ifm->ifm_data);
#endif /* HAVE_IFM_DATA */
ncnt += dl->sdl_nlen + 1;
} else
idx = 0;
break;
case RTM_NEWADDR:
ifam = (struct ifa_msghdr *)(void *)rtm;
if (idx && ifam->ifam_index != idx)
abort(); /* this cannot happen */
#define RTA_MASKS (RTA_NETMASK | RTA_IFA | RTA_BRD)
if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
break;
p = (char *)(void *)(ifam + 1);
++icnt;
#ifdef HAVE_IFAM_DATA
dcnt += sizeof(ifam->ifam_data) + ALIGNBYTES;
#endif /* HAVE_IFAM_DATA */
/* Scan to look for length of address */
alen = 0;
for (p0 = p, i = 0; i < RTAX_MAX; i++) {
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
== 0)
continue;
sa = (struct sockaddr *)(void *)p;
len = SA_RLEN(sa);
if (i == RTAX_IFA) {
alen = len;
break;
}
p += len;
}
for (p = p0, i = 0; i < RTAX_MAX; i++) {
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
== 0)
continue;
sa = (struct sockaddr *)(void *)p;
len = SA_RLEN(sa);
if (i == RTAX_NETMASK && SA_LEN(sa) == 0)
dcnt += alen;
else
dcnt += len;
p += len;
}
break;
}
}
#else /* NET_RT_IFLIST */
ifc.ifc_buf = buf;
ifc.ifc_len = sizeof(buf);
if ((sock = _socket(AF_INET, SOCK_STREAM, 0)) < 0)
return (-1);
i = _ioctl(sock, SIOCGIFCONF, (char *)&ifc);
_close(sock);
if (i < 0)
return (-1);
ifr = ifc.ifc_req;
lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
while (ifr < lifr) {
struct sockaddr *sa;
sa = &ifr->ifr_addr;
++icnt;
dcnt += SA_RLEN(sa);
ncnt += sizeof(ifr->ifr_name) + 1;
if (SA_LEN(sa) < sizeof(*sa))
ifr = (struct ifreq *)(((char *)sa) + sizeof(*sa));
else
ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
}
#endif /* NET_RT_IFLIST */
if (icnt + dcnt + ncnt == 1) {
*pif = NULL;
free(buf);
return (0);
}
data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt);
if (data == NULL) {
free(buf);
return(-1);
}
ifa = (struct ifaddrs *)(void *)data;
data += sizeof(struct ifaddrs) * icnt;
names = data + dcnt;
memset(ifa, 0, sizeof(struct ifaddrs) * icnt);
ift = ifa;
#ifdef NET_RT_IFLIST
idx = 0;
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
rtm = (struct rt_msghdr *)(void *)next;
if (rtm->rtm_version != RTM_VERSION)
continue;
switch (rtm->rtm_type) {
case RTM_IFINFO:
ifm = (struct if_msghdr *)(void *)rtm;
if (ifm->ifm_addrs & RTA_IFP) {
idx = ifm->ifm_index;
dl = (struct sockaddr_dl *)(void *)(ifm + 1);
cif = ift;
ift->ifa_name = names;
ift->ifa_flags = (int)ifm->ifm_flags;
memcpy(names, dl->sdl_data,
(size_t)dl->sdl_nlen);
names[dl->sdl_nlen] = 0;
names += dl->sdl_nlen + 1;
ift->ifa_addr = (struct sockaddr *)(void *)data;
memcpy(data, dl,
(size_t)SA_LEN((struct sockaddr *)
(void *)dl));
data += SA_RLEN((struct sockaddr *)(void *)dl);
#ifdef HAVE_IFM_DATA
/* ifm_data needs to be aligned */
ift->ifa_data = data = (void *)ALIGN(data);
memcpy(data, &ifm->ifm_data, sizeof(ifm->ifm_data));
data += sizeof(ifm->ifm_data);
#else /* HAVE_IFM_DATA */
ift->ifa_data = NULL;
#endif /* HAVE_IFM_DATA */
ift = (ift->ifa_next = ift + 1);
} else
idx = 0;
break;
case RTM_NEWADDR:
ifam = (struct ifa_msghdr *)(void *)rtm;
if (idx && ifam->ifam_index != idx)
abort(); /* this cannot happen */
if (idx == 0 || (ifam->ifam_addrs & RTA_MASKS) == 0)
break;
ift->ifa_name = cif->ifa_name;
ift->ifa_flags = cif->ifa_flags;
ift->ifa_data = NULL;
p = (char *)(void *)(ifam + 1);
/* Scan to look for length of address */
alen = 0;
for (p0 = p, i = 0; i < RTAX_MAX; i++) {
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
== 0)
continue;
sa = (struct sockaddr *)(void *)p;
len = SA_RLEN(sa);
if (i == RTAX_IFA) {
alen = len;
break;
}
p += len;
}
for (p = p0, i = 0; i < RTAX_MAX; i++) {
if ((RTA_MASKS & ifam->ifam_addrs & (1 << i))
== 0)
continue;
sa = (struct sockaddr *)(void *)p;
len = SA_RLEN(sa);
switch (i) {
case RTAX_IFA:
ift->ifa_addr =
(struct sockaddr *)(void *)data;
memcpy(data, p, len);
data += len;
break;
case RTAX_NETMASK:
ift->ifa_netmask =
(struct sockaddr *)(void *)data;
if (SA_LEN(sa) == 0) {
memset(data, 0, alen);
data += alen;
break;
}
memcpy(data, p, len);
data += len;
break;
case RTAX_BRD:
ift->ifa_broadaddr =
(struct sockaddr *)(void *)data;
memcpy(data, p, len);
data += len;
break;
}
p += len;
}
#ifdef HAVE_IFAM_DATA
/* ifam_data needs to be aligned */
ift->ifa_data = data = (void *)ALIGN(data);
memcpy(data, &ifam->ifam_data, sizeof(ifam->ifam_data));
data += sizeof(ifam->ifam_data);
#endif /* HAVE_IFAM_DATA */
ift = (ift->ifa_next = ift + 1);
break;
}
}
free(buf);
#else /* NET_RT_IFLIST */
ifr = ifc.ifc_req;
lifr = (struct ifreq *)&ifc.ifc_buf[ifc.ifc_len];
while (ifr < lifr) {
struct sockaddr *sa;
ift->ifa_name = names;
names[sizeof(ifr->ifr_name)] = 0;
strncpy(names, ifr->ifr_name, sizeof(ifr->ifr_name));
while (*names++)
;
ift->ifa_addr = (struct sockaddr *)data;
sa = &ifr->ifr_addr;
memcpy(data, sa, SA_LEN(sa));
data += SA_RLEN(sa);
ifr = (struct ifreq *)(((char *)sa) + SA_LEN(sa));
ift = (ift->ifa_next = ift + 1);
}
#endif /* NET_RT_IFLIST */
if (--ift >= ifa) {
ift->ifa_next = NULL;
*pif = ifa;
} else {
*pif = NULL;
free(ifa);
}
return (0);
}
void
freeifaddrs(struct ifaddrs *ifp)
{
free(ifp);
}
-61
View File
@@ -1,61 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* Copyright (c) 2016 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
int
getnameinfo(const struct sockaddr *sa, socklen_t salen, char *node,
size_t nodelen, char *service, size_t servicelen, int flags)
{
int af;
const struct sockaddr_in *sa_in = (const struct sockaddr_in *)sa;
(void) salen;
af = sa->sa_family;
if (af != AF_INET) {
return EAI_FAMILY;
}
if ((flags & NI_NAMEREQD) != 0) {
return EAI_NONAME;
}
/* FIXME: This return just the address value. Try resolving instead. */
if (node != NULL && nodelen > 0) {
if (inet_ntop(af, &sa_in->sin_addr, node, nodelen) == NULL) {
return EAI_FAIL;
}
}
if (service != NULL && servicelen > 0) {
in_port_t port = ntohs(sa_in->sin_port);
int rv;
rv = snprintf(service, servicelen, "%u", port);
if (rv <= 0) {
return EAI_FAIL;
} else if ((unsigned)rv >= servicelen) {
return EAI_OVERFLOW;
}
}
return 0;
}
-313
View File
@@ -1,313 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*-
* Copyright (c) 1985, 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
* -
* --Copyright--
*/
/* Portions Copyright (c) 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#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 <rtems/rtems_netdb.h>
#include <resolv.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include "res_config.h"
#define BYADDR 0
#define BYNAME 1
#define MAXALIASES 35
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
#define MAXPACKET 1024
#endif
typedef union {
HEADER hdr;
u_char buf[MAXPACKET];
} querybuf;
typedef union {
long al;
char ac;
} align;
static struct netent *
getnetanswer(
querybuf *answer,
int anslen,
int net_i)
{
register HEADER *hp;
register u_char *cp;
register int n;
u_char *eom;
int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN];
char *in, *st, *pauxt, *bp, **ap;
char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
static struct netent net_entry;
static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];
/*
* find first satisfactory answer
*
* answer --> +------------+ ( MESSAGE )
* | Header |
* +------------+
* | Question | the question for the name server
* +------------+
* | Answer | RRs answering the question
* +------------+
* | Authority | RRs pointing toward an authority
* | Additional | RRs holding additional information
* +------------+
*/
eom = answer->buf + anslen;
hp = &answer->hdr;
ancount = ntohs(hp->ancount); /* #/records in the answer section */
qdcount = ntohs(hp->qdcount); /* #/entries in the question section */
bp = netbuf;
buflen = sizeof(netbuf);
cp = answer->buf + HFIXEDSZ;
if (!qdcount) {
if (hp->aa)
h_errno = HOST_NOT_FOUND;
else
h_errno = TRY_AGAIN;
return (NULL);
}
while (qdcount-- > 0)
cp += __dn_skipname(cp, eom) + QFIXEDSZ;
ap = net_aliases;
*ap = NULL;
net_entry.n_aliases = net_aliases;
haveanswer = 0;
while (--ancount >= 0 && cp < eom) {
n = dn_expand(answer->buf, eom, cp, bp, buflen);
if ((n < 0) || !res_dnok(bp))
break;
cp += n;
ans[0] = '\0';
(void)strncpy(&ans[0], bp, sizeof(ans) - 1);
ans[sizeof(ans) - 1] = '\0';
GETSHORT(type, cp);
GETSHORT(class, cp);
cp += INT32SZ; /* TTL */
GETSHORT(n, cp);
if (class == C_IN && type == T_PTR) {
n = dn_expand(answer->buf, eom, cp, bp, buflen);
if ((n < 0) || !res_hnok(bp)) {
cp += n;
return (NULL);
}
cp += n;
*ap++ = bp;
bp += strlen(bp) + 1;
net_entry.n_addrtype =
(class == C_IN) ? AF_INET : AF_UNSPEC;
haveanswer++;
}
}
if (haveanswer) {
*ap = NULL;
switch (net_i) {
case BYADDR:
net_entry.n_name = *net_entry.n_aliases;
net_entry.n_net = 0L;
break;
case BYNAME:
in = *net_entry.n_aliases;
net_entry.n_name = &ans[0];
aux2[0] = '\0';
for (i = 0; i < 4; i++) {
for (st = in, nchar = 0;
*st != '.';
st++, nchar++)
;
if (nchar != 1 || *in != '0' || flag) {
flag = 1;
(void)strncpy(paux1,
(i==0) ? in : in-1,
(i==0) ?nchar : nchar+1);
paux1[(i==0) ? nchar : nchar+1] = '\0';
pauxt = paux2;
paux2 = strcat(paux1, paux2);
paux1 = pauxt;
}
in = ++st;
}
net_entry.n_net = inet_network(paux2);
break;
}
net_entry.n_aliases++;
return (&net_entry);
}
h_errno = TRY_AGAIN;
return (NULL);
}
struct netent *
_getnetbydnsaddr(
register unsigned long net,
register int net_type )
{
unsigned int netbr[4];
int nn, anslen;
querybuf buf;
char qbuf[MAXDNAME];
unsigned long net2;
struct netent *net_entry;
if (net_type != AF_INET)
return (NULL);
for (nn = 4, net2 = net; net2; net2 >>= 8)
netbr[--nn] = net2 & 0xff;
switch (nn) {
case 3: /* Class A */
sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
break;
case 2: /* Class B */
sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
break;
case 1: /* Class C */
sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
netbr[1]);
break;
case 0: /* Class D - E */
sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
netbr[1], netbr[0]);
break;
}
anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
if (anslen < 0) {
#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf("res_query failed\n");
#endif
return (NULL);
}
net_entry = getnetanswer(&buf, anslen, BYADDR);
if (net_entry) {
unsigned u_net = net; /* maybe net should be unsigned ? */
/* Strip trailing zeros */
while ((u_net & 0xff) == 0 && u_net != 0)
u_net >>= 8;
net_entry->n_net = u_net;
return (net_entry);
}
return (NULL);
}
struct netent *
_getnetbydnsname(
register const char *net )
{
int anslen;
querybuf buf;
char qbuf[MAXDNAME];
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
h_errno = NETDB_INTERNAL;
return (NULL);
}
strncpy(qbuf, net, sizeof(qbuf) - 1);
qbuf[sizeof(qbuf) - 1] = '\0';
anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
if (anslen < 0) {
#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf("res_query failed\n");
#endif
return (NULL);
}
return getnetanswer(&buf, anslen, BYNAME);
}
void
_setnetdnsent(
int stayopen)
{
if (stayopen)
_res.options |= RES_STAYOPEN | RES_USEVC;
}
void
_endnetdnsent(void)
{
_res.options &= ~(RES_STAYOPEN | RES_USEVC);
res_close();
}
-175
View File
@@ -1,175 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* Copyright (c) 1983, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
* Dep. Matematica Universidade de Coimbra, Portugal, Europe
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* from getnetent.c 1.1 (Coimbra) 93/06/02
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <netdb.h>
#include <rtems/rtems_netdb.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h>
#endif
#define MAXALIASES 35
static FILE *netf;
static char line[BUFSIZ+1];
static struct netent net;
static char *net_aliases[MAXALIASES];
static int _net_stayopen;
void
_setnethtent(int f)
{
if (netf == NULL)
netf = fopen(_PATH_NETWORKS, "r" );
else
rewind(netf);
_net_stayopen |= f;
}
void
_endnethtent(void)
{
if (netf) {
fclose(netf);
netf = NULL;
}
_net_stayopen = 0;
}
struct netent *
getnetent(void)
{
char *p;
register char *cp, **q;
if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
return (NULL);
again:
p = fgets(line, sizeof line, netf);
if (p == NULL)
return (NULL);
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");
if (cp == NULL)
goto again;
*cp = '\0';
net.n_name = p;
cp = strpbrk(p, " \t");
if (cp == NULL)
goto again;
*cp++ = '\0';
while (*cp == ' ' || *cp == '\t')
cp++;
p = strpbrk(cp, " \t");
if (p != NULL)
*p++ = '\0';
net.n_net = inet_network(cp);
net.n_addrtype = AF_INET;
q = net.n_aliases = net_aliases;
if (p != NULL)
cp = p;
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &net_aliases[MAXALIASES - 1])
*q++ = cp;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
*q = NULL;
return (&net);
}
struct netent *
_getnetbyhtname(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);
}
struct netent *
_getnetbyhtaddr(
unsigned long net,
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);
}
-179
View File
@@ -1,179 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*-
* Copyright (c) 1994, Garrett Wollman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <rtems/rtems_netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <arpa/nameser.h>
#ifdef YP
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
#endif
#define MAXALIASES 35
#define MAXADDRS 35
#ifdef YP
static char *host_aliases[MAXALIASES];
#endif /* YP */
static struct netent *
_getnetbynis(
const char *name,
char *map,
int af)
{
#ifdef YP
register char *cp, **q;
static char *result;
int resultlen;
static struct netent h;
static char *domain = (char *)NULL;
static char ypbuf[YPMAXRECORD + 2];
switch(af) {
case AF_INET:
break;
default:
case AF_INET6:
errno = EAFNOSUPPORT;
return NULL;
}
if (domain == (char *)NULL)
if (yp_get_default_domain (&domain))
return (NULL);
if (yp_match(domain, map, name, strlen(name), &result, &resultlen))
return (NULL);
bcopy((char *)result, (char *)&ypbuf, resultlen);
ypbuf[resultlen] = '\0';
free(result);
result = (char *)&ypbuf;
if ((cp = index(result, '\n')))
*cp = '\0';
cp = strpbrk(result, " \t");
*cp++ = '\0';
h.n_name = result;
while (*cp == ' ' || *cp == '\t')
cp++;
h.n_net = inet_network(cp);
h.n_addrtype = AF_INET;
q = h.n_aliases = host_aliases;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &host_aliases[MAXALIASES - 1])
*q++ = cp;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
*q = NULL;
return (&h);
#else
return (NULL);
#endif
}
struct netent *
_getnetbynisname(
const char *name)
{
return _getnetbynis(name, "networks.byname", AF_INET);
}
struct netent *
_getnetbynisaddr(
unsigned long addr,
int af)
{
char *str, *cp;
unsigned long net2;
int nn;
unsigned int netbr[4];
char buf[MAXDNAME];
if (af != AF_INET) {
errno = EAFNOSUPPORT;
return (NULL);
}
for (nn = 4, net2 = addr; net2; net2 >>= 8) {
netbr[--nn] = net2 & 0xff;
}
switch (nn) {
case 3: /* Class A */
sprintf(buf, "%u", netbr[3]);
break;
case 2: /* Class B */
sprintf(buf, "%u.%u", netbr[2], netbr[3]);
break;
case 1: /* Class C */
sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]);
break;
case 0: /* Class D - E */
sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1],
netbr[2], netbr[3]);
break;
}
str = (char *)&buf;
cp = str + (strlen(str) - 2);
while(!strcmp(cp, ".0")) {
*cp = '\0';
cp = str + (strlen(str) - 2);
}
return _getnetbynis(str, "networks.byaddr", af);
}
-158
View File
@@ -1,158 +0,0 @@
.\" Copyright (c) 1983, 1991, 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.
.\"
.\" @(#)getnetent.3 8.1 (Berkeley) 6/4/93
.\"
.Dd June 4, 1993
.Dt GETNETENT 3
.Os BSD 4.2
.Sh NAME
.Nm getnetent ,
.Nm getnetbyaddr ,
.Nm getnetbyname ,
.Nm setnetent ,
.Nm endnetent
.Nd get network entry
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Ft struct netent *
.Fn getnetent void
.Ft struct netent *
.Fn getnetbyname "const char *name"
.Ft struct netent *
.Fn getnetbyaddr "unsigned long net" "int type"
.Ft void
.Fn setnetent "int stayopen"
.Ft void
.Fn endnetent void
.Sh DESCRIPTION
The
.Fn getnetent ,
.Fn getnetbyname ,
and
.Fn getnetbyaddr
functions
each return a pointer to an object with the
following structure
containing the broken-out
fields of a line in the network data base,
.Pa /etc/networks .
.Bd -literal -offset indent
struct netent {
char *n_name; /* official name of net */
char **n_aliases; /* alias list */
int n_addrtype; /* net number type */
unsigned long n_net; /* net number */
};
.Ed
.Pp
The members of this structure are:
.Bl -tag -width n_addrtype
.It Fa n_name
The official name of the network.
.It Fa n_aliases
A zero terminated list of alternate names for the network.
.It Fa n_addrtype
The type of the network number returned; currently only AF_INET.
.It Fa n_net
The network number. Network numbers are returned in machine byte
order.
.El
.Pp
The
.Fn getnetent
function
reads the next line of the file, opening the file if necessary.
.Pp
The
.Fn setnetent
function
opens and rewinds the file. If the
.Fa stayopen
flag is non-zero,
the net data base will not be closed after each call to
.Fn getnetbyname
or
.Fn getnetbyaddr .
.Pp
The
.Fn endnetent
function
closes the file.
.Pp
The
.Fn getnetbyname
function
and
.Fn getnetbyaddr
sequentially search from the beginning
of the file until a matching
net name or
net address and type is found,
or until
.Dv EOF
is encountered. The
.Fa type
must be
.Dv AF_INET .
Network numbers are supplied in host order.
.Sh FILES
.Bl -tag -width /etc/networks -compact
.It Pa /etc/networks
.El
.Sh DIAGNOSTICS
Null pointer
(0) returned on
.Dv EOF
or error.
.Sh SEE ALSO
.Xr networks 5
.Pp
.%T RFC 1101
.Sh HISTORY
The
.Fn getnetent ,
.Fn getnetbyaddr ,
.Fn getnetbyname ,
.Fn setnetent ,
and
.Fn endnetent
functions appeared in
.Bx 4.2 .
.Sh BUGS
The data space used by
these functions is static; if future use requires the data, it should be
copied before any subsequent calls to these functions overwrite it.
Only Internet network
numbers are currently understood.
Expecting network numbers to fit
in no more than 32 bits is probably
naive.
-193
View File
@@ -1,193 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*-
* Copyright (c) 1994, Garrett Wollman
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <rtems/rtems_netdb.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
#ifdef HAVE_STRINGS_H
#include <strings.h> /* for strcasecmp */
#endif
#ifndef _PATH_NETCONF
#define _PATH_NETCONF "/etc/host.conf"
#endif
enum service_type {
SERVICE_NONE = 0,
SERVICE_BIND,
SERVICE_TABLE,
SERVICE_NIS };
#define SERVICE_MAX SERVICE_NIS
static struct {
const char *name;
enum service_type type;
} service_names[] = {
{ "hosts", SERVICE_TABLE },
{ "/etc/hosts", SERVICE_TABLE },
{ "hosttable", SERVICE_TABLE },
{ "htable", SERVICE_TABLE },
{ "bind", SERVICE_BIND },
{ "dns", SERVICE_BIND },
{ "domain", SERVICE_BIND },
{ "yp", SERVICE_NIS },
{ "yellowpages", SERVICE_NIS },
{ "nis", SERVICE_NIS },
{ 0, SERVICE_NONE }
};
static enum service_type service_order[SERVICE_MAX + 1];
static int service_done = 0;
static enum service_type
get_service_name(const char *name) {
int i;
for(i = 0; service_names[i].type != SERVICE_NONE; i++) {
if(!strcasecmp(name, service_names[i].name)) {
return service_names[i].type;
}
}
return SERVICE_NONE;
}
static void
init_services(void)
{
char *cp, *p, buf[BUFSIZ];
register int cc = 0;
FILE *fd;
if ((fd = (FILE *)fopen(_PATH_NETCONF, "r")) == NULL) {
/* make some assumptions */
service_order[0] = SERVICE_TABLE;
service_order[1] = SERVICE_NONE;
} else {
while (fgets(buf, BUFSIZ, fd) != NULL && cc < SERVICE_MAX) {
if(buf[0] == '#')
continue;
p = buf;
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
;
if (cp == NULL)
continue;
do {
if (isalpha((unsigned char)cp[0])) {
service_order[cc] = get_service_name(cp);
if(service_order[cc] != SERVICE_NONE)
cc++;
}
while ((cp = strsep(&p, "\n \t,:;")) != NULL && *cp == '\0')
;
} while(cp != NULL && cc < SERVICE_MAX);
}
service_order[cc] = SERVICE_NONE;
fclose(fd);
}
service_done = 1;
}
struct netent *
getnetbyname(const char *name)
{
struct netent *hp = 0;
int nserv = 0;
if (!service_done)
init_services();
while (!hp) {
switch (service_order[nserv]) {
case SERVICE_NONE:
return NULL;
case SERVICE_TABLE:
hp = _getnetbyhtname(name);
break;
case SERVICE_BIND:
hp = _getnetbydnsname(name);
break;
case SERVICE_NIS:
hp = _getnetbynisname(name);
break;
}
nserv++;
}
return hp;
}
struct netent *
getnetbyaddr(uint32_t addr, int af)
{
struct netent *hp = 0;
int nserv = 0;
if (!service_done)
init_services();
while (!hp) {
switch (service_order[nserv]) {
case SERVICE_NONE:
return 0;
case SERVICE_TABLE:
hp = _getnetbyhtaddr(addr, af);
break;
case SERVICE_BIND:
hp = _getnetbydnsaddr(addr, af);
break;
case SERVICE_NIS:
hp = _getnetbynisaddr(addr, af);
break;
}
nserv++;
}
return hp;
}
void
setnetent(int stayopen)
{
_setnethtent(stayopen);
_setnetdnsent(stayopen);
}
void
endnetent(void)
{
_endnethtent();
_endnetdnsent();
}
-62
View File
@@ -1,62 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdb.h>
extern int _proto_stayopen;
extern struct protoent * getprotobynumber_static(int);
struct protoent *
getprotobynumber(
int proto )
{
register struct protoent *p;
setprotoent(_proto_stayopen);
while ( (p = getprotoent()) )
if (p->p_proto == proto)
break;
if (!_proto_stayopen)
endprotoent();
if ( !p )
p = getprotobynumber_static(proto);
return (p);
}
-146
View File
@@ -1,146 +0,0 @@
.\" Copyright (c) 1983, 1991, 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.
.\"
.\" @(#)getprotoent.3 8.1 (Berkeley) 6/4/93
.\"
.Dd June 4, 1993
.Dt GETPROTOENT 3
.Os BSD 4.2
.Sh NAME
.Nm getprotoent ,
.Nm getprotobynumber ,
.Nm getprotobyname ,
.Nm setprotoent ,
.Nm endprotoent
.Nd get protocol entry
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Ft struct protoent *
.Fn getprotoent void
.Ft struct protoent *
.Fn getprotobyname "const char *name"
.Ft struct protoent *
.Fn getprotobynumber "int proto"
.Ft void
.Fn setprotoent "int stayopen"
.Ft void
.Fn endprotoent void
.Sh DESCRIPTION
The
.Fn getprotoent ,
.Fn getprotobyname ,
and
.Fn getprotobynumber
functions
each return a pointer to an object with the
following structure
containing the broken-out
fields of a line in the network protocol data base,
.Pa /etc/protocols .
.Bd -literal -offset indent
.Pp
struct protoent {
char *p_name; /* official name of protocol */
char **p_aliases; /* alias list */
int p_proto; /* protocol number */
};
.Ed
.Pp
The members of this structure are:
.Bl -tag -width p_aliases
.It Fa p_name
The official name of the protocol.
.It Fa p_aliases
A zero terminated list of alternate names for the protocol.
.It Fa p_proto
The protocol number.
.El
.Pp
The
.Fn getprotoent
function
reads the next line of the file, opening the file if necessary.
.Pp
The
.Fn setprotoent
function
opens and rewinds the file. If the
.Fa stayopen
flag is non-zero,
the net data base will not be closed after each call to
.Fn getprotobyname
or
.Fn getprotobynumber .
.Pp
The
.Fn endprotoent
function
closes the file.
.Pp
The
.Fn getprotobyname
function
and
.Fn getprotobynumber
sequentially search from the beginning
of the file until a matching
protocol name or
protocol number is found,
or until
.Dv EOF
is encountered.
.Sh RETURN VALUES
Null pointer
(0) returned on
.Dv EOF
or error.
.Sh FILES
.Bl -tag -width /etc/protocols -compact
.It Pa /etc/protocols
.El
.Sh SEE ALSO
.Xr protocols 5
.Sh HISTORY
The
.Fn getprotoent ,
.Fn getprotobynumber ,
.Fn getprotobyname ,
.Fn setprotoent ,
and
.Fn endprotoent
functions appeared in
.Bx 4.2 .
.Sh BUGS
These functions use a static data space;
if the data is needed for future use, it should be
copied before any subsequent calls overwrite it.
Only the Internet
protocols are currently understood.
-121
View File
@@ -1,121 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXALIASES 35
static FILE *protof = NULL;
static char line[BUFSIZ+1];
static struct protoent proto;
static char *proto_aliases[MAXALIASES];
int _proto_stayopen;
void
setprotoent(
int f)
{
if (protof == NULL)
protof = fopen(_PATH_PROTOCOLS, "r" );
else
rewind(protof);
_proto_stayopen |= f;
}
void
endprotoent(void)
{
if (protof) {
fclose(protof);
protof = NULL;
}
_proto_stayopen = 0;
}
struct protoent *
getprotoent(void)
{
char *p;
register char *cp, **q;
if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
return (NULL);
again:
if ((p = fgets(line, BUFSIZ, protof)) == NULL)
return (NULL);
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");
if (cp == NULL)
goto again;
*cp = '\0';
proto.p_name = p;
cp = strpbrk(p, " \t");
if (cp == NULL)
goto again;
*cp++ = '\0';
while (*cp == ' ' || *cp == '\t')
cp++;
p = strpbrk(cp, " \t");
if (p != NULL)
*p++ = '\0';
proto.p_proto = atoi(cp);
q = proto.p_aliases = proto_aliases;
if (p != NULL) {
cp = p;
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &proto_aliases[MAXALIASES - 1])
*q++ = cp;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
}
*q = NULL;
return (&proto);
}
-69
View File
@@ -1,69 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdb.h>
#include <string.h>
extern int _proto_stayopen;
extern struct protoent *getprotobyname_static(const char *);
struct protoent *
getprotobyname(
const char *name)
{
register struct protoent *p;
register 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();
if ( !p )
p = getprotobyname_static(name);
return (p);
}
-101
View File
@@ -1,101 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdb.h>
#include <string.h>
extern int _serv_stayopen;
int getservbyname_r(
const char *name,
const char *proto,
struct servent *result_buf,
char *buf,
size_t buflen,
struct servent **result
)
{
#warning "implement a proper getservbyport_r"
*result = getservbyname(name, proto);
if ( *result )
return 0;
return -1;
}
struct servent *
getservbyname(
const char *name,
const char *proto )
{
register struct servent *p;
register char **cp;
#ifdef YP
extern char *___getservbyname_yp;
extern char *___getservbyproto_yp;
___getservbyname_yp = (char *)name;
___getservbyproto_yp = (char *)proto;
#endif
setservent(_serv_stayopen);
while ( (p = getservent()) ) {
if (strcmp(name, p->s_name) == 0)
goto gotname;
for (cp = p->s_aliases; *cp; cp++)
if (strcmp(name, *cp) == 0)
goto gotname;
continue;
gotname:
if (proto == 0 || strcmp(p->s_proto, proto) == 0)
break;
}
if (!_serv_stayopen)
endservent();
#ifdef YP
___getservbyname_yp = NULL;
___getservbyproto_yp = NULL;
#endif
return (p);
}
-94
View File
@@ -1,94 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <netdb.h>
#include <string.h>
extern int _serv_stayopen;
int getservbyport_r(
int port,
const char *proto,
struct servent *result_buf,
char *buf,
size_t buflen,
struct servent **result
)
{
#warning "implement a proper getservbyport_r"
*result = getservbyport(port, proto);
if ( *result )
return 0;
return -1;
}
struct servent *
getservbyport(
int port,
const char *proto)
{
register struct servent *p;
#ifdef YP
extern int ___getservbyport_yp;
extern char *___getservbyproto_yp;
___getservbyport_yp = port;
___getservbyproto_yp = (char *)proto;
#endif
setservent(_serv_stayopen);
while ( (p = getservent()) ) {
if (p->s_port != port)
continue;
if (proto == 0 || strcmp(p->s_proto, proto) == 0)
break;
}
if (!_serv_stayopen)
endservent();
#ifdef YP
___getservbyport_yp = 0;
___getservbyproto_yp = NULL;
#endif
return (p);
}
-155
View File
@@ -1,155 +0,0 @@
.\" Copyright (c) 1983, 1991, 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.
.\"
.\" From: @(#)getservent.3 8.3 (Berkeley) 1/12/94
.\"
.Dd July 9, 1995
.Dt GETSERVENT 3
.Os BSD 4.2
.Sh NAME
.Nm getservent ,
.Nm getservbyport ,
.Nm getservbyname ,
.Nm setservent ,
.Nm endservent
.Nd get service entry
.Sh SYNOPSIS
.Fd #include <netdb.h>
.Ft struct servent *
.Fn getservent
.Ft struct servent *
.Fn getservbyname "const char *name" "const char *proto"
.Ft struct servent *
.Fn getservbyport "int port" "const char *proto"
.Ft void
.Fn setservent "int stayopen"
.Ft void
.Fn endservent void
.Sh DESCRIPTION
The
.Fn getservent ,
.Fn getservbyname ,
and
.Fn getservbyport
functions
each return a pointer to an object with the
following structure
containing the broken-out
fields of a line in the network services data base,
.Pa /etc/services .
.Bd -literal -offset indent
struct servent {
char *s_name; /* official name of service */
char **s_aliases; /* alias list */
int s_port; /* port service resides at */
char *s_proto; /* protocol to use */
};
.Ed
.Pp
The members of this structure are:
.Bl -tag -width s_aliases
.It Fa s_name
The official name of the service.
.It Fa s_aliases
A zero terminated list of alternate names for the service.
.It Fa s_port
The port number at which the service resides.
Port numbers are returned in network byte order.
.It Fa s_proto
The name of the protocol to use when contacting the
service.
.El
.Pp
The
.Fn getservent
function
reads the next line of the file, opening the file if necessary.
.Pp
The
.Fn setservent
function
opens and rewinds the file. If the
.Fa stayopen
flag is non-zero,
the net data base will not be closed after each call to
.Fn getservbyname
or
.Fn getservbyport .
.Pp
The
.Fn endservent
function
closes the file.
.Pp
The
.Fn getservbyname
and
.Fn getservbyport
functions
sequentially search from the beginning
of the file until a matching
protocol name or
port number is found,
or until
.Dv EOF
is encountered.
If a protocol name is also supplied (non-
.Dv NULL ) ,
searches must also match the protocol.
.ne 1i
.Sh FILES
.Bl -tag -width /etc/services -compact
.It Pa /etc/services
.El
.Sh DIAGNOSTICS
Null pointer
(0) returned on
.Dv EOF
or error.
.Sh SEE ALSO
.Xr getprotoent 3 ,
.Xr services 5
.Sh HISTORY
The
.Fn getservent ,
.Fn getservbyport ,
.Fn getservbyname ,
.Fn setservent ,
and
.Fn endservent
functions appeared in
.Bx 4.2 .
.Sh BUGS
These functions use static data storage;
if the data is needed for future use, it should be
copied before any subsequent calls overwrite it.
Expecting port numbers to fit in a 32 bit
quantity is probably naive.
-281
View File
@@ -1,281 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#ifdef YP
#include <rpc/rpc.h>
#include <rpcsvc/yp_prot.h>
#include <rpcsvc/ypclnt.h>
static int serv_stepping_yp = 0;
extern int _yp_check __P(( char ** ));
#endif
#define MAXALIASES 35
static FILE *servf = NULL;
static char line[BUFSIZ+1];
static struct servent serv;
static char *serv_aliases[MAXALIASES];
int _serv_stayopen;
#ifdef YP
char *___getservbyname_yp = NULL;
char *___getservbyproto_yp = NULL;
int ___getservbyport_yp = 0;
static char *yp_domain = NULL;
static int
_getservbyport_yp(line)
char *line;
{
char *result;
int resultlen;
char buf[YPMAXRECORD + 2];
int rv;
snprintf(buf, sizeof(buf), "%d/%s", ntohs(___getservbyport_yp),
___getservbyproto_yp);
___getservbyport_yp = 0;
___getservbyproto_yp = NULL;
if(!yp_domain) {
if(yp_get_default_domain(&yp_domain))
return (0);
}
/*
* We have to be a little flexible here. Ideally you're supposed
* to have both a services.byname and a services.byport map, but
* some systems have only services.byname. FreeBSD cheats a little
* by putting the services.byport information in the same map as
* services.byname so that either case will work. We allow for both
* possibilities here: if there is no services.byport map, we try
* services.byname instead.
*/
if ((rv = yp_match(yp_domain, "services.byport", buf, strlen(buf),
&result, &resultlen))) {
if (rv == YPERR_MAP) {
if (yp_match(yp_domain, "services.byname", buf,
strlen(buf), &result, &resultlen))
return(0);
} else
return(0);
}
/* getservent() expects lines terminated with \n -- make it happy */
snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
free(result);
return(1);
}
static int
_getservbyname_yp(line)
char *line;
{
char *result;
int resultlen;
char buf[YPMAXRECORD + 2];
if(!yp_domain) {
if(yp_get_default_domain(&yp_domain))
return (0);
}
snprintf(buf, sizeof(buf), "%s/%s", ___getservbyname_yp,
___getservbyproto_yp);
___getservbyname_yp = 0;
___getservbyproto_yp = NULL;
if (yp_match(yp_domain, "services.byname", buf, strlen(buf),
&result, &resultlen)) {
return(0);
}
/* getservent() expects lines terminated with \n -- make it happy */
snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
free(result);
return(1);
}
static int
_getservent_yp(line)
char *line;
{
static char *key = NULL;
static int keylen;
char *lastkey, *result;
int resultlen;
int rv;
if(!yp_domain) {
if(yp_get_default_domain(&yp_domain))
return (0);
}
if (!serv_stepping_yp) {
if (key)
free(key);
if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen,
&result, &resultlen))) {
serv_stepping_yp = 0;
return(0);
}
serv_stepping_yp = 1;
} else {
lastkey = key;
rv = yp_next(yp_domain, "services.byname", key, keylen, &key,
&keylen, &result, &resultlen);
free(lastkey);
if (rv) {
serv_stepping_yp = 0;
return (0);
}
}
/* getservent() expects lines terminated with \n -- make it happy */
snprintf(line, BUFSIZ, "%.*s\n", resultlen, result);
free(result);
return(1);
}
#endif
void
setservent(
int f)
{
if (servf == NULL)
servf = fopen(_PATH_SERVICES, "r" );
else
rewind(servf);
_serv_stayopen |= f;
}
void
endservent(void)
{
if (servf) {
fclose(servf);
servf = NULL;
}
_serv_stayopen = 0;
}
struct servent *
getservent(void)
{
char *p;
register char *cp, **q;
#ifdef YP
if (serv_stepping_yp && _getservent_yp(line)) {
p = (char *)&line;
goto unpack;
}
tryagain:
#endif
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
return (NULL);
again:
if ((p = fgets(line, BUFSIZ, servf)) == NULL)
return (NULL);
#ifdef YP
if (*p == '+' && _yp_check(NULL)) {
if (___getservbyname_yp != NULL) {
if (!_getservbyname_yp(line))
goto tryagain;
}
else if (___getservbyport_yp != 0) {
if (!_getservbyport_yp(line))
goto tryagain;
}
else if (!_getservent_yp(line))
goto tryagain;
}
unpack:
#endif
if (*p == '#')
goto again;
cp = strpbrk(p, "#\n");
if (cp == NULL)
goto again;
*cp = '\0';
serv.s_name = p;
p = strpbrk(p, " \t");
if (p == NULL)
goto again;
*p++ = '\0';
while (*p == ' ' || *p == '\t')
p++;
cp = strpbrk(p, ",/");
if (cp == NULL)
goto again;
*cp++ = '\0';
serv.s_port = htons((u_short)atoi(p));
serv.s_proto = cp;
q = serv.s_aliases = serv_aliases;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
cp++;
continue;
}
if (q < &serv_aliases[MAXALIASES - 1])
*q++ = cp;
cp = strpbrk(cp, " \t");
if (cp != NULL)
*cp++ = '\0';
}
*q = NULL;
return (&serv);
}
-129
View File
@@ -1,129 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/*
* Copyright (c) 1987, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions Copyright (c) 1996 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/types.h>
#include <sys/uio.h>
#include <netdb.h>
#include <string.h>
#include <unistd.h>
const char *h_errlist[] = {
"Resolver Error 0 (no error)",
"Unknown host", /* 1 HOST_NOT_FOUND */
"Host name lookup failure", /* 2 TRY_AGAIN */
"Unknown server error", /* 3 NO_RECOVERY */
"No address associated with name", /* 4 NO_ADDRESS */
};
int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
int *
__h_errno(void)
{
static int the_h_errno;
return &the_h_errno;
}
#define HERROR_USE_WRITEV
/*
* herror --
* print the error indicated by the h_errno value.
*/
void
herror(const char *s)
{
#if defined(HERROR_USE_WRITEV)
struct iovec iov[4];
register struct iovec *v = iov;
if (s && *s) {
v->iov_base = (char *)s;
v->iov_len = strlen(s);
v++;
v->iov_base = ": ";
v->iov_len = 2;
v++;
}
v->iov_base = (char *)hstrerror(h_errno);
v->iov_len = strlen(v->iov_base);
v++;
v->iov_base = "\n";
v->iov_len = 1;
writev(STDERR_FILENO, iov, (v - iov) + 1);
#else
/*
* no writev implementation available
*/
if (s && *s) {
write (2, s, strlen (s));
write (2, ": ", 2);
}
s = (char *)hstrerror(h_errno);
write (2, s, strlen (s));
write (2, "\n", 1);
#endif
}
const char *
hstrerror(int err)
{
if (err < 0)
return ("Resolver internal error");
else if (err < h_nerr)
return (h_errlist[err]);
return ("Unknown resolver error");
}
@@ -1,93 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/* $KAME: if_indextoname.c,v 1.7 2000/11/08 03:09:30 itojun Exp $ */
/*-
* Copyright (c) 1997, 2000
* Berkeley Software Design, Inc. 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.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
*
* BSDI Id: if_indextoname.c,v 2.3 2000/04/17 22:38:05 dab Exp
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
/*
* From RFC 2533:
*
* The second function maps an interface index into its corresponding
* name.
*
* #include <net/if.h>
*
* char *if_indextoname(unsigned int ifindex, char *ifname);
*
* The ifname argument must point to a buffer of at least IF_NAMESIZE
* bytes into which the interface name corresponding to the specified
* index is returned. (IF_NAMESIZE is also defined in <net/if.h> and
* its value includes a terminating null byte at the end of the
* interface name.) This pointer is also the return value of the
* function. If there is no interface corresponding to the specified
* index, NULL is returned, and errno is set to ENXIO, if there was a
* system error (such as running out of memory), if_indextoname returns
* NULL and errno would be set to the proper value (e.g., ENOMEM).
*/
char *
if_indextoname(unsigned int ifindex, char *ifname)
{
struct ifaddrs *ifaddrs, *ifa;
int error = 0;
if (getifaddrs(&ifaddrs) < 0)
return(NULL); /* getifaddrs properly set errno */
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK &&
ifindex == ((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index)
break;
}
if (ifa == NULL) {
error = ENXIO;
ifname = NULL;
}
else
strncpy(ifname, ifa->ifa_name, IFNAMSIZ);
freeifaddrs(ifaddrs);
errno = error;
return(ifname);
}
-152
View File
@@ -1,152 +0,0 @@
#include <machine/rtems-bsd-user-space.h>
/* $KAME: if_nameindex.c,v 1.8 2000/11/24 08:20:01 itojun Exp $ */
/*-
* Copyright (c) 1997, 2000
* Berkeley Software Design, Inc. 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.
*
* THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``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 Berkeley Software Design, Inc. 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.
*
* BSDI Id: if_nameindex.c,v 2.3 2000/04/17 22:38:05 dab Exp
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_dl.h>
#include <net/if.h>
#include <ifaddrs.h>
#include <stdlib.h>
#include <string.h>
/*
* From RFC 2553:
*
* 4.3 Return All Interface Names and Indexes
*
* The if_nameindex structure holds the information about a single
* interface and is defined as a result of including the <net/if.h>
* header.
*
* struct if_nameindex {
* unsigned int if_index;
* char *if_name;
* };
*
* The final function returns an array of if_nameindex structures, one
* structure per interface.
*
* struct if_nameindex *if_nameindex(void);
*
* The end of the array of structures is indicated by a structure with
* an if_index of 0 and an if_name of NULL. The function returns a NULL
* pointer upon an error, and would set errno to the appropriate value.
*
* The memory used for this array of structures along with the interface
* names pointed to by the if_name members is obtained dynamically.
* This memory is freed by the next function.
*
* 4.4. Free Memory
*
* The following function frees the dynamic memory that was allocated by
* if_nameindex().
*
* #include <net/if.h>
*
* void if_freenameindex(struct if_nameindex *ptr);
*
* The argument to this function must be a pointer that was returned by
* if_nameindex().
*/
struct if_nameindex *
if_nameindex(void)
{
struct ifaddrs *ifaddrs, *ifa;
unsigned int ni;
int nbytes;
struct if_nameindex *ifni, *ifni2;
char *cp;
if (getifaddrs(&ifaddrs) < 0)
return(NULL);
/*
* First, find out how many interfaces there are, and how
* much space we need for the string names.
*/
ni = 0;
nbytes = 0;
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK) {
nbytes += strlen(ifa->ifa_name) + 1;
ni++;
}
}
/*
* Next, allocate a chunk of memory, use the first part
* for the array of structures, and the last part for
* the strings.
*/
cp = malloc((ni + 1) * sizeof(struct if_nameindex) + nbytes);
ifni = (struct if_nameindex *)cp;
if (ifni == NULL)
goto out;
cp += (ni + 1) * sizeof(struct if_nameindex);
/*
* Now just loop through the list of interfaces again,
* filling in the if_nameindex array and making copies
* of all the strings.
*/
ifni2 = ifni;
for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
if (ifa->ifa_addr &&
ifa->ifa_addr->sa_family == AF_LINK) {
ifni2->if_index =
((struct sockaddr_dl*)ifa->ifa_addr)->sdl_index;
ifni2->if_name = cp;
strcpy(cp, ifa->ifa_name);
ifni2++;
cp += strlen(cp) + 1;
}
}
/*
* Finally, don't forget to terminate the array.
*/
ifni2->if_index = 0;
ifni2->if_name = NULL;
out:
freeifaddrs(ifaddrs);
return(ifni);
}
void
if_freenameindex(struct if_nameindex *ptr)
{
free(ptr);
}

Some files were not shown because too many files have changed in this diff Show More