Ticket #65: scapy6.dif

File scapy6.dif, 6.9 kB (added by masanobu@iij.ad.jp, 1 year ago)
Line 
1 diff -u scapy6/scapy.py newscapy6/scapy.py
2 --- scapy6/scapy.py     2007-11-22 17:48:22.000000000 +0900
3 +++ newscapy6/scapy.py  2007-11-22 17:51:48.000000000 +0900
4 @@ -122,11 +122,16 @@
5  LINUX=sys.platform.startswith("linux")
6  OPENBSD=sys.platform.startswith("openbsd")
7  FREEBSD=sys.platform.startswith("freebsd")
8 +NETBSD = sys.platform.startswith("netbsd")
9  DARWIN=sys.platform.startswith("darwin")
10  BIG_ENDIAN= struct.pack("H",1) == "\x00\x01"
11  X86_64 = (os.uname()[4] == 'x86_64')
12  SOLARIS=sys.platform.startswith("sunos")
13  
14 +if OPENBSD or FREEBSD or NETBSD or DARWIN:
15 +       loname = "lo0"
16 +else:
17 +       loname = "lo"
18  
19  if LINUX:
20      DNET=PCAP=0
21 @@ -1050,13 +1055,13 @@
22          for d,m,gw,i,a in self.routes:
23              aa = atol(a)
24              if aa == dst:
25 -                pathes.append((0xffffffffL,("lo",a,"0.0.0.0")))
26 +                pathes.append((0xffffffffL,(loname,a,"0.0.0.0")))
27              if (dst & m) == (d & m):
28                  pathes.append((m,(i,a,gw)))
29          if not pathes:
30              if verbose:
31                  warning("No route found (no default route?)")
32 -            return "lo","0.0.0.0","0.0.0.0" #XXX linux specific!
33 +            return loname,"0.0.0.0","0.0.0.0" #XXX linux specific!
34          # Choose the more specific route (greatest netmask).
35          # XXX: we don't care about metrics
36          pathes.sort()
37 @@ -1073,7 +1078,7 @@
38  
39  if DNET:
40      def get_if_raw_hwaddr(iff):
41 -        if iff[:2] == "lo":
42 +        if iff[:2] == loname:
43              return (772, '\x00'*6)
44          try:
45              l = dnet.intf().get(iff)
46 @@ -1103,7 +1108,7 @@
47          try:
48              return pcap.lookupdev()
49          except pcap.pcapc.EXCEPTION:
50 -            return 'lo'
51 +            return loname
52  
53      def attach_filter(s, filter):
54          warning("attach_filter() should not be called in PCAP mode")
55 @@ -1121,12 +1126,12 @@
56          return lst
57      def get_working_if():
58          for i in get_if_list():
59 -            if i == 'lo':               
60 +            if i == loname:               
61                  continue
62              ifflags = struct.unpack("16xH14x",get_if(i,SIOCGIFFLAGS))[0]
63              if ifflags & IFF_UP:
64                  return i
65 -        return "lo"
66 +        return loname
67      def attach_filter(s, filter):
68          # XXX We generate the filter on the interface conf.iface
69          # because tcpdump open the "any" interface and ppp interfaces
70 @@ -1256,14 +1261,14 @@
71          f=open("/proc/net/route","r")
72          routes = []
73          s=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
74 -        ifreq = ioctl(s, SIOCGIFADDR,struct.pack("16s16x","lo"))
75 +        ifreq = ioctl(s, SIOCGIFADDR,struct.pack("16s16x",loname))
76          addrfamily = struct.unpack("h",ifreq[16:18])[0]
77          if addrfamily == socket.AF_INET:
78 -            ifreq2 = ioctl(s, SIOCGIFNETMASK,struct.pack("16s16x","lo"))
79 +            ifreq2 = ioctl(s, SIOCGIFNETMASK,struct.pack("16s16x",loname))
80              msk = socket.ntohl(struct.unpack("I",ifreq2[20:24])[0])
81              dst = socket.ntohl(struct.unpack("I",ifreq[20:24])[0]) & msk
82              ifaddr = inet_ntoa(ifreq[20:24])
83 -            routes.append((dst, msk, "0.0.0.0", "lo", ifaddr))
84 +            routes.append((dst, msk, "0.0.0.0", loname, ifaddr))
85          else:
86              warning("Interface lo: unkown address family (%i)"% addrfamily)
87      
88 @@ -1337,7 +1342,7 @@
89          if (tmp[0] & 0xf0) == 0xe0: # mcast @
90              return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1]&0x7f,tmp[2],tmp[3])
91          iff,a,gw = conf.route.route(ip)
92 -        if iff == "lo":
93 +        if iff == loname:
94              return "ff:ff:ff:ff:ff:ff"
95          if gw != "0.0.0.0":
96              ip = gw
97 @@ -1352,7 +1357,7 @@
98          if (tmp[0] & 0xf0) == 0xe0: # mcast @
99              return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1]&0x7f,tmp[2],tmp[3])
100          iff,a,gw = conf.route.route(ip)
101 -        if ( (iff == "lo") or (ip == conf.route.get_if_bcast(iff)) ):
102 +        if ( (iff == loname) or (ip == conf.route.get_if_bcast(iff)) ):
103              return "ff:ff:ff:ff:ff:ff"
104          if gw != "0.0.0.0":
105              ip = gw
106 @@ -13209,7 +13214,7 @@
107  conf=Conf()
108  
109  betteriface = conf.route.route("0.0.0.0", verbose=0)[0]
110 -if betteriface != "lo": #XXX linux specific...
111 +if betteriface != loname: #XXX linux specific...
112      conf.iface = betteriface
113  del(betteriface)
114  
115 diff -u scapy6/scapy6.py newscapy6/scapy6.py
116 --- scapy6/scapy6.py    2007-11-22 17:48:22.000000000 +0900
117 +++ newscapy6/scapy6.py 2007-11-22 18:26:55.000000000 +0900
118 @@ -36,7 +36,16 @@
119  #############################################################################
120  
121  ETH_P_IPV6 = 0x86dd
122 +OPENBSD=sys.platform.startswith("openbsd")
123 +FREEBSD=sys.platform.startswith("freebsd")
124  NETBSD = sys.platform.startswith("netbsd")
125 +DARWIN=sys.platform.startswith("darwin")
126 +WINDOWS = sys.platform.startswith("win")
127 +
128 +if OPENBSD or FREEBSD or NETBSD or DARWIN:
129 +       loname = "lo0"
130 +else:
131 +       loname = "lo"
132  
133  # From net/ipv6.h on Linux (+ Additions)
134  IPV6_ADDR_UNICAST     = 0x01
135 @@ -81,7 +90,7 @@
136         cset = filter(lambda x: x[1] == IPV6_ADDR_SITELOCAL, laddr)
137      elif in6_ismaddr(addr):
138         if in6_ismnladdr(addr):
139 -           cset = [('::1', 16, 'lo')]
140 +           cset = [('::1', 16, loname)]
141         elif in6_ismgladdr(addr):
142             cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr)
143         elif in6_ismlladdr(addr):
144 @@ -312,7 +321,7 @@
145                  
146          if not pathes:
147              warning("No route found for IPv6 destination %s (no default route?)" % dst)
148 -            return ("lo", "::", "::") # XXX Linux specific
149 +            return (loname, "::", "::") # XXX Linux specific
150  
151          pathes.sort()
152          pathes.reverse()
153 @@ -432,7 +441,7 @@
154             nh = proc2r(nh)
155  
156              cset = [] # candidate set (possible source addresses)
157 -           if dev == 'lo':
158 +           if dev == loname:
159                 if d == '::':
160                     continue
161                 cset = ['::1']
162 @@ -459,7 +468,7 @@
163          # Just some dummy values for now
164          xx = "::1"
165          scope = 128
166 -        ifname = "lo"
167 +        ifname = loname
168          ret.append(xx, scope, ifname)
169          return ret
170  
171 @@ -469,7 +478,7 @@
172          d = '::'
173          dp = 0
174          nh = '::'
175 -        dev = 'lo'
176 +        dev = loname
177          cset = ['::1']
178          routes.append((d, dp, nh, dev, cset))
179          return routes
180 @@ -528,10 +537,9 @@
181                  ok = l.find('Destination')
182                  continue
183              # gv 12/12/06: under debugging     
184 -           #if NETBSD:
185 -           #    dest,nh,fl,_,_,_,dev = l.split()[:7]
186 -           #else:
187 -           if 1:
188 +           if NETBSD or OPENBSD:
189 +               d,nh,fl,_,_,_,dev = l.split()[:7]
190 +           else:       # FREEBSD or DARWIN
191                  d,nh,fl,dev = l.split()[:4]
192             if filter(lambda x: x[2] == dev, lifaddr) == []:
193                 continue
194 @@ -553,7 +561,7 @@
195                 d,dev = d.split('%')
196             if '%' in nh:
197                 nh,dev = nh.split('%')
198 -           if 'lo' in dev:
199 +           if loname in dev:
200                 cset = ['::1']
201                 nh = '::'
202              else:
203 @@ -690,7 +698,7 @@
204      
205          iff,a,nh = conf.route6.route(ip6, dev=conf.iface)
206  
207 -        if iff == "lo":
208 +        if iff == loname:
209              return "ff:ff:ff:ff:ff:ff"
210  
211          if nh != '::':