home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Source Code 1992 March
/
Source_Code_CD-ROM_Walnut_Creek_March_1992.iso
/
usenet
/
altsrcs
/
3
/
3298
/
netinp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-05-06
|
2KB
|
125 lines
/* History:
5/1/91 DJB baseline public domain. todo: eliminate this file.
Derived from authd 3.01, DJB.
*/
#ifdef USENETSTAT
#include "confnonsfinet.h"
#ifdef NONSFINET
#define NETSTAT "/usr/bin/netstat -n -A"
#endif
/* End of machine define-mod section. */
#ifndef NETSTAT
#define NETSTAT "/usr/ucb/netstat -n -A -f inet"
#endif
#ifndef NETSTATBUF
#define NETSTATBUF 200 /* 80 would suffice */
#endif
#ifndef NETSTATREMOTE
#define NETSTATREMOTE 49 /* has to be 53 for SunOS 4.1.1, I think */
#endif
#ifndef NETSTATWIDTH
#define NETSTATWIDTH 17
#endif
#ifndef REMOTESIZE
#define REMOTESIZE 100 /* guaranteed to be enough */
#endif
#endif
#include <stdio.h>
FILE *popen(); /* grrrr */
#include "kmem.h"
#include "structinpcb.h"
#ifdef USENETSTAT
#include "structtcp.h"
#else
#include "inpcblist.h"
#endif
#include "netinp.h"
#ifdef USENETSTAT
static FILE *fi;
static char remote[REMOTESIZE];
static char s[NETSTATBUF];
static int header;
static int pcb;
static struct tcpcb tcp;
static struct inpcb inp;
char *inploc;
int netinpinit(r1,r2,r3,r4,rp)
int r1;
int r2;
int r3;
int r4;
int rp;
{
fi = popen(NETSTAT,"r");
if (!fi)
return -1;
(void) sprintf(remote,"%d.%d.%d.%d.%d ",r1,r2,r3,r4,rp);
header = 0;
return 0;
}
struct inpcb *nextnetinp()
{
if (!header)
{
header = 1;
if (!fgets(s,sizeof(s),fi))
return 0;
if (!fgets(s,sizeof(s),fi))
return 0;
}
do
{
if (!fgets(s,sizeof(s),fi))
return 0; /* XXX: cannot distinguish from error */
if (sscanf(s,"%8x",&pcb) != 1)
return 0;
}
while (strncmp(s + NETSTATREMOTE,remote,NETSTATWIDTH));
if (kmemcpy((char *) &tcp,(char *) pcb,sizeof(tcp)) == -1)
return 0;
if (!tcp.t_inpcb)
return 0;
if (kmemcpy((char *) &inp,(char *) tcp.t_inpcb,sizeof(inp)) == -1)
return 0;
if (inp.inp_ppcb != (char *) pcb)
return 0;
inploc = tcp.t_inpcb;
return &inp;
}
#else
char *inploc;
static struct inpcb *inp;
int netinpinit(r1,r2,r3,r4,rp)
int r1;
int r2;
int r3;
int r4;
int rp;
{
if (inpcblistinit() == -1)
return -1;
inp = 0;
}
struct inpcb *nextnetinp()
{
inp = nextinpcb(inp);
inploc = (char *) inpcbloc;
return inp;
}
#endif