2013-02-08 21 views
17

में रॉ सॉकेट क्या है जब मैं सॉकेट प्रोग्रामिंग के माध्यम से चला गया तो मैं स्पष्ट रूप से RAW_SOCKET को समझ नहीं पाया।सॉकेट प्रोग्रामिंग

मेरे समझ

है मैं इस विकल्प AF_INET के साथ एक सॉकेट खोलते हैं, तो RAW_SOCKET के मतलब मैं बना सकते हैं मेरी अब AF_INET हेडर से पहले हेडर लेकिन अंत में डेटा AF_INET प्रोटोकॉल के प्रारूप में भेजना है। क्या मेरी समझ सही है। अगर गलत कुछ मुझे समझा सकता है।

ThankYou

उत्तर

12

RAW_SOCKET उपयोगकर्ता यह इंटरनेट (आईपी) के स्तर से ऊपर खुद परिवहन परत प्रोटोकॉल है लागू करने के लिए अनुमति देते हैं। आप ट्रांसपोर्ट लेवल हेडर बनाने और इसके पीछे तर्क के लिए जिम्मेदार हैं।

------------------------------------------------------------------- 
| Ethernet (typically) header | IP header | Your header | payload | 
------------------------------------------------------------------- 

संपादित करें: एक पैकेट की तरह लग रहे हैं वहाँ Linux man page पर कच्चे सॉकेट का अच्छा विवरण दिया गया है, या here यदि आप Windows का उपयोग कर रहे हैं।

+0

क्या आप मुझे थोड़ा और स्पष्टीकरण – kar

+0

@kar उदाहरण के साथ संपादित कर सकते हैं। – KBart

1

यह आईसीएमपी (पिंग) जैसे प्रोटोकॉल के लिए भी प्रयोग किया जाता है, आपको इसे बनाने के लिए आईसीपीएम पैकेट की संरचना जाननी है। इसके अलावा अपने पैकेट को संशोधित doesn'n कर्नेल

2

तुम भी .. "पैकेट सॉकेट" है कि आप एल 2 (ईथरनेट) और एल 3 (आईपी) परतों से अधिक पूर्ण नियंत्रण करने की अनुमति देगा के साथ SOCK_RAW उपयोग कर सकते हैं आप कर सकते हैं जिसका अर्थ है पूरी तरह से कस्टम प्रस्तुत करना आप पैकेट के रूप में यह एक एनआईसी से बाहर आता है ..

यहाँ विवरण:

http://www.kernel.org/doc/man-pages/online/pages/man7/packet.7.html

http://austinmarton.wordpress.com/2011/09/14/sending-raw-ethernet-packets-from-a-specific-interface-in-c-on-linux/

33

हर परत में, पैकेट है खंड को अलग करने के लिए: हेडर, पेलोड

गैर-रॉ सॉकेट का अर्थ है कि आप केवल ट्रांसपोर्ट लेयर पेलोड निर्धारित कर सकते हैं। यानी यह ओएस कार्य है जो परिवहन, नेटवर्क और डेटा लिंक परत शीर्षलेख बनाने के लिए है।

कच्चे सॉकेट का अर्थ है कि आप पैकेट के प्रत्येक अनुभाग, या तो हेडर या पेलोड निर्धारित कर सकते हैं। कृपया ध्यान दें कि कच्चे सॉकेट एक सामान्य शब्द है। मैं कच्चे सॉकेट को वर्गीकृत करता हूं: नेटवर्क सॉकेट एंड डी डेटा-लिंक सॉकेट (या वैकल्पिक रूप से एल 3 सॉकेट और एल 2 सॉकेट)

एल 3 सॉकेट में आप नेटवर्क परत में पैकेट का हेडर और पेलोड निर्धारित कर सकते हैं। उदाहरण के लिए यदि नेटवर्क लेयर प्रोटोकॉल आईपीवी 4 है, तो आप आईपीवी 4 हेडर और पेलोड निर्धारित कर सकते हैं। इस प्रकार आप ट्रांसपोर्ट लेयर हेडर/पेलोड, आईसीएमपी हेडर/पेलोड, रूटिंग प्रोटोकॉल हेडर/पेलोड सेट कर सकते हैं।

एल 2 सॉकेट में आप डेटा लिंक परत में पैकेट का हेडर और पेलोड सेट कर सकते हैं, यानी पैकेट में सब कुछ। इस प्रकार आप एल 3 सॉकेट + एआरपी हेडर/पेलोड, पीपीपी हेडर/पेलोड, पीपीपीओई हेडर/पेलोड, .... निर्धारित करते हैं।

अब प्रोग्रामिंग में:

  • सॉकेट (AF_INET, RAW_SOCKET, ...) का अर्थ है L3 सॉकेट, नेटवर्क परत प्रोटोकॉल = आईपीवी 4
  • सॉकेट (AF_IPX, RAW_SOCKET, ...) = मतलब है L3 सॉकेट, नेटवर्क परत प्रोटोकॉल IPX
  • सॉकेट (AF_INET6, RAW_SOCKET, ...) का अर्थ है L3 सॉकेट, नेटवर्क परत प्रोटोकॉल = आईपीवी 6
  • सॉकेट (AF_PACKET, RAW_SOCKET, ...) का अर्थ है एल 2 सॉकेट, डाटा -लिंक परत प्रोटोकॉल = ईथरनेट

तीसरा पैरामीटर पेलोड प्रोटोकॉल निर्दिष्ट करता है।

-2
  Once the application creates RAW socket is used to send and 
    receive packets from source to destination those all packets are 
    treated as datagram on an unconnected socket 

      when sending IPv4 data, an application has a choice on 
    whether to specify the IPv4 header at the front of the outgoing 
    datagram for the packet. 

      If the IP_HDRINCL socket option is set to true for an IPv4 
    socket (address family of AF_INET), the application must supply the 
    IPv4 header in the outgoing data for send operations. 

      If this socket option is false (the default setting), then 
    the IPv4 header should not be in included the outgoing data for 
    send operations. 

      It is important to understand that some sockets of type 
    SOCK_RAW may receive many unexpected datagrams. For example, a PING 
    program may create a socket of type SOCK_RAW to send ICMP echo 
    requests and receive responses. While the application is expecting 
    ICMP echo responses, if several SOCK_RAW sockets are open on a 
    computer at the same time, the same datagrams may be delivered to 
    all the open sockets. An application must have a mechanism to 
    recognize and to ignore all others. 

      For a PING program, such a mechanism might include 
    inspecting the received IP header for unique identifiers in the 
    ICMP header (the application's process ID, for example) 

      TCP data cannot be sent by using raw socket 
      Referred from below link : 
        https://msdn.microsoft.com/en-us/library/windows/desktop/ms740548%28v=vs.85%29.aspx