Resolve conflicts from merge of 3.2a7, take 2.

This commit is contained in:
thorpej 1997-05-27 22:51:36 +00:00
parent 57d41e13fb
commit c4aac2cbce
12 changed files with 124 additions and 116 deletions

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.7 1997/05/25 12:05:10 darrenr Exp $
# $NetBSD: Makefile,v 1.8 1997/05/27 22:51:36 thorpej Exp $
PROG= ipftest
SRCS= ipt.c ipft_sn.c ipft_ef.c ipft_td.c ipft_pc.c opt.c ipft_tx.c misc.c ip_frag.c ip_state.c ip_nat.c ipft_hx.c ip_fil.c fil.c parse.c
SRCS= ipt.c ipft_sn.c ipft_ef.c ipft_td.c ipft_pc.c opt.c ipft_tx.c misc.c ip_frag.c ip_state.c ip_nat.c ipft_hx.c ip_fil.c fil.c parse.c ip_proxy.c
NOMAN= yes
CFLAGS+=-I${.CURDIR} -I${.CURDIR}/../ipf -I${.CURDIR}/../../../sys

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipt.c,v 1.3 1997/05/25 12:05:12 darrenr Exp $ */
/* $NetBSD: ipt.c,v 1.4 1997/05/27 22:51:39 thorpej Exp $ */
/*
* (C)opyright 1993-1996 by Darren Reed.
@ -51,7 +51,7 @@
#if !defined(lint) && defined(LIBC_SCCS)
static char sccsid[] = "@(#)ipt.c 1.19 6/3/96 (C) 1993-1996 Darren Reed";
static char rcsid[] = "$Id: ipt.c,v 1.3 1997/05/25 12:05:12 darrenr Exp $";
static char rcsid[] = "Id: ipt.c,v 2.0.2.5 1997/04/30 13:59:39 darrenr Exp ";
#endif
extern char *optarg;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipmon.c,v 1.4 1997/05/25 12:05:16 darrenr Exp $ */
/* $NetBSD: ipmon.c,v 1.5 1997/05/27 22:53:48 thorpej Exp $ */
/*
* (C)opyright 1993-1996 by Darren Reed.
@ -51,13 +51,13 @@
#include <netinet/ip_compat.h>
#include <netinet/ip_fil.h>
#include "ip_proxy.h"
#include <netinet/ip_proxy.h>
#include <netinet/ip_nat.h>
#include <netinet/ip_state.h>
#if !defined(lint) && defined(LIBC_SCCS)
static char sccsid[] = "@(#)ipmon.c 1.21 6/5/96 (C)1993-1996 Darren Reed";
static char rcsid[] = "$Id: ipmon.c,v 1.4 1997/05/25 12:05:16 darrenr Exp $";
static char rcsid[] = "Id: ipmon.c,v 2.0.2.9 1997/04/30 13:54:10 darrenr Exp ";
#endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: ipnat.c,v 1.6 1997/05/25 12:05:20 darrenr Exp $ */
/* $NetBSD: ipnat.c,v 1.7 1997/05/27 22:56:10 thorpej Exp $ */
/*
* (C)opyright 1993,1994,1995 by Darren Reed.
@ -50,14 +50,14 @@
#include <ctype.h>
#include <netinet/ip_compat.h>
#include <netinet/ip_fil.h>
#include "ip_proxy.h"
#include <netinet/ip_proxy.h>
#include <netinet/ip_nat.h>
#include "kmem.h"
#if !defined(lint) && defined(LIBC_SCCS)
static char sccsid[] ="@(#)ipnat.c 1.9 6/5/96 (C) 1993 Darren Reed";
static char rcsid[] = "$Id: ipnat.c,v 1.6 1997/05/25 12:05:20 darrenr Exp $";
static char rcsid[] = "Id: ipnat.c,v 2.0.2.9 1997/05/05 14:03:55 darrenr Exp ";
#endif
#if SOLARIS

View File

@ -1,3 +1,5 @@
/* $NetBSD: resend.c,v 1.3 1997/05/27 23:08:25 thorpej Exp $ */
/*
* resend.c (C) 1995 Darren Reed
*
@ -28,26 +30,20 @@ static char sccsid[] = "@(#)resend.c 1.3 1/11/96 (C)1995 Darren Reed";
#include <netinet/ip_icmp.h>
#ifndef linux
#include <netinet/ip_var.h>
#include <netinet/tcpip.h>
#if defined(__NetBSD__)
#include <net/if_ether.h>
#else
#include <netinet/if_ether.h>
#endif
#endif
#include "ip_compat.h"
#ifdef linux
#include <linux/sockios.h>
#include "tcpip.h"
#endif
#include "ipt.h"
#include "ipsend.h"
static u_char buf[65536]; /* 1 big packet */
static void printpacket __P((ip_t *));
extern int initdevice(), arp(), sendip();
void printpacket(ip)
static void printpacket(ip)
ip_t *ip;
{
tcphdr_t *t;
@ -123,7 +119,7 @@ char *datain;
bcopy(ip, (char *)(eh + 1), len);
printpacket(ip);
if (sendip(wfd, eh, sizeof(*eh) + len) == -1)
if (sendip(wfd, (char *)eh, sizeof(*eh) + len) == -1)
{
perror("send_packet");
break;

View File

@ -1,3 +1,5 @@
/* $NetBSD: 44arp.c,v 1.3 1997/05/27 23:10:46 thorpej Exp $ */
/*
* Based upon 4.4BSD's /usr/sbin/arp
*/
@ -23,6 +25,11 @@
#include <errno.h>
#include <nlist.h>
#include <stdio.h>
#include <netinet/in.h>
#include <netinet/ip_var.h>
#include <netinet/tcp.h>
#include "ipsend.h"
/*
* lookup host and return
@ -56,7 +63,7 @@ char *addr, *eaddr;
{
int mib[6];
size_t needed;
char *malloc(), *lim, *buf, *next;
char *lim, *buf, *next;
struct rt_msghdr *rtm;
struct sockaddr_inarp *sin;
struct sockaddr_dl *sdl;

View File

@ -1,3 +1,5 @@
/* $NetBSD: ip.c,v 1.3 1997/05/27 23:10:48 thorpej Exp $ */
/*
* ip.c (C) 1995 Darren Reed
*
@ -31,17 +33,12 @@ static char sccsid[] = "%W% %G% (C)1995";
#include <netinet/if_ether.h>
#endif
#include <netinet/ip_var.h>
#include <netinet/tcpip.h>
#endif
#include "ip_compat.h"
#ifdef linux
#include "tcpip.h"
#endif
#include "ipsend.h"
static char *ipbuf = NULL, *ethbuf = NULL;
extern int arp(), sendip();
u_short chksum(buf,len)
u_short *buf;
@ -77,7 +74,7 @@ struct in_addr gwip;
bcopy((char *)buf, s + sizeof(*eh), len);
if (gwip.s_addr == last_gw.s_addr)
bcopy(last_arp, (char *)&eh->ether_dhost, 6);
else if (arp((char *)&gwip, &eh->ether_dhost) == -1)
else if (arp((char *)&gwip, (char *)&eh->ether_dhost) == -1)
{
perror("arp");
return -2;
@ -111,7 +108,7 @@ int frag;
bzero((char *)&eh->ether_shost, sizeof(eh->ether_shost));
if (last_gw.s_addr && (gwip.s_addr == last_gw.s_addr))
bcopy(last_arp, (char *)&eh->ether_dhost, 6);
else if (arp((char *)&gwip, &eh->ether_dhost) == -1)
else if (arp((char *)&gwip, (char *)&eh->ether_dhost) == -1)
{
perror("arp");
return -2;
@ -133,7 +130,7 @@ int frag;
if (!frag || (sizeof(*eh) + ntohs(ip->ip_len) < mtu))
{
ip->ip_sum = 0;
ip->ip_sum = chksum(ip, ip->ip_hl << 2);
ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
bcopy((char *)ip, ipbuf + sizeof(*eh), ntohs(ip->ip_len));
err = sendip(nfd, ipbuf, sizeof(*eh) + ntohs(ip->ip_len));
@ -206,7 +203,7 @@ int frag;
ts += hlen;
ip->ip_len = htons(ts);
ip->ip_sum = 0;
ip->ip_sum = chksum(ip, hlen);
ip->ip_sum = chksum((u_short *)ip, hlen);
bcopy((char *)ip, ipbuf + sizeof(*eh), hlen);
bcopy(s + sent, ipbuf + sizeof(*eh) + hlen, ts - hlen);
err = sendip(nfd, ipbuf, sizeof(*eh) + ts);
@ -272,7 +269,7 @@ struct in_addr gwip;
ti->ti_len = htons(thlen);
ip->ip_len = (ip->ip_hl << 2) + thlen;
ti->ti_sum = 0;
ti->ti_sum = chksum(ti, thlen + sizeof(ip_t));
ti->ti_sum = chksum((u_short *)ti, thlen + sizeof(ip_t));
bcopy((char *)&ti->ti_sport,
(char *)ip + (ip->ip_hl << 2), thlen);
@ -304,7 +301,7 @@ struct in_addr gwip;
ti->ti_len = htons(thlen);
ip->ip_len = (ip->ip_hl << 2) + thlen;
ti->ti_sum = 0;
ti->ti_sum = chksum(ti, thlen + sizeof(ip_t));
ti->ti_sum = chksum((u_short *)ti, thlen + sizeof(ip_t));
bcopy((char *)&ti->ti_sport,
(char *)ip + (ip->ip_hl << 2), sizeof(udphdr_t));
@ -325,7 +322,7 @@ struct in_addr gwip;
ic = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
ic->icmp_cksum = 0;
ic->icmp_cksum = chksum((char *)ic, sizeof(struct icmp));
ic->icmp_cksum = chksum((u_short *)ic, sizeof(struct icmp));
return send_ip(nfd, mtu, ip, gwip, 1);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: ipsend.c,v 1.3 1997/05/27 23:10:49 thorpej Exp $ */
/*
* ipsend.c (C) 1995 Darren Reed
*
@ -34,21 +36,13 @@ static char sccsid[] = "@(#)ipsend.c 1.5 12/10/95 (C)1995 Darren Reed";
#include <netinet/ip_icmp.h>
#ifndef linux
#include <netinet/ip_var.h>
#include <netinet/tcpip.h>
#endif
#include "ip_compat.h"
#ifdef linux
#include <linux/sockios.h>
#include "tcpip.h"
#endif
#include "ipt.h"
#include "ipsend.h"
extern char *optarg;
extern int optind;
extern int resolve(), optname(), initdevice(), send_packet();
char options[68];
#ifdef linux
char default_device[] = "eth0";
@ -69,7 +63,12 @@ char default_device[] = "lan0";
#endif
void usage(prog)
static void usage __P((char *));
static void do_icmp __P((ip_t *, char *));
int main __P((int, char **));
static void usage(prog)
char *prog;
{
fprintf(stderr, "Usage: %s [options] dest [flags]\n\
@ -178,7 +177,7 @@ char **argv;
ip->ip_len = sizeof(*ip);
ip->ip_hl = sizeof(*ip) >> 2;
while ((c = getopt(argc, argv, "IP:TUd:f:g:m:o:s:t:")) != -1)
while ((c = (char)getopt(argc, argv, "IP:TUd:f:g:m:o:s:t:")) != -1)
switch (c)
{
case 'I' :
@ -346,5 +345,5 @@ char **argv;
if (tcp->th_dport)
return do_socket(dev, mtu, ti, gwip);
#endif
return send_packets(dev, mtu, ti, gwip);
return send_packets(dev, mtu, (ip_t *)ti, gwip);
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: sbpf.c,v 1.3 1997/05/27 23:10:52 thorpej Exp $ */
/*
* (C)opyright October 1995 Darren Reed. (from tcplog)
*
@ -40,7 +42,7 @@
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/tcp.h>
#include <netinet/tcpip.h>
#include "ipsend.h"
#if !defined(lint) && defined(LIBC_SCCS)
static char sbpf[] = "@(#)sbpf.c 1.3 8/25/95 (C)1995 Darren Reed";

View File

@ -1,3 +1,5 @@
/* $NetBSD: iptest.c,v 1.3 1997/05/27 23:13:15 thorpej Exp $ */
/*
* ipsend.c (C) 1995 Darren Reed
*
@ -34,23 +36,16 @@ static char sccsid[] = "%W% %G% (C)1995 Darren Reed";
#include <netinet/ip_icmp.h>
#ifndef linux
#include <netinet/ip_var.h>
#include <netinet/tcpip.h>
#endif
#include "ip_compat.h"
#ifdef linux
#include <linux/sockios.h>
#include "tcpip.h"
#endif
#include "ipt.h"
#include "ipsend.h"
extern char *optarg;
extern int optind;
extern int initdevice(), resolve();
extern int ip_test1(), ip_test2(), ip_test3(), ip_test4(), ip_test5();
extern int ip_test6(), ip_test7();
char options[68];
#ifdef linux
char default_device[] = "eth0";
@ -70,9 +65,12 @@ char default_device[] = "lan0";
# endif
#endif
static void usage __P((char *));
int main __P((int, char **));
void usage(prog)
char *prog;
static void usage(prog)
char *prog;
{
fprintf(stderr, "Usage: %s [options] dest\n\
\toptions:\n\
@ -94,8 +92,8 @@ char *prog;
int main(argc, argv)
int argc;
char **argv;
int argc;
char **argv;
{
struct tcpiphdr *ti;
struct in_addr gwip;
@ -112,7 +110,8 @@ char **argv;
ip->ip_len = sizeof(*ip);
ip->ip_hl = sizeof(*ip) >> 2;
while ((c = getopt(argc, argv, "1234567IP:TUd:f:g:m:o:p:s:t:")) != -1)
while ((c = (char)getopt(argc, argv,
"1234567IP:TUd:f:g:m:o:p:s:t:")) != -1)
switch (c)
{
case '1' :
@ -191,19 +190,26 @@ char **argv;
switch (tests)
{
case 1 :
return ip_test1(dev, mtu, ti, gwip, pointtest);
ip_test1(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
case 2 :
return ip_test2(dev, mtu, ti, gwip, pointtest);
ip_test2(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
case 3 :
return ip_test3(dev, mtu, ti, gwip, pointtest);
ip_test3(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
case 4 :
return ip_test4(dev, mtu, ti, gwip, pointtest);
ip_test4(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
case 5 :
return ip_test5(dev, mtu, ti, gwip, pointtest);
ip_test5(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
case 6 :
return ip_test6(dev, mtu, ti, gwip, pointtest);
ip_test6(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
case 7 :
return ip_test7(dev, mtu, ti, gwip, pointtest);
ip_test7(dev, mtu, (ip_t *)ti, gwip, pointtest);
break;
default :
break;
}

View File

@ -1,3 +1,5 @@
/* $NetBSD: iptests.c,v 1.3 1997/05/27 23:13:17 thorpej Exp $ */
/*
* (C)opyright 1993, 1994, 1995 by Darren Reed.
*
@ -27,6 +29,9 @@ static char sccsid[] = "%W% %G% (C)1995 Darren Reed";
#endif
#include <kvm.h>
#include <sys/socket.h>
#if defined(solaris)
# include <sys/stream.h>
#endif
#include <sys/socketvar.h>
#ifdef sun
#include <sys/systm.h>
@ -56,23 +61,15 @@ static char sccsid[] = "%W% %G% (C)1995 Darren Reed";
#include <netinet/in_pcb.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
#include "ip_compat.h"
#ifdef linux
#include "tcpip.h"
#else
#include <netinet/tcpip.h>
# if defined(__SVR4) || defined(__svr4__)
#include <sys/sysmacros.h>
# endif
#endif
#include "ipsend.h"
#define PAUSE() tv.tv_sec = 0; tv.tv_usec = 10000; \
(void) select(0, NULL, NULL, NULL, &tv)
extern int send_ip(), send_tcp(), send_udp(), send_icmp(), send_ether();
extern int initdevice(), kmemcpy();
extern u_short chksum();
extern struct tcpcb *find_tcp();
void ip_test1(dev, mtu, ip, gwip, ptest)
char *dev;
@ -182,8 +179,8 @@ int ptest;
for (; i < (ntohs(ip->ip_len) * 2); i++) {
ip->ip_id = htons(id++);
ip->ip_sum = 0;
ip->ip_sum = chksum(ip, ip->ip_hl << 2);
(void) send_ether(nfd, ip, i, gwip);
ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
(void) send_ether(nfd, (char *)ip, i, gwip);
printf("%d\r", i);
fflush(stdout);
PAUSE();
@ -194,8 +191,8 @@ int ptest;
ip->ip_id = htons(id++);
ip->ip_len = htons(i);
ip->ip_sum = 0;
ip->ip_sum = chksum(ip, ip->ip_hl << 2);
(void) send_ether(nfd, ip, len, gwip);
ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
(void) send_ether(nfd, (char *)ip, len, gwip);
printf("%d\r", i);
fflush(stdout);
PAUSE();
@ -213,8 +210,8 @@ int ptest;
ip->ip_id = htons(id++);
ip->ip_len = htons(i);
ip->ip_sum = 0;
ip->ip_sum = chksum(ip, ip->ip_hl << 2);
(void) send_ether(nfd, ip, len, gwip);
ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
(void) send_ether(nfd, (char *)ip, len, gwip);
printf("%d\r", i);
fflush(stdout);
PAUSE();
@ -225,8 +222,8 @@ int ptest;
for (i = len; i > 0; i--) {
ip->ip_id = htons(id++);
ip->ip_sum = 0;
ip->ip_sum = chksum(ip, ip->ip_hl << 2);
(void) send_ether(nfd, ip, i, gwip);
ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
(void) send_ether(nfd, (char *)ip, i, gwip);
printf("%d\r", i);
fflush(stdout);
PAUSE();
@ -1047,7 +1044,7 @@ int ptest;
printf("Can't find PCB\n");
goto skip_five_and_six;
}
kmemcpy((char*)&tcb, (void *)t, sizeof(tcb));
KMCPY(&tcb, t, sizeof(tcb));
ti.ti_win = tcb.rcv_adv;
ti.ti_seq = tcb.snd_nxt - 1;
ti.ti_ack = tcb.rcv_nxt;

View File

@ -1,3 +1,5 @@
/* $NetBSD: sock.c,v 1.3 1997/05/27 23:13:19 thorpej Exp $ */
/*
* sock.c (C) 1995 Darren Reed
*
@ -53,13 +55,11 @@ static char sccsid[] = "@(#)sock.c 1.2 1/11/96 (C)1995 Darren Reed";
#include <netinet/in_pcb.h>
#include <netinet/tcp_timer.h>
#include <netinet/tcp_var.h>
#include <netinet/tcpip.h>
#include "ipsend.h"
int nproc;
struct proc *proc;
extern int initdevice(), send_tcp();
#ifndef KMEM
# ifdef _PATH_KMEM
# define KMEM _PATH_KMEM
@ -77,9 +77,17 @@ extern int initdevice(), send_tcp();
# define KERNEL "/vmunix"
#endif
#if BSD < 199103
static struct proc *getproc __P((void));
#else
static struct kinfo_proc *getproc __P((void));
#endif
int kmemcpy(buf, pos, n)
char *buf;
off_t pos;
void *pos;
int n;
{
static int kfd = -1;
@ -87,7 +95,7 @@ int n;
if (kfd == -1)
kfd = open(KMEM, O_RDONLY);
if (lseek(kfd, pos, SEEK_SET) == -1)
if (lseek(kfd, (off_t)pos, SEEK_SET) == -1)
{
perror("lseek");
return -1;
@ -107,7 +115,7 @@ struct nlist names[3] = {
};
#if BSD < 199103
struct proc *getproc()
static struct proc *getproc()
{
struct proc *p;
pid_t pid = getpid();
@ -119,21 +127,20 @@ struct proc *getproc()
fprintf(stderr, "nlist(%#x) == %d\n", names, n);
return NULL;
}
if (kmemcpy((char *)&nproc, (off_t)names[1].n_value,
sizeof(nproc)) == -1)
if (KMCPY(&nproc, names[1].n_value, sizeof(nproc)) == -1)
{
fprintf(stderr, "read nproc (%#x)\n", names[1].n_value);
return NULL;
}
siz = nproc * sizeof(struct proc);
if (kmemcpy((char *)&p, (off_t)names[0].n_value, sizeof(p)) == -1)
if (KMCPY(&p, names[0].n_value, sizeof(p)) == -1)
{
fprintf(stderr, "read(%#x,%#x,%d) proc\n",
names[0].n_value, &p, sizeof(p));
return NULL;
}
proc = (struct proc *)malloc(siz);
if (kmemcpy((char *)proc, (off_t)p, siz) == -1)
if (KMCPY(proc, p, siz) == -1)
{
fprintf(stderr, "read(%#x,%#x,%d) proc\n",
p, proc, siz);
@ -167,22 +174,21 @@ struct tcpiphdr *ti;
return NULL;
up = (struct user *)malloc(sizeof(*up));
if (kmemcpy((char *)up, (off_t)p->p_uarea, sizeof(*up)) == -1)
if (KMCPY(up, p->p_uarea, sizeof(*up)) == -1)
{
fprintf(stderr, "read(%#x,%#x) failed\n", p, p->p_uarea);
return NULL;
}
o = (struct file **)calloc(1, sizeof(*o) * (up->u_lastfile + 1));
if (kmemcpy((char *)o, (off_t)up->u_ofile,
(up->u_lastfile + 1) * sizeof(*o)) == -1)
if (KMCPY(o, up->u_ofile, (up->u_lastfile + 1) * sizeof(*o)) == -1)
{
fprintf(stderr, "read(%#x,%#x,%d) - u_ofile - failed\n",
up->u_ofile_arr, o, sizeof(*o));
return NULL;
}
f = (struct file *)calloc(1, sizeof(*f));
if (kmemcpy((char *)f, (off_t)o[fd], sizeof(*f)) == -1)
if (KMCPY(f, o[fd], sizeof(*f)) == -1)
{
fprintf(stderr, "read(%#x,%#x,%d) - o[fd] - failed\n",
up->u_ofile_arr[fd], f, sizeof(*f));
@ -190,7 +196,7 @@ struct tcpiphdr *ti;
}
s = (struct socket *)calloc(1, sizeof(*s));
if (kmemcpy((char *)s, (off_t)f->f_data, sizeof(*s)) == -1)
if (KMCPY(s, f->f_data, sizeof(*s)) == -1)
{
fprintf(stderr, "read(%#x,%#x,%d) - f_data - failed\n",
o[fd], s, sizeof(*s));
@ -198,7 +204,7 @@ struct tcpiphdr *ti;
}
i = (struct inpcb *)calloc(1, sizeof(*i));
if (kmemcpy((char *)i, (off_t)s->so_pcb, sizeof(*i)) == -1)
if (KMCPY(i, s->so_pcb, sizeof(*i)) == -1)
{
fprintf(stderr, "kvm_read(%#x,%#x,%d) - so_pcb - failed\n",
s->so_pcb, i, sizeof(*i));
@ -206,7 +212,7 @@ struct tcpiphdr *ti;
}
t = (struct tcpcb *)calloc(1, sizeof(*t));
if (kmemcpy((char *)t, (off_t)i->inp_ppcb, sizeof(*t)) == -1)
if (KMCPY(t, i->inp_ppcb, sizeof(*t)) == -1)
{
fprintf(stderr, "read(%#x,%#x,%d) - inp_ppcb - failed\n",
i->inp_ppcb, t, sizeof(*t));
@ -215,7 +221,7 @@ struct tcpiphdr *ti;
return (struct tcpcb *)i->inp_ppcb;
}
#else
struct kinfo_proc *getproc()
static struct kinfo_proc *getproc()
{
static struct kinfo_proc kp;
pid_t pid = getpid();
@ -252,7 +258,7 @@ struct tcpiphdr *ti;
return NULL;
fd = (struct filedesc *)malloc(sizeof(*fd));
if (kmemcpy((char *)fd, (void *)p->kp_proc.p_fd, sizeof(*fd)) == -1)
if (KMCPY(fd, p->kp_proc.p_fd, sizeof(*fd)) == -1)
{
fprintf(stderr, "read(%#lx,%#lx) failed\n",
(u_long)p, (u_long)p->kp_proc.p_fd);
@ -260,15 +266,14 @@ struct tcpiphdr *ti;
}
o = (struct file **)calloc(1, sizeof(*o) * (fd->fd_lastfile + 1));
if (kmemcpy((char *)o, (void *)fd->fd_ofiles,
(fd->fd_lastfile + 1) * sizeof(*o)) == -1)
if (KMCPY(o, fd->fd_ofiles, (fd->fd_lastfile + 1) * sizeof(*o)) == -1)
{
fprintf(stderr, "read(%#lx,%#lx,%d) - u_ofile - failed\n",
(u_long)fd->fd_ofiles, (u_long)o, sizeof(*o));
return NULL;
}
f = (struct file *)calloc(1, sizeof(*f));
if (kmemcpy((char *)f, (void *)o[tfd], sizeof(*f)) == -1)
if (KMCPY(f, o[tfd], sizeof(*f)) == -1)
{
fprintf(stderr, "read(%#lx,%#lx,%d) - o[tfd] - failed\n",
(u_long)o[tfd], (u_long)f, sizeof(*f));
@ -276,7 +281,7 @@ struct tcpiphdr *ti;
}
s = (struct socket *)calloc(1, sizeof(*s));
if (kmemcpy((char *)s, (void *)f->f_data, sizeof(*s)) == -1)
if (KMCPY(s, f->f_data, sizeof(*s)) == -1)
{
fprintf(stderr, "read(%#lx,%#lx,%d) - f_data - failed\n",
(u_long)f->f_data, (u_long)s, sizeof(*s));
@ -284,7 +289,7 @@ struct tcpiphdr *ti;
}
i = (struct inpcb *)calloc(1, sizeof(*i));
if (kmemcpy((char *)i, (void *)s->so_pcb, sizeof(*i)) == -1)
if (KMCPY(i, s->so_pcb, sizeof(*i)) == -1)
{
fprintf(stderr, "kvm_read(%#lx,%#lx,%d) - so_pcb - failed\n",
(u_long)s->so_pcb, (u_long)i, sizeof(*i));
@ -292,7 +297,7 @@ struct tcpiphdr *ti;
}
t = (struct tcpcb *)calloc(1, sizeof(*t));
if (kmemcpy((char *)t, (void *)i->inp_ppcb, sizeof(*t)) == -1)
if (KMCPY(t, i->inp_ppcb, sizeof(*t)) == -1)
{
fprintf(stderr, "read(%#lx,%#lx,%d) - inp_ppcb - failed\n",
(u_long)i->inp_ppcb, (u_long)t, sizeof(*t));
@ -302,12 +307,11 @@ struct tcpiphdr *ti;
}
#endif /* BSD < 199301 */
int do_socket(dev, mtu, ti, gwip, flags)
int do_socket(dev, mtu, ti, gwip)
char *dev;
int mtu;
struct tcpiphdr *ti;
struct in_addr gwip;
int flags;
{
struct sockaddr_in rsin, lsin;
struct tcpcb *t, tcb;
@ -341,7 +345,7 @@ int flags;
(void) getsockname(fd, (struct sockaddr *)&lsin, &len);
ti->ti_sport = lsin.sin_port;
printf("sport %d\n", ntohs(lsin.sin_port));
nfd = initdevice(dev, ntohs(lsin.sin_port));
nfd = initdevice(dev, ntohs(lsin.sin_port), 1);
if (!(t = find_tcp(fd, ti)))
return -1;
@ -357,12 +361,12 @@ int flags;
perror("connect");
return -1;
}
kmemcpy((char*)&tcb, (void *)t, sizeof(tcb));
KMCPY(&tcb, t, sizeof(tcb));
ti->ti_win = tcb.rcv_adv;
ti->ti_seq = tcb.snd_nxt - 1;
ti->ti_ack = tcb.rcv_nxt;
if (send_tcp(nfd, mtu, ti, gwip, TH_SYN) == -1)
if (send_tcp(nfd, mtu, (ip_t *)ti, gwip) == -1)
return -1;
(void)write(fd, "Hello World\n", 12);
sleep(2);