I want to write a socket program in Linux. So it'll use glibc system calls like socket(), bind(), listen(), write() etc.
I wonder, can i compile it without any changing in FreeBSD, Solaris or Mac OS? If yes, is it called "posix standards"?
I want to write a socket program in Linux. So it'll use glibc system calls like socket(), bind(), listen(), write() etc.
I wonder, can i compile it without any changing in FreeBSD, Solaris or Mac OS? If yes, is it called "posix standards"?
Socket (), bind (), write () are all Posix functions and using them will make your code portable across a wide range of POSIX complaint operating systems.
Linux uses glibc, however other POSIX complaint OS will use any other libc not necessarily glibc. But all the above functions (system calls) will be in implemented with the same signature and functionality and you can compile then and run the same code everywhere.
The socket calls originated with BSD but today all Unix-like OSs support them. Windows also somewhat supports these in its own flavor (called Winsock).
I don't think these are part of Posix but in reality you shouldn't have portability issues.
Btw, when you do a 'man 2 socket' (or whatever call) it shows useful history and standards info at the bottom.
All the systems you mention follow the Single UNIX Specification, and have POSIX:2001 as a common denominator (see the compliance section), so that's what you want to target.
The GNU libc has many functions that are not in POSIX however. To see whether you can use a particular function you can look at the "CONFORMING TO" section of the relevant manpage, or refer to the GNU libc manual. For example we can see in socket(2) that socket conforms to POSIX.1-2001, so you can use it.
For more background on this, read 1.2 Standards and Portability.
One of the most portable ways you can do networking is using the Asio library from Boost:
http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio.html
It's easy to use and portable to both Windows as well as Unix/Posix systems (like Linux, Mac, the various BSDs, etc.)