2

Say ff a socket is open for Ethernet then is it same as socket in TCP/IP ? In some existing code i have found that, it supports Ethernet protocol, does that mean i can connect to this Ethernet socket using TCP socket client.

I am in confusion, please help.

Thanks in advance Sagar

Sagar
  • 1,115
  • 2
  • 13
  • 22

2 Answers2

0

A raw ethernet socket, e.g. SOCK_RAW, cannot be used for TCP communication without you writing the protocol handler (you don't want to do that). You are expected to know how to serialize/deserialize ethernet frames when a socket is opened in raw ethernet mode. SOCK_STREAM is the mode for TCP and the internet is awash with examples of TCP client/server code.

Andy Brown
  • 11,766
  • 2
  • 42
  • 61
0

There is some confusion. Ethernet is a layer 1 and 2 technology in the OSI model and the TCP/IP model. For communicating directly over 802.3, in Linux you can use packet sockets to directly generate an 802.3 frame and send it out through the NIC. You can also use packets sockets to receive 802.3 frames. Something different is TCP socket, stream sockets. Use stream sockets for a TCP connection. With a packet socket you can always receive a 802.3 frame containing an IP datagram which contains a TCP segment. However, in order to establish a TCP connection you need to have a TCP communication established between two points. If the code you saw says "Ethernet protcol", you should check it is actually doing, it could just be a misconception on the programmer side. Check the type of socket they are using.

rodolk
  • 5,606
  • 3
  • 28
  • 34