Redirect fprintf output to port

I worked in Java and know basic C.

I need to debug code that was not written by me. In my Java projects, I use log4j with the following configuration:

log4j.rootCategory=INFO, A1, socket
log4j.appender.socket=org.apache.log4j.net.SocketAppender
log4j.appender.socket.remoteHost=localhost
log4j.appender.socket.port=4445
log4j.appender.socket.locationInfo=true
log4j.appender.A1=org.apache.log4j.ConsoleAppender

After that, I use the beanmill plugin in NetBeans to read the magazine to find out the origin of the magazine. You can find the source code for the line in the output log, but it takes time, and I have to do this for a lot of operators. Beanmill makes this as easy as clicking on a recorded line.

Now I need to work with some C code that uses many operators fprintf.

Any idea how I can achieve what I'm doing with log4j and beanmill by redirecting the output fprintfto port 4445?

I work on Windows XP, with MinGW and NetBeans 7.3.

+5
1

, localhost:4445.

fprintf . fprintf.

, fprintf . fprintfsock, . Windows - :

#define fprintf(a,b,...) fprintfsock(a,b,__VA_ARGS__)

void fprintfsock( SOCKET s, const char* f, ... )
{
    va_list a;
    va_start( a, f );
    int l = vsnprintf( 0, 0, f, a );
    char* buf = (char*) malloc( l + 1 );
    va_start( a, f );
    vsnprintf( buf, l, f, a );
    send( s, buf, l, 0 );
    free( buf );
}
+2

All Articles