DNSãµã¼ãã¼ã¨ãåããã¦ã¿ã
ããããã°DNSãµã¼ãã¼ã¨ãåããããã¨ç¡ããªãããæ¹ç¥ããªããªãã¨æã£ãã®ã§åæ¥ã§ãåããã¦ã¿ã¾ããã ãã®è¨äºã¯æè¡è¨äºã§ã¯ããã¾ãããææ³æ¥è¨ã§ãã
æè¡ç®çã§æ¥ã¦ãã¾ã£ãæ¹ã®ããã«å ã«åèã«ããè³æãã¾ã¨ãã¾ããç§ã®æ¸ãã¦ãæ¬æã¯ãã ã®ææ³æã§ãã
åèã«ããè³æ
ãã¨Chat-GPTã«ãè²ã èãã¾ãã
ææ³
ã³ã¼ãã§ã
å ¨ä½
åæ¥ã§ãã£ããå®è£ ã§ãããããã«ã¯ã·ã³ãã«ãªå°è±¡ã§ããã é¢åãããã¦domainæååã®æå¾ã«ãã¤ã³ã¿ã¼ãæ¥ããã¿ã¼ã³ã®ãã¡ã¤ã³æååã®èªã¿åãå®è£ ã¯ãµããã¾ããã
ã試ãã ã£ãã®ã§æãã£ããç°å¢ä¾åãªã³ã¼ãã«ãªã£ã¦ãã¾ããWinSockã¨Visual Studio 2022 17.10ã§æ¸ãã¾ããã ãã¨ãããã¼ã¿ãã«ã«æ¸ãç´ããããªã£ã¦ãã¾ããããåãããã¨ãåªå ãã¾ããã
C++
C++ã®ãã£ããã¢ããã§ãã¦ãªãã®ã§å¤ãæ¸ãæ¹ãå¤ãããããã¾ãããç¹ã«IOã¾ããã¯formatãprintlnã§ããã®ã§å¤ããã ãã£ã¨constãconstexprã«ã§ããç®æãããããããã¾ãããã¬ã¬ã·ã¼ãªãã£ã¹ãã使ã£ã¦ãç®æãããããããã¾ããã
ãã¤ããªãé çªã«ç§»åãã¦èªã¿åããããæä½ãæ¸ãã¦ã¦æã£ãã®ã§ãããC++ã«ã¡ã¢ãªãã¤ããªã¹ããªã¼ã ãã»ããï¼ã¨æãã¾ãããããããã§ãªãã
ãã¤ããªèªã¿åã㯠std::ifstream
ããã¾ãããããã¯ã¡ã¢ãªãèªã¿åããã®ã§ã¯ãªãã§ãã
ã¨ããããä»å㯠std::vector<std::byte>
ã¨ãã¦æ±ãã¾ããããç¾å¨ã®C++ã§ã¯ãããç¡é£ãªãã§ãããï¼
ãã¨recv/sendãã©ããããéä¿¡ã®iostreamããã£ããããã®ã«ãªã¨æãã¾ããã
æ¨æºã«Asioå
¥ãããã¨ããåããããã®ã§ãã®è¾ºè½ã¡çãããã§ãããã
ååãªãæ§é ä½ãéæ¨æºãªã®ã§æããã¦ãã¾ãããééçã«ã¡ã³ãã¢ã¯ã»ã¹ã§ããã®ã便å©ã§ç´ããããªã ð
ã³ã¼ãã®ååã¯åå®ç¾©ãOStremã®ãªã¼ãã¼ãã¼ãã§ã³ã¼ãéããããã§ãã¾ãã
DNS
ä¸é¨ã»ãã¥ãªãã£ã¾ããããDNSã®è¾¼ã¿å ¥ã£ãä»æ§ã®é¨åã¯ããããªãã¨ãããããã¾ããããåºæ¬çãªããããåRecordé¨åã¯ããããããã¨æãã¾ããã è¦æ ¼ãæ¢ããã¨ãã«ãRFC1035èªä½ãã¢ãããã¼ãããã®ã§ã¯ãªããããçã«å¥ã®è¦æ ¼ã§æ©è½ã追å ãããã ï½ã¨ç¥ãã¾ãã(ãªãï¼) ãã±ãããTCPã§ã¯ãªãUDPã§éã£ã¦ãããã¨ãã1ãã±ããã§åã¾ãããã«512ãã¤ãã«åã¾ãããã«ãã¦ãããªã©ãåãã¦ç¥ãã¾ããã ãã±ããã®é·ããæããããã«ãã¡ã¤ã³åããã¤ã³ã¿(ãªãã»ãã)ã§åç §ã§ããæ¹æ³ã¯é¢ç½ãã£ãã§ãã
IDãä¹±æ°ã«ãããã¨æã£ã¦ããã®ã«å®æ°ã«ããã¾ã¾å¿ãã¦ã¾ããâ¦
ãã®ä»
ãã±ããã¨ã¡ã¢ãªã®ã¨ã³ãã£ã¢ã³ã®éããå¿ãã¦ã¦ããã°ãã htons
㨠stohs
å¿ãã¦ã¦è©°ã¾ã£ãããã¦ã¾ããã使ããªãã¨å¿ãã¾ããã
ã¾ãã dns_header
ã®ããããã£ã¼ã«ãã®ãã©ã°ã®å®ç¾©é ãè¦æ ¼ã®é çªéãã«å®ç¾©ãããã£ãã®ã§ãããã©ããã¦ããªã¯ã¨ã¹ããã¬ã¹ãã³ã¹ã®ã¡ã¢ãªã®ãããã³ã°ãä¸æãããã諦ãã¦å®ç¾©é ãå¤ãã¾ãããããããã§ãã