ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.h
(Generate patch)

Comparing gvpe/src/util.h (file contents):
Revision 1.3 by pcg, Fri Mar 21 23:17:01 2003 UTC vs.
Revision 1.4 by pcg, Fri Mar 28 04:05:10 2003 UTC

20*/ 20*/
21 21
22#ifndef UTIL_H__ 22#ifndef UTIL_H__
23#define UTIL_H__ 23#define UTIL_H__
24 24
25#include <sys/socket.h>
26#include <netinet/in.h>
27
28#include <map>
29
30#include "iom.h" 25#include "iom.h"
31#include "device.h" 26#include "device.h"
32
33#define SOCKADDR sockaddr_in // this is lame, I know
34 27
35/* 28/*
36 * check for an existing vped for this net, and write pid to pidfile 29 * check for an existing vped for this net, and write pid to pidfile
37 */ 30 */
38extern int write_pidfile (void); 31extern int write_pidfile (void);
70 p[5] = id; 63 p[5] = id;
71} 64}
72 65
73#define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5]) 66#define mac2id(p) (p[0] & 0x01 ? 0 : (p[4] << 8) | p[5])
74 67
75struct sockinfo
76 {
77 u32 host;
78 u16 port;
79
80 void set (const SOCKADDR *sa)
81 {
82 host = sa->sin_addr.s_addr;
83 port = sa->sin_port;
84 }
85
86 sockinfo()
87 {
88 host = port = 0;
89 }
90
91 sockinfo(const SOCKADDR &sa)
92 {
93 set (&sa);
94 }
95
96 sockinfo(const SOCKADDR *sa)
97 {
98 set (sa);
99 }
100
101 SOCKADDR *sa()
102 {
103 static SOCKADDR sa;
104
105 sa.sin_family = AF_INET;
106 sa.sin_port = port;
107 sa.sin_addr.s_addr = host;
108
109 return &sa;
110 }
111
112 operator const char *();
113 };
114
115inline bool
116operator == (const sockinfo &a, const sockinfo &b)
117{
118 return a.host == b.host && a.port == b.port;
119}
120
121inline bool
122operator < (const sockinfo &a, const sockinfo &b)
123{
124 return a.host < b.host
125 || (a.host == b.host && a.port < b.port);
126}
127
128struct sliding_window { 68struct sliding_window {
129 u32 v[(WINDOWSIZE + 31) / 32]; 69 u32 v[(WINDOWSIZE + 31) / 32];
130 u32 seq; 70 u32 seq;
131 71
132 void reset (u32 seqno) 72 void reset (u32 seqno)
158 98
159 u32 s = seqno % WINDOWSIZE; 99 u32 s = seqno % WINDOWSIZE;
160 u32 *cell = v + (s >> 5); 100 u32 *cell = v + (s >> 5);
161 u32 mask = 1 << (s & 31); 101 u32 mask = 1 << (s & 31);
162 102
163 //printf ("received seqno %08lx, seq %08lx, mask %08lx is %08lx\n", seqno, seq, mask, ismask);
164 if (*cell & mask) 103 if (*cell & mask)
165 { 104 {
166 slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n" 105 slog (L_ERR, _("received duplicate packet (received %08lx, expected %08lx)\n"
167 "possible replay attack, or just packet duplication"), seqno, seq + 1);//D 106 "possible replay attack, or just packet duplication"), seqno, seq + 1);//D
168 return false; 107 return false;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines