mirror of https://github.com/secdev/scapy.git
Accept None as destination (to use the default route) in SourceIP(6)Field
This commit is contained in:
parent
8dfafd7852
commit
39b3002b5e
|
@ -268,15 +268,15 @@ class SourceIPField(IPField):
|
|||
if conf.route is None:
|
||||
# unused import, only to initialize conf.route
|
||||
import scapy.route
|
||||
dst=getattr(pkt,self.dstname)
|
||||
if isinstance(dst,Gen):
|
||||
r = map(conf.route.route, dst)
|
||||
r.sort()
|
||||
if r[0] != r[-1]:
|
||||
warning("More than one possible route for %s"%repr(dst))
|
||||
iff,x,gw = r[0]
|
||||
dst = ("0.0.0.0" if self.dstname is None else
|
||||
getattr(pkt, self.dstname))
|
||||
if isinstance(dst, (Gen, list)):
|
||||
r = {conf.route.route(daddr) for daddr in dst}
|
||||
if len(r) > 1:
|
||||
warning("More than one possible route for %r" % (dst,))
|
||||
x = min(r)[1]
|
||||
else:
|
||||
iff,x,gw = conf.route.route(dst)
|
||||
x = conf.route.route(dst)[1]
|
||||
return IPField.i2h(self, pkt, x)
|
||||
|
||||
|
||||
|
|
|
@ -247,17 +247,17 @@ class SourceIP6Field(IP6Field):
|
|||
return IP6Field.i2m(self, pkt, x)
|
||||
def i2h(self, pkt, x):
|
||||
if x is None:
|
||||
dst=getattr(pkt,self.dstname)
|
||||
if isinstance(dst,Gen):
|
||||
r = map(conf.route6.route, dst)
|
||||
r.sort()
|
||||
if r[0] == r[-1]:
|
||||
x=r[0][1]
|
||||
else:
|
||||
warning("More than one possible route for %s"%repr(dst))
|
||||
return None
|
||||
if conf.route6 is None:
|
||||
# unused import, only to initialize conf.route6
|
||||
import scapy.route6
|
||||
dst = ("::" if self.dstname is None else getattr(pkt, self.dstname))
|
||||
if isinstance(dst, (Gen, list)):
|
||||
r = {conf.route6.route(daddr) for daddr in dst}
|
||||
if len(r) > 1:
|
||||
warning("More than one possible route for %r" % (dst,))
|
||||
x = min(r)[1]
|
||||
else:
|
||||
iff,x,nh = conf.route6.route(dst)
|
||||
x = conf.route6.route(dst)[1]
|
||||
return IP6Field.i2h(self, pkt, x)
|
||||
|
||||
class DestIP6Field(IP6Field, DestField):
|
||||
|
|
Loading…
Reference in New Issue