home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
comm
/
amitcp-3.0ß2.lha
/
AmiTCP
/
src
/
amitcp
/
kern
/
amiga_cstat.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-03
|
15KB
|
576 lines
RCS_ID_C="$Id: amiga_cstat.c,v 3.1 1994/02/03 03:59:36 ppessi Exp $";
/*
* Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
* Helsinki University of Technology, Finland.
* All rights reserved.
*
* HISTORY
* $Log: amiga_cstat.c,v $
* Revision 3.1 1994/02/03 03:59:36 ppessi
* Changed the format of network interface names
*
* Revision 1.23 1994/01/18 02:29:17 jraja
* Added rexx_gethostname() and rexx_sethostname() functions.
*
* Revision 1.22 1993/12/31 01:23:24 ppessi
* Fixed netmask handling.
*
* Revision 1.21 1993/11/06 23:51:22 ppessi
* Added Berkeley licence. Added route tree printing routines.
* Changed some allocation routines.
*
*/
/*
* Copyright (c) 1983, 1988 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <conf.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <sys/synch.h>
#include <sys/malloc.h>
#include <sys/syslog.h>
#include <kern/amiga_includes.h>
#include <kern/amiga_rexx.h>
#include <kern/amiga_config.h>
#include <dos/rdargs.h>
#if __SASC
#include <proto/dos.h>
#elif __GNUC__
#include <inline/dos.h>
#endif
#include <net/route.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/in_pcb.h>
#include <netinet/ip_var.h>
#include <netinet/ip_icmp.h>
#include <netinet/icmp_var.h>
#include <netinet/tcp.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <api/apicalls.h>
long count = 0;
int
ultoa(unsigned long ul,char *buffer)
{
static char buf[10];
char *p;
int len;
p = buf;
*p='\0';
do {
*++p = (ul % 10)+'0';
} while (ul /= 10);
len = p - buf;
while (*buffer++ = *p--)
;
return(len);
}
int
ltoa(long l, char *buffer)
{
int len=0;
if(l<0){
*buffer++='-';
l=-l;
len++;
}
return (len + ultoa((unsigned long)l, buffer));
}
/*
* Allocate big enough buffer for reply
*/
LONG
CS_Alloc(struct CSource *reply, size_t size)
{
/* do we have enough space? */
if (reply->CS_Length < size) {
char *buffer;
if ((buffer = bsd_malloc(size, M_TEMP, 0)) == NULL){
return 0;
}
/*
* Old buffer will be freed by caller
*/
reply->CS_Buffer = buffer;
reply->CS_Length = size;
}
return 1;
}
/*
* getsockets(): a reply statics for all sockets
*
*/
struct printsocket {
struct in_addr inp_faddr; /* u_long, far addr */
u_short inp_fport;
struct in_addr inp_laddr; /* u_long, local addr */
u_short inp_lport;
short so_type; /* SOCK_STREAM, _DGRAM... */
u_short so_rcv_sb_cc; /* Recv queue size */
u_short so_snd_sb_cc; /* Send queue */
short inp_ppcb_t_state; /* State of TCP connection */
};
LONG
getsockets(struct CSource *args, UBYTE **errstrp, struct CSource *res)
{
int i, count = 0;
struct inpcb *pcb;
struct printsocket *pps, *mem;
spl_t s = splnet(); /* Critical section starts here */
/* Count number of connections */
for(pcb = udb.inp_next; pcb != &udb ; pcb = pcb->inp_next)
++count;
for(pcb = tcb.inp_next; pcb != &tcb ; pcb = pcb->inp_next)
++count;
if (count == 0) { /* return now if nothing to print */
splx(s);
return RETURN_OK;
}
/* Allocate memory */
mem = (struct printsocket *)
bsd_malloc(sizeof(struct printsocket) * (count), M_TEMP, 0);
if (mem == NULL) {
splx(s);
*errstrp = ERR_MEMORY;
return RETURN_FAIL;
}
/* Proto recv-q send-q laddr lport faddr fport state */
/* 1 1 4 1 4 1 8 1 4 1 8 1 4 1 1 1 = 42 chars */
#define STATLEN 42
if (!CS_Alloc(res, STATLEN * count + 1)) {
/* Allocation failed, free printsocket memory */
splx(s);
bsd_free(mem, M_TEMP);
*errstrp = ERR_MEMORY;
return RETURN_FAIL;
}
/* Copy information, TCP first.. */
for(pcb = tcb.inp_next, pps = mem; pcb != &tcb; pcb = pcb->inp_next, ++pps){
pps->inp_faddr = pcb->inp_faddr;
pps->inp_fport = pcb->inp_fport;
pps->inp_laddr = pcb->inp_laddr;
pps->inp_lport = pcb->inp_lport;
pps->so_type = pcb->inp_socket->so_type;
pps->so_rcv_sb_cc = pcb->inp_socket->so_rcv.sb_cc;
pps->so_snd_sb_cc = pcb->inp_socket->so_snd.sb_cc;
pps->inp_ppcb_t_state = ((struct tcpcb *)(pcb->inp_ppcb))->t_state;
}
/* ...then UDP */
for(pcb = udb.inp_next; pcb != &udb; pcb = pcb->inp_next, ++pps){
pps->inp_faddr = pcb->inp_faddr;
pps->inp_fport = pcb->inp_fport;
pps->inp_laddr = pcb->inp_laddr;
pps->inp_lport = pcb->inp_lport;
pps->so_type = pcb->inp_socket->so_type;
pps->so_rcv_sb_cc = pcb->inp_socket->so_rcv.sb_cc;
pps->so_snd_sb_cc = pcb->inp_socket->so_snd.sb_cc;
pps->inp_ppcb_t_state = 0; /* NO state for UDP */
}
splx(s); /* Critical section completed now */
/*
* Print all socket entries
*/
for(i = 0; i < count; i++)
csprintf(res, "%lc %04lx %04lx %08lx %04lx %08lx %04lx %1lx%s",
mem[i].so_type == SOCK_STREAM ? 't': 'u',
mem[i].so_rcv_sb_cc, mem[i].so_snd_sb_cc,
mem[i].inp_laddr.s_addr, mem[i].inp_lport,
mem[i].inp_faddr.s_addr, mem[i].inp_fport,
mem[i].inp_ppcb_t_state,
(i < count - 1) ? " " : "");
#if DIAGNOSTIC /* check for overrun */
if (res->CS_CurChr >= res->CS_Length)
log(LOG_ERR, "getsockets(): buffer overwritten by %ld bytes\n",
res->CS_CurChr - res->CS_Length + 1);
#endif
/*
* free mem
*/
bsd_free(mem, M_TEMP);
return RETURN_OK;
}
/*
* Get ICMP history profiles
*/
#include <netinet/icmp_var.h>
#include <netinet/ip_icmp.h>
LONG
read_icmphist(struct CSource *args, UBYTE **errstrp, struct CSource *res)
{
int i;
UBYTE *p = res->CS_Buffer;
for(i = 0;i <= ICMP_MAXTYPE; i++){
p += ultoa(icmpstat.icps_outhist[i], p);
*p++=' ';
}
for(i = 0;i <= ICMP_MAXTYPE; i++){
p += ultoa(icmpstat.icps_inhist[i], p);
*p++ = ' ';
}
*--p = '\0';
res->CS_CurChr = p - res->CS_Buffer;
return RETURN_OK;
}
/*
* Get routing tables
*/
#include <net/route.h>
#include <net/if.h>
#define DB(x) ;
/* Address families supported */
extern STRPTR KW_Protocols;
/* What is stored in the route entry */
#define NORMAL 0
#define MASK 1
#define DUPED 2
/* Our recursion depth in route tree. 32 is # of bits in IP address */
/* Other protocols may require deeper stack */
#define MAX_ROUT