Software Design 2012年6月号ã®ããçããããã¯ã¼ã¯ããã°ã©ãã³ã°ããå¦ã«ããã«ããã£ã¦é¢ç½ãã£ãã®ã§ããããããã«ãã®ãã¼ã¸æ°ã§PF_PACKETãèªãã¨ãã¤ãã¦ãããªãèªè ãå¤ãã¦æ®å¿µããã
ã¨ãããã¨ã§ãåèã¾ã§ã«æ¦è¦å³ãæ¸ãã¦ã¿ã¾ããã
Cè¨èªã®ã½ã±ããããã°ã©ãã³ã°ããªãã¨ãªãåå¼·ããæ¹ã¯å¤ãã¨æãã¾ããã½ã±ããã¯ãã«ã¼ãã«å é¨ã®ãããã¯ã¼ã¯ã¬ã¤ã¤ã¼ã¨ã¦ã¼ã¶ç©ºéãçµã³ã¤ããã¤ã³ã¿ã¼ãã§ã¼ã¹ï¼APIï¼ãªããã§ãããã«ã¼ãã«å é¨ã§ã¯ãé常ãä¸å³ï¼å³å´ï¼ã®æµãã§åä¿¡ãã±ãããå¦çããã¦ããã¾ãã
- ç©çNICãåãåã£ããã±ããã¯ãããã¤ã¹ãã©ã¤ããL2ãããã³ã«ã®å¦çããã¦ãããã«L3ãããã³ã«ã®ç¨®é¡ï¼IPv4/IPv6ãªã©ã®éãï¼ã®å¤å¥ã¾ã§è¡ãã¾ãã
- å¤å¥ããçµæã«åºã¥ãã¦ãé©åãªL3ãããã³ã«ã®ãã³ãã©ã¼ãå¼ã³åºããã¦ãL3ãããã³ã«ã®å¦çããã¦ãããã«L4ãããã³ã«ã®ç¨®é¡ï¼TCP/UDP/ICMPãªã©ã®éãï¼ã®å¤å¥ãè¡ãã¾ãã
- å¤å¥ããçµæã«åºã¥ãã¦ãé©åãªL4ãããã³ã«ã®ãã³ãã©ã¼ãå¼ã³åºããã¦ãæå¾ã«ãPF_INETã®å£ãéã£ã¦ãã½ã±ããçµç±ã§ã¦ã¼ã¶ããã»ã¹ã«åã渡ããã¾ãã
ä¸æ¹ãPF_PACKETã¯ãããã¤ã¹ãã©ã¤ããL2å¦çãããç´å¾ã®ãã±ããããã£ããã³ãã¼ãã¦ã横æµãããè£å£ã¨ãã¦ç¨æããã¦ãã¾ããSocketããªã¼ãã³ããéã®ãä½æ³ï¼åªæï¼ï¼ã¯æ¬¡ã®ã¨ããã§ãé常ã¯ã第ä¸å¼æ°ã«ãPF_INETãï¼ãããã¯AF_INETï¼ãæå®ãã¾ãã
sock = socket(PF_INET, SOCK_STREAM, htons(ETH_P_IP));
ããã«ãPF_PACKETããæå®ãããã¨ã§ãåä¿¡ç´å¾ã®çãã±ãããã¦ã¼ã¶ç©ºéã®ã¢ããªã±ã¼ã·ã§ã³ã§åãåããã¨ãã§ããããã«ãªãã¾ããããã¯ããã±ããã®ã³ãã¼ãåãåã£ã¦ããã ããªã®ã§ããã®ãã±ãããåãåãã¹ãæ¬æ¥ã®ã¢ããªã±ã¼ã·ã§ã³ã«ãã¡ããã¨åããã±ããã¯å±ãã¾ãã
ã¡ãªã¿ã«ãLinuxã«ã¼ãã«ã®ãããã¯ã¼ã¯ã¬ã¤ã¤ã¼ã詳ãã解説ããæ¸ç±ãã»ã¨ãã©ãªãã¦ãå°ã£ã¦ãã¾ããç§ãããåèã«ããã®ã¯ãUnderstanding Linux Network Internalsã§ããããªãã¡ã¬ã³ã¹æ¬ã¨ãã¦ã¯ããã®ã§ãããé ããèªãã§ç解ããã«ã¯ãã¡ãã£ã¨è¦ãããããããæ¸ç±ãããã°ãç´¹ä»ãã ããã