summaryrefslogtreecommitdiff
path: root/net/pptp/patches/patch-ad
blob: 70a485ff2d92cf1c640d9dc1d9e1983caa80e444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
$NetBSD: patch-ad,v 1.1.1.1 2000/04/10 01:14:02 jtk Exp $

Index: pptp_gre.c
--- pptp_gre.c.orig	1998/09/02 14:40:54
+++ pptp_gre.c	1999/02/12 14:23:29
@@ -5,10 +5,10 @@
  * $Id: patch-ad,v 1.1.1.1 2000/04/10 01:14:02 jtk Exp $
  */
 
+#include <sys/types.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <unistd.h>
@@ -34,12 +34,12 @@
 
 #if 1
 #include <stdio.h>
-void print_packet(int fd, void *pack, unsigned len) {
+void print_packet(int fd, void *pack, unsigned len, const char *msg) {
   unsigned char *b = (unsigned char *)pack;
   unsigned i,j;
   FILE *out = fdopen(fd, "w");
 
-  fprintf(out,"-- begin packet (%u) --\n", len);
+  fprintf(out,"-- begin %s packet (%u) --\n", msg, len);
   for (i=0; i<len; i+=16) {
     for (j=0; j<8; j++)
       if (i+2*j+1<len)
@@ -119,6 +119,8 @@
   /*  this is the only blocking read we will allow */
   if (start>=end) {
     if ((status=read(fd,buffer,sizeof(buffer)))<0) return status;
+    if (status == 0)
+	return -1;			/* FD is closed */
     end = status; start = 0;
   } 
   
@@ -198,6 +200,7 @@
     ip_len = (buffer[0]&0xF)*4;
   header = (struct pptp_gre_header *)(buffer+ip_len);
 
+/*  print_packet(2, buffer, status, "in");*/
   /* verify packet (else discard) */
   if (((ntoh8(header->ver)&0x7F)!=PPTP_GRE_VER) || /* version should be 1   */
       (ntoh16(header->protocol)!=PPTP_GRE_PROTO)|| /* GRE protocol for PPTP */
@@ -258,7 +261,7 @@
   u.header.call_id	= hton16(pptp_gre_call_id);
   
   /* special case ACK with no payload */
-  if (pack==NULL) 
+  if (pack==NULL) {
     if (ack_sent != seq_recv) {
       u.header.ver |= hton8(PPTP_GRE_FLAG_A);
       u.header.payload_len = hton16(0);
@@ -266,6 +269,7 @@
       ack_sent = seq_recv;
       return write(fd, &u.header, sizeof(u.header)-sizeof(u.header.seq));
     } else return 0; /* we don't need to send ACK */
+  }
   /* send packet with payload */
   u.header.flags |= hton8(PPTP_GRE_FLAG_S);
   u.header.seq    = hton32(seq);
@@ -283,7 +287,7 @@
   /* record and increment sequence numbers */
   seq_sent = seq; seq++;
   /* write this baby out to the net */
-  /* print_packet(2, u.buffer, header_len+len); */
+/*  print_packet(2, u.buffer, header_len+len, "out");*/
   return write(fd, u.buffer, header_len+len);
 }