Simple raw socket server in C/C++ on Linux

廉价感情. 提交于 2019-12-20 10:32:10

问题


I am trying to build an Ethernet network with raw sockets. I cannot use TCP/IP, UDP, or any other protocol.

This is because it will be communicating with very simple hardware that won't have the resources to handle all the different protocol layers. My network will consist of 1 host computer communicating with several pieces of hardware through an Ethernet switch. At this point I basically just want to send simple packets to each piece of hardware and to establish a simple server I can expand on. My system is running Linux and the server needs to be written in C or C++.

I have been trying to find information on how to use raw sockets, but everyone always says not to use them and provides no information. I have a pretty strong programming background but no networking experience. Can anyone provide any information on how to get started or where a relevant tutorial can be found?


回答1:


There are various tutorials on the net which are relatively easy to find. A good place for you to start would be with one such tutorial: Sockets Tutorial. It includes a simple client/server example in C (though the example is using the TCP protocol).

More results:

Raw Sockets programming on Linux with C

LINUX SOCKET PART 17 Advanced TCP/IP - THE RAW SOCKET PROGRAM EXAMPLES

Here is a comprehensive list of google search results on raw socket programming in C



来源:https://stackoverflow.com/questions/12588727/simple-raw-socket-server-in-c-c-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!