Add inet_ntoa() and replace ARP's private routine with same.

This commit is contained in:
Garrett Wollman 1995-03-16 17:32:27 +00:00
parent 9b2fa02dd9
commit ef0cdf3329
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=7088
4 changed files with 64 additions and 30 deletions

View File

@ -1,15 +1,15 @@
# @(#)Makefile 7.9 (Berkeley) 6/1/93
# $Id: Makefile,v 1.6 1995/01/10 01:57:56 bde Exp $
# $Id: Makefile,v 1.7 1995/02/27 09:16:02 ugen Exp $
.undef NOPROFILE
LIB= kern
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/.. -DKERNEL
SRCS= adddi3.c anddi3.c ashldi3.c ashrdi3.c bcmp.c cmpdi2.c divdi3.c \
ffs.c iordi3.c locc.c lshldi3.c lshrdi3.c mcount.c moddi3.c \
muldi3.c negdi2.c notdi2.c qdivrem.c random.c rindex.c scanc.c \
skpc.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \
subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
ffs.c iordi3.c inet_ntoa.c locc.c lshldi3.c lshrdi3.c mcount.c \
moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c random.c rindex.c \
scanc.c skpc.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
strncpy.c subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
.if exists(${.CURDIR}/${MACHINE}/Makefile.inc)
.PATH: ${.CURDIR}/${MACHINE}

49
sys/libkern/inet_ntoa.c Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright 1994, 1995 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that both the above copyright notice and this
* permission notice appear in all copies, that both the above
* copyright notice and this permission notice appear in all
* supporting documentation, and that the name of M.I.T. not be used
* in advertising or publicity pertaining to distribution of the
* software without specific, written prior permission. M.I.T. makes
* no representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied
* warranty.
*
* THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
* ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
* SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <netinet/in.h>
char *
inet_ntoa(struct in_addr ina)
{
static char buf[4*sizeof "123"];
unsigned char *ucp = (unsigned char *)&ina;
sprintf(buf, "%d.%d.%d.%d",
ucp[0] & 0xff,
ucp[1] & 0xff,
ucp[2] & 0xff,
ucp[3] & 0xff);
return buf;
}

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)if_ether.c 8.1 (Berkeley) 6/10/93
* $Id: if_ether.c,v 1.10 1994/12/22 22:00:29 wollman Exp $
* $Id: if_ether.c,v 1.11 1995/02/20 15:48:40 davidg Exp $
*/
/*
@ -96,24 +96,6 @@ int arpinit_done = 0;
int arp_proxyall = 1;
#endif
/*
* Support: format an IP address. There should be a standard kernel routine
* to do this.
*/
static char *
arp_ntoa(struct in_addr *x)
{
static char buf[4*sizeof "123"];
unsigned char *ucp = (unsigned char *)x;
sprintf(buf, "%d.%d.%d.%d",
ucp[0] & 0xff,
ucp[1] & 0xff,
ucp[2] & 0xff,
ucp[3] & 0xff);
return buf;
}
/*
* Timeout routine. Age arp_tab entries periodically.
*/
@ -467,13 +449,13 @@ in_arpinput(m)
sizeof (ea->arp_sha))) {
log(LOG_ERR,
"arp: ether address is broadcast for IP address %s!\n",
arp_ntoa(&isaddr));
inet_ntoa(isaddr));
goto out;
}
if (isaddr.s_addr == myaddr.s_addr) {
log(LOG_ERR,
"duplicate IP address %s! sent from ethernet address: %s\n",
arp_ntoa(&isaddr), ether_sprintf(ea->arp_sha));
inet_ntoa(isaddr), ether_sprintf(ea->arp_sha));
itaddr = myaddr;
goto reply;
}
@ -482,7 +464,7 @@ in_arpinput(m)
if (sdl->sdl_alen &&
bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen))
log(LOG_INFO, "arp info overwritten for %s by %s\n",
arp_ntoa(&isaddr), ether_sprintf(ea->arp_sha));
inet_ntoa(isaddr), ether_sprintf(ea->arp_sha));
bcopy((caddr_t)ea->arp_sha, LLADDR(sdl),
sdl->sdl_alen = sizeof(ea->arp_sha));
if (rt->rt_expire)
@ -539,7 +521,7 @@ in_arpinput(m)
rtfree(rt);
#ifdef DEBUG_PROXY
printf("arp: proxying for %s\n",
arp_ntoa(&itaddr));
inet_ntoa(itaddr));
#endif
#else
goto out;
@ -617,7 +599,7 @@ arplookup(addr, create, proxy)
if(why && create) {
log(LOG_DEBUG, "arplookup %s failed: %s\n",
arp_ntoa(&sin.sin_addr), why);
inet_ntoa(sin.sin_addr), why);
return 0;
} else if(why) {
return 0;

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)in.h 8.3 (Berkeley) 1/3/94
* $Id: in.h,v 1.6 1994/12/21 17:23:59 wollman Exp $
* $Id: in.h,v 1.7 1995/02/14 23:04:50 wollman Exp $
*/
#ifndef _NETINET_IN_H_
@ -244,12 +244,15 @@ struct ip_mreq {
#ifdef KERNEL
struct ifnet; struct mbuf; /* forward declarations for Standard C */
int in_broadcast __P((struct in_addr, struct ifnet *));
int in_canforward __P((struct in_addr));
int in_cksum __P((struct mbuf *, int));
int in_localaddr __P((struct in_addr));
u_long in_netof __P((struct in_addr));
void in_socktrim __P((struct sockaddr_in *));
char *inet_ntoa __P((struct in_addr)); /* in libkern */
#endif
#endif