SNAT,是发源地址转换,其打算是用ip数据包的源地址转换成为另外一个地方

SNAT,可能有人觉得奇怪,好好的为何要进行ip地址转换啊,为了抓明白是题目,我们若拘留一下局域网用户高达公网的规律,假而内网主机A(192.168.2.8)要跟外网主机B(61.132.62.131)通信,A向B发出IP数据包,如果没SNAT对A主机进行源地址转换,A与B主机的通讯会不正规中断,因为当路由器用内网的数目包发到公网IP后,公网IP会给您的私网IP回数据包,这时,公网IP根本就无法知道乃的私网IP应该什么走了。所以问她达到一级路由器,当然这是必之,因为从公网上从就是无法观私网IP,因此而无法让他通信。为了落实数据包的正确发送和返回,网关得将A的址转换为一个法定的公网地址,同时为以后B主机能够拿数据包发送给A,这个合法的公网地址必须是网关的外网地址,如果是另外公网地址的讲话,B会将多少包发送及任何网关,而不是A主机所当的网关,A将寿终正寝不顶B发过来的数据包,所以内网主机要高达公网就得使来合法的公网地址,而得这地址之计就是深受网关进行SNAT(出自地址转换),将内网地址转换成公网址(一般是网关的表面地址),所以大家常常会盼为为内网用户高达公网,我们得以routeros的firewall中安snat,俗称IP地址欺骗或作(masquerade)

Eval函数大家还充分熟悉,但是globalEval方法也不行少动,大多数参考手册也尚未相关api,下面就是针对那用法及源码相应介绍:

 

jQuery.globalEval()函数用于全局性地执行同一段子JavaScript代码。

示例:

var name = "全局变量";

function test(){
    var name = "局部变量";

    alert(name);                     // 局部变量

    eval( "alert(name);" );          // 局部变量

    $.globalEval( "alert(name);" );  // 全局变量
}

test();

 

好望该措施与eval方法相比起一个作用域的限定不同异即始终高居大局作用域下面,下面进行源码分析:

// Evaluates a script in a global context
// Workarounds based on findings by Jim Driscoll
// http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
globalEval: function( data ) {
    if ( data && rnotwhite.test( data ) ) {
         // We use execScript on Internet Explorer
         // We use an anonymous function so that context is window
         // rather than jQuery in Firefox
            ( window.execScript || function( data ) {
                window[ "eval" ].call( window, data );
            } )( data );
     }
 },

 

诠释里之意是关乎了这个方的实现是在Jim
Driscoll的根底之上的而将相关的篇章链接还就了端,索性链接还好打开瞅瞅,里面大概介绍了怎么受js代码在大局执行之计,对于ie浏览器而言则提供了一个未极端常用之艺术(反正自己是率先差听到)—window.execScript

window.execScript
方法会根据提供的脚本语言执行同样截脚本代码。window.execScript
方法发生星星点点只参数,第一独参数指定为实施的脚本代码段,第二个参数指定脚本代码语言类别
(缺省值为 JScript),execScript
方法执行后底代码位于全局意图域下。举例:

 var str='全局'; 
    (function(){
        var str='局部';
        window.execScript('alert(str)');  //ie 全局
}());  

 

不过这措施现在只有ie支持,早期的chrome版本也支撑现在早已放弃,具体的这个方法介绍请参考http://ued.sina.com/?p=789;

开辟注释中的网址是一个英文网站四级英语水品的自决然的运了谷歌网页翻译功能,可以谷歌不给力告诉我一筹莫展翻译,那没有办法只有能够硬在头皮读下来,怕译错把原文附上请为原文为以

For more standards-respecting browsers,
the way to do this should be to use the call function, which is a
standard function attached to every Function object.
So, eval.call(window, src) should work. But to understand why, it’s
important to know about context, in addition to scope. Every function
call has it’s own context: this is the object that’s represented by the
special value this. When we use the call function, the first parameter
is the context object we’ll use for this. This is handy for all kinds
of purposes, but for us, it’s just nice to use to set the context to
the window object – which, you’ll recall, is the global.

 

随即段是供解决方法的,对于正式浏览器而言可以以eval函数解析js代码字符串,然后通过对象冒充的艺术把作用域指向window,下面就是是协调之测试:

var str='全局'; 
(function(){
     var str='局部';
     eval.call(window, "alert(str)"); 
}());  

经过测试ie9及以上和非ie均弹有“全局“
,ie9因下弹出片,说明这个主意有见兼容性有题目呀,但是是法自然就吃非IE用的,你ie爱咋咋地吧

Sadly, eval.call(window,src) breaks on
Chrome – it complains about contexts not matching. Odd – and I was
unable to Google up why this might be so. But a couple lucky guesses
later, and I discovered that window.eval.call(window,src) works on all
non-IE browsers. Now, when I say “var j = 1”, the window[j] is the
variable that’s set… So, that’s good. Why do we have to add the
extra window. on Chrome? Not sure – I could guess, but it’s too likely
to be wrong.

 

该文作者用了反复就此了”odd“,我吗认为老”odd”,作者说于谷歌中报错了,然后拿代码修改也window.eval.call(window,src)就可以啦,正而作者所迷惑的,全局方法是无需加window直接调用的这个大家还理解,但是自开检测的时段是没出现问题的,应该是遥远了谷歌已经缓解了,最后作者还关乎火狐在执行解析this存在问题

 

At this point, I thought
we’d licked the problem. No such luck. Sure, global variables are
getting set, but it turns out that if you say: alert(this) – then you
would correctly receive the global object back on Chrome and Safari, but
not Firefox – there, you’d get back the object that was the enclosing
object before the call function got called. Very odd, and likely a bug
in their
implementation.

 

既是全局解析alert(this)肯定是window才对,而火狐弹出多年来底作用链的靶子,对于欲测试下,代码如下:

 var str='全局'; 
      (function(){
           var str='局部';
           window.eval.call(window, "alert(this)"); 
  }());  

由此检测火狐没有问题,估计火狐也是早把这题目处理了,在篇章的最后作者留了一个措施

var globalEval = function globalEval(src) {
    if (window.execScript) {
        window.execScript(src);
        return;
    }
    var fn = function() {
        window.eval.call(window,src);
    };
    fn();
};

足说此艺术就够用了,但是回过头来看看我们的jQuery源码会发觉精简了重重

data && rnotwhite.test( data )

拖欠规则确保发生数据同时是未牵动空格的数码,当然你为堪无传字符串但是没什么意思rnotwhite的概念在构造函数中

// Check if a string has a non-whitespace character in it
    rnotwhite = /\S/,

有关怎么而检测不可知发出空格或立即首外文中发生外开发者指出了如是空白的当ie8出现错误

 

by vesperaba - 2012-10-18 08:54
If src is a blank string you will get an error in IE8. To avoid that I added the following check at the beginning:

if (src == undefined || src == '') {
     return;
}

//The whole function will be:
var globalEval = function globalEval(src) {
if (src == undefined || src == '') {
     return;
}
if (window.execScript) {
    window.execScript(src);
       return;
   }
   var fn = function() {
       window.eval.call(window,src);
   };
   fn();
};

 

透过逻辑或运算来选何种措施分析,如果是用eval则是处于一个由实行之匿名函数中,结构非常简短

( window.execScript || function( data ) {
      window[ "eval" ].call( window, data );
 } )( data );

任何需小心的转业该方式没有回到值,或者可以知道呢返回undefined