Cross-platform raw socket programming

4 years 3 months ago #9 by Robinson

I have a project in C where I am doing socket programming. I've been doing research and it seems that while most library calls are the same, some differ between Linux/xBSD/yBSD. As an example, when you call socket() in Linux, you want PF_PACKET. You will include linux/if_ether.h to get the sockaddr_11 data structure. In FreeBSD, you use PF_LINK, and the data structure is simply called sockaddr. Is there some way to do this cross-platform without being too messy? I don't want to narrowly focus on Linux and then spend weeks migrating to NetBSD, should that situation arise. The problem is basically that we have to mitigate implementation risks before hardware and OS choice have been decided (a risk in itself).I'm sure it can be handled by lots of fun defines and ifdefs, but I'd rather avoid that if there's a better way.

Any help will be apprecited.

I didn't find the right solution from the Internet.

Home Device Example

Thank you.

Please Log in or Create an account to join the conversation.

Time to create page: 0.215 seconds


Neither the owner nor the website operator nor the authors of the content can be responsible for any possible losses (especilly the economical or financial ones) caused by application of the information published on these web sites. There is absolutely no warranty of the accuracy, completeness of information, text, graphics, links etc of the content of these web sites.

Trading of stocks, CFD's and forex is highly risky and can lead to high losses.