Commit 0eb2fef0 authored by Stewart Brodie's avatar Stewart Brodie
Browse files

Import of source code for Internet support binaries and utilities.

parent 3d6cd6f4
**/s/** gitlab-language=armasm linguist-language=armasm linguist-detectable=true
**/c/** gitlab-language=c linguist-language=c linguist-detectable=true
**/h/** gitlab-language=c linguist-language=c linguist-detectable=true
| Copyright 1998 Acorn Computers Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
|
| !MkMods target module [module [module ...]]
|
| The following code which forms the body of !MkMods basically does:
| for i in (....)
| do
| dir module
| amu_machine target
| up
| end
|
If "%*0" = "" Then Error Do not run me with no parameters
If "%1" = "" Then Obey !MkMods %0 arp ifconfig ifrconfig inetstat newfiler ping pong route sysctl traceroute utils
If "%1" = "" Then Obey
dir %1
amu_machine %0
up
| No new-line at the end of this command, please!
If "%2" <> "" Then Obey !MkMods %0 %*2
\ No newline at end of file
# Copyright 1998 Acorn Computers Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
TARGET= ARP
INCLUDES= C:,TCPIPLibs:
CC= cc
RM= remove
WFLAGS= fr~c~v
WIPE= -wipe
CFLAGS= -pcc -I$(INCLUDES) -c ${THROWBACK} -depend !Depend
OBJS= o.${TARGET}
LIBS= C:o.Stubs TCPIPLibs:o.Unixlib TCPIPLibs:o.Inetlib \
TCPIPLibs:o.Socklib5
.SUFFIXES: .c .o
.c.o:; $(CC) $(CFLAGS) -o $@ $<
${TARGET}: $(OBJS) $(LIBS)
Link -o $@ $(OBJS) $(LIBS)
Squeeze $@
clean:; ${RM} ${TARGET}
${WIPE} o.* ${WFLAGS}
# Dynamic dependencies:
o.ARP: c.ARP
o.ARP: TCPIPLibs:sys.h.param
o.ARP: TCPIPLibs:sys.h.types
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:machine.h.endian
o.ARP: TCPIPLibs:machine.h.ansi
o.ARP: TCPIPLibs:machine.h.types
o.ARP: TCPIPLibs:sys.h.syslimits
o.ARP: TCPIPLibs:sys.h.signal
o.ARP: TCPIPLibs:machine.h.signal
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:machine.h.param
o.ARP: TCPIPLibs:machine.h.limits
o.ARP: TCPIPLibs:sys.h.file
o.ARP: TCPIPLibs:sys.h.fcntl
o.ARP: TCPIPLibs:sys.h.types
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:sys.h.unistd
o.ARP: TCPIPLibs:sys.h.socket
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:sys.h.sysctl
o.ARP: TCPIPLibs:net.h.if
o.ARP: TCPIPLibs:sys.h.socket
o.ARP: TCPIPLibs:sys.h.time
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:net.h.if_arp
o.ARP: TCPIPLibs:sys.h.socket
o.ARP: TCPIPLibs:net.h.if_dl
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:net.h.if_types
o.ARP: TCPIPLibs:net.h.route
o.ARP: TCPIPLibs:net.h.radix
o.ARP: TCPIPLibs:netinet.h.in
o.ARP: TCPIPLibs:netinet.h.if_ether
o.ARP: TCPIPLibs:arpa.h.inet
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:h.netdb
o.ARP: TCPIPLibs:sys.h.cdefs
o.ARP: TCPIPLibs:sys.h.errno
o.ARP: C:h.kernel
o.ARP: TCPIPLibs:h.unixlib
o.ARP: TCPIPLibs:h.riscos
o.ARP: TCPIPLibs:h.nlist
o.ARP: TCPIPLibs:sys.h.cdefs
.\" Copyright (c) 1985, 1986, 1988, 1994
.\" 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.
.\"
.\" @(#)arp4.4 6.5 (Berkeley) 4/18/94
.\"
.Dd April 18, 1994
.Dt ARP 4
.Os BSD 4
.Sh NAME
.Nm arp
.Nd Address Resolution Protocol
.Sh SYNOPSIS
.Em "pseudo-device ether"
.Sh DESCRIPTION
The Address Resolution Protocol (ARP) is a protocol used to dynamically
map between Internet host addresses and 10Mb/s Ethernet addresses.
It is used by all the 10Mb/s Ethernet interface drivers.
It is not specific to Internet protocols or to 10Mb/s Ethernet,
but this implementation currently supports only that combination.
.Pp
ARP caches Internet-Ethernet address mappings.
When an interface requests a mapping for an address not in the cache,
ARP queues the message which requires the mapping and broadcasts
a message on the associated network requesting the address mapping.
If a response is provided, the new mapping is cached and any pending
message is transmitted.
ARP will queue at most one packet while waiting for a response to a
mapping request;
only the most recently ``transmitted'' packet is kept.
If the target host does not respond after several requests,
the host is considered to be down for a short period (normally 20 seconds),
allowing an error to be returned to transmission attempts during this
interval.
The error is
.Li EHOSTDOWN
for a non-responding destination host, and
.Li EHOSTUNREACH
for a non-responding router.
.Pp
The ARP cache is stored in the system routing table as
dynamically-created host routes.
The route to a directly-attached Ethernet network is installed as a
.Dq cloning
route (one with the
.Li RTF_CLONING
flag set),
causing routes to individual hosts on that network to be created on
demand.
These routes time out periodically (normally 20 minutes after validated;
entries are not validated when not in use).
An entry for a host which is not responding is a
.Dq reject
route (one with the
.Li RTF_REJECT
flag set).
.Pp
ARP entries may be added, deleted or changed with the
.Xr arp 8
utility.
Manually-added entries may be temporary or permanent,
and may be
.Dq published ,
in which case the system will respond to ARP requests for that host
as if it were the target of the request.
.Pp
In the past,
ARP was used to negotiate the use of a trailer encapsulation.
This is no longer supported.
.Pp
ARP watches passively for hosts impersonating the local host (i.e. a host
which responds to an ARP mapping request for the local host's address).
.Sh DIAGNOSTICS
.Em "duplicate IP address %x!! sent from ethernet address: %x:%x:%x:%x:%x:%x."
ARP has discovered another host on the local network which responds to
mapping requests for its own Internet address with a different Ethernet
address, generally indicating that two hosts are attempting to use the
same Internet address.
.Sh SEE ALSO
.Xr inet 4 ,
.Xr route 4 ,
.Xr arp 8 ,
.Xr ifconfig 8 ,
.Xr route 8
.sp
.Rs
.%A Plummer, D.
.%B "An Ethernet Address Resolution Protocol"
.%T RFC826
.Re
.Rs
.%A Leffler, S.J.
.%A Karels, M.J.
.%B "Trailer Encapsulations
.%T RFC893
.Re
.\" Copyright (c) 1985, 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.
.\"
.\" @(#)arp.8 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt ARP 8
.Os BSD 4.3
.Sh NAME
.Nm arp
.Nd address resolution display and control
.Sh SYNOPSIS
.Nm arp
.Ar hostname
.Nm arp
.Fl a
.Nm arp
.Fl d Ar hostname
.Nm arp
.Fl s Ar hostname ether_addr
.Op Ar temp
.Op Ar pub
.Nm arp
.Fl f Ar filename
.Sh DESCRIPTION
The
.Nm arp
program displays and modifies the Internet-to-Ethernet address translation
tables used by the address resolution protocol
.Pq Xr arp 4 .
With no flags, the program displays the current
.Tn ARP
entry for
.Ar hostname .
The host may be specified by name or by number,
using Internet dot notation.
.Pp
Available options:
.Bl -tag -width Ds
.It Fl a
The program displays all of the current
.Tn ARP
entries.
.It Fl d
A super-user may delete an entry for the host called
.Ar hostname
with the
.Fl d
flag.
.It Fl s Ar hostname ether_addr
Create an
.Tn ARP
entry for the host called
.Ar hostname
with the Ethernet address
.Ar ether_addr .
The Ethernet address is given as six hex bytes separated by colons.
The entry will be permanent unless the word
.Ar temp
is given in the command.
If the word
.Ar pub
is given, the entry will be "published"; i.e., this system will
act as an
.Tn ARP
server,
responding to requests for
.Ar hostname
even though the host address is not its own.
.It Fl f
Causes the file
.Ar filename
to be read and multiple entries to be set in the
.Tn ARP
tables. Entries
in the file should be of the form
.Pp
.Bd -filled -offset indent -compact
.Ar hostname ether_addr
.Op Ar temp
.Op Ar pub
.Ed
.Pp
with argument meanings as given above.
.El
.Sh SEE ALSO
.Xr inet 3 ,
.Xr arp 4 ,
.Xr ifconfig 8
.Sh HISTORY
The
.Nm
command appeared in
.Bx 4.3 .
/*
* Copyright (c) 1984, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Sun Microsystems, 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.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1984, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)arp.c 8.2 (Berkeley) 1/2/94";
#endif /* not lint */
/*
* arp - display, set, and delete arp table entries
*/
#include <sys/param.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/route.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#include <netdb.h>
#ifdef __unix
#include <errno.h>
#else
#include <sys/errno.h>
#include <unixlib.h>
#include <riscos.h>
#endif
#include <nlist.h>
#include <stdio.h>
#ifdef __unix
#include <paths.h>
#endif
extern int errno;
static int pid;
static int kflag;
static int nflag;
static int s = -1;
#ifdef __riscos
char *__progname = "ARP";
void
close_sock()
{
if (s >= 0)
socketclose(s);
}
#endif
main(argc, argv)
int argc;
char **argv;
{
int ch;
#ifdef __riscos
atexit(close_sock);
#else
pid = getpid();
#endif
while ((ch = getopt(argc, argv, "andfs")) != EOF)
switch((char)ch) {
case 'a':
dump(0);
exit(0);
case 'd':
if (argc < 3 || argc > 4)
usage();
delete(argv[2], argv[3]);
exit(0);
case 'n':
nflag = 1;
continue;
case 's':
if (argc < 4 || argc > 7)
usage();
exit(set(argc-2, &argv[2]) ? 1 : 0);
case 'f' :
if (argc != 3)
usage();
file(argv[2]);
exit(0);
case '?':
default:
usage();
}
if (argc != 2)
usage();
get(argv[1]);
exit(0);
}
/*
* Process a file to set standard arp entries
*/
file(name)
char *name;
{
FILE *fp;
int i, retval;
char line[100], arg[5][50], *args[5];
if ((fp = fopen(name, "r")) == NULL) {
fprintf(stderr, "arp: cannot open %s\n", name);
exit(1);
}
args[0] = &arg[0][0];
args[1] = &arg[1][0];
args[2] = &arg[2][0];
args[3] = &arg[3][0];
args[4] = &arg[4][0];
retval = 0;
while(fgets(line, 100, fp) != NULL) {
i = sscanf(line, "%s %s %s %s %s", arg[0], arg[1], arg[2],
arg[3], arg[4]);
if (i < 2) {
fprintf(stderr, "arp: bad line: %s\n", line);
retval = 1;
continue;
}
if (set(i, args))
retval = 1;
}
fclose(fp);
return (retval);
}
getsocket() {
if (s < 0) {
s = socket(PF_ROUTE, SOCK_RAW, 0);
if (s < 0) {
perror("arp: socket");
exit(1);
}
}
}
struct sockaddr_in so_mask = {8, 0, 0, { 0xffffffff}};
struct sockaddr_inarp blank_sin = {sizeof(blank_sin), AF_INET }, sin_m;
struct sockaddr_dl blank_sdl = {sizeof(blank_sdl), AF_LINK }, sdl_m;
int expire_time, flags, export_only, doing_proxy, found_entry;
struct {
struct rt_msghdr m_rtm;
char m_space[512];
} m_rtmsg;
/*
* Set an individual arp entry
*/
set(argc, argv)
int argc;
char **argv;
{
struct hostent *hp;
register struct sockaddr_inarp *sin = &sin_m;
register struct sockaddr_dl *sdl;
register struct rt_msghdr *rtm = &(m_rtmsg.m_rtm);
u_char *ea;
char *host = argv[0], *eaddr = argv[1];
getsocket();
argc -= 2;
argv += 2;
sdl_m = blank_sdl;
sin_m = blank_sin;
sin->sin_addr.s_addr = inet_addr(host);
if (sin->sin_addr.s_addr == -1) {
if (!(hp = gethostbyname(host))) {
fprintf(stderr, "arp: %s: ", host);
herror((char *)NULL);
return (1);
}
bcopy((char *)hp->h_addr, (char *)&sin->sin_addr,
sizeof sin->sin_addr);
}
ea = (u_char *)LLADDR(&sdl_m);
if (ether_aton(eaddr, ea) == 0)
sdl_m.sdl_alen = 6;
doing_proxy = flags = export_only = expire_time = 0;
while (argc-- > 0) {
if (strncmp(argv[0], "temp", 4) == 0) {
struct timeval time;
gettimeofday(&time, 0);
expire_time = time.tv_sec + 20 * 60;
}
else if (strncmp(argv[0], "pub", 3) == 0) {
flags |= RTF_ANNOUNCE;
doing_proxy = SIN_PROXY;
} else if (strncmp(argv[0], "trail", 5) == 0) {
printf("%s: Sending trailers is no longer supported\n",
host);
}
argv++;
}
tryagain:
if (rtmsg(RTM_GET) < 0) {
perror(host);
return (1);
}
sin = (struct sockaddr_inarp *)(rtm + 1);
sdl = (struct sockaddr_dl *)(sin->sin_len + (char *)sin);
if (sin->sin_addr.s_addr == sin_m.sin_addr.s_addr) {
if (sdl->sdl_family == AF_LINK &&
(rtm->rtm_flags & RTF_LLINFO) &&
!(rtm->rtm_flags & RTF_GATEWAY)) switch (sdl->sdl_type) {
case IFT_ETHER: case IFT_FDDI: case IFT_ISO88023:
case IFT_ISO88024: case IFT_ISO88025:
goto overwrite;
}
if (doing_proxy == 0) {
printf("set: can only proxy for %s\n", host);
return (1);
}
if (sin_m.sin_other & SIN_PROXY) {