- Posts: 7
- Thank you received: 0
Cross-platform raw socket programming
6 years 7 months ago #9
by Robinson
Cross-platform raw socket programming was created by Robinson
HI,
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.
References:
arstechnica.com/civis/viewtopic.php?t=430245
Home Device Example
Thank you.
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.
References:
arstechnica.com/civis/viewtopic.php?t=430245
Home Device Example
Thank you.
Please Log in or Create an account to join the conversation.
Time to create page: 0.273 seconds