Out of the box

Personal rants

Archive for the ‘C/C++’ Category

MiniUPnP frameworks for MacOSX

with 2 comments

UPDATE 2010.10.01: Updated the frameworks to the latest versions.
UPDATE 2010.06.20: Created a personal repository to keep track of new changes.
UPDATE 2009.08.20: Completed the redirection support for ipfw, but I’m not having enough free time lately, so I shared my work. The patch was accepted, but it requires some work to complete the support.

I packaged two parts of MiniUPnP into distinct frameworks, so developers can embed in their .app’s. MiniUPnPc is a client implementation of the Internet Gateway Device Protocol. libnatpmp is a client implementation of the NAT Port Mapping Protocol (part of the Bonjour Protocol).

You can download them here. Both frameworks are universal (PPC, x86, x86-64).

Additionally, ipfw isn’t supported by MiniUPnPd, the server implementation, so I’ll work on it during my spare time. Please, let me know if you are interested on it too.

Written by jweyrich

July 22, 2009 at 8:01 pm

Checking the OS with CPP

leave a comment »

#if defined(__APPLE__) || defined(MAC_OS_CLASSIC) \
	|| defined(MAC_OS_X) || defined(macintosh)
#	define OS_MAC
#elif defined(linux) || defined(__linux) || defined(__linux__)
#	define OS_LINUX
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#	define OS_FREEBSD
#elif defined(__NetBSD__)
#	define OS_NETBSD
#elif defined(__OpenBSD__)
#	define OS_OPENBSD
#elif defined(__MINT__)
#	define OS_MINT
#elif defined(bsdi) || defined(__bsdi) || defined(__bsdi__)
#	define OS_BSD_BASED
#elif defined(sun) || defined(__SVR4)
#	define OS_SOLARIS
#elif defined(hpux) || defined(__hpux) || defined(__hpux__)
#	define OS_HPUX
#elif defined(riscos) || defined(__riscos) || defined(__riscos__)
#	define OS_RISC_OS
#elif defined(__OS2__) || defined(__EMX__)
#	define OS_OS2
#elif defined(osf) || defined(__osf) \
	|| defined(__osf__) || defined(_OSF_SOURCE)
#	define OS_OSF
#elif defined(sgi) || defined(__sgi) \
	|| defined(__sgi__) || defined(_SGI_SOURCE)
#	define OS_IRIX
#elif defined(_AIX)
#	define OS_AIX
#elif defined(__BEOS__)
#	define OS_BEOS
#elif defined(__CYGWIN__)
#	define OS_CYGWIN
#elif defined(__VMS)
#	define OS_OPENVMS
#elif defined(__osf__)
#	define OS_OSF
#elif defined(__QNXNTO__)
#	define OS_QNXNTO
#elif defined(_arch_dreamcast)
#	define OS_DREAMCAST
#elif defined(WINDOWS) || defined(WIN32) || defined(_WIN32)
#	define OS_WINDOWS
#endif

#if defined(OS_MAC) || defined(OS_LINUX) || defined(OS_FREEBSD) \
	|| defined(OS_OPENBSD)
#	define OS_POSIX
#endif

Written by jweyrich

October 4, 2008 at 8:22 pm

Posted in C/C++, Programming

C++ smart enum

leave a comment »

#define DECLARE_ENUM_OPERATORS(type) \
	inline type operator&(type v1, type v2) \
	{ return type(int(v1) & int(v2)); } \
	inline type operator|(type v1, type v2) \
	{ return type(int(v1) | int(v2)); } \
	inline type operator^(type v1, type v2) \
	{ return type(int(v1) ^ int(v2)); } \
	inline type operator~(type v1) \
	{ return type(~int(v1)); } \
	inline type& operator|=(type& v1, type v2) \
	{ return v1 = v1 | v2; } \
	inline type& operator&=(type& v1, type v2) \
	{ return v1 = v1 & v2; } \
	inline type& operator^=(type& v1, type v2) \
	{ return v1 = v1 ^ v2; } \
	inline type& operator+=(type& v1, int v2) \
	{ return v1 = type(int(v1) + v2); } \
	inline type& operator-=(type& v1, int v2) \
	{ return v1 = type(int(v1) - v2); } \
	inline type& operator++(type& v1, int) \
	{ return v1 = type(int(v1) + 1); } \
	inline type& operator--(type& v1, int) \
	{ return v1 = type(int(v1) - 1); }

Written by jweyrich

October 4, 2008 at 8:09 pm

Posted in C/C++, Programming

Follow

Get every new post delivered to your Inbox.