I'm having a hard time trying to get /system/bin/raccoon
to log the variables being sent to it through the control socket. I can get it to log with any variables sent to the command line just fine but when I try to use an external app sending the variables to /dev/socket/raccoon
I can't see them. What am I doing wrong? Below is the code. Thanks in advance
My logging code
FILE *filepntr = fopen("/sdcard/log.txt", "w");
fprintf(filepntr, "\nThis line was for shits and giggles");
fprintf(filepntr, "*argc: %d\n", *argc );
fprintf(filepntr, "*argv[0]: %s\n", *argv[0] );
if ( *argc == 1 ) {
fprintf(filepntr, "No arguments were passed.\n" );
} else {
fprintf(filepntr, "Arguments:\n" );
for ( i = 1; i < *argc; ++i ) {
fprintf(filepntr, " %d. %s\n", i, *argv[i] );
}
}
Below is the app code:
static int android_get_control_and_arguments(int *argc, char ***argv)
{
static char *args[32];
int control;
int i;
atexit(notify_death);
if ((i = android_get_control_socket("racoon")) == -1) {
return -1;
}
do_plog(LLV_DEBUG, "Waiting for control socket");
if (listen(i, 1) == -1 || (control = accept(i, NULL, 0)) == -1) {
do_plog(LLV_ERROR, "Cannot get control socket");
exit(1);
}
close(i);
fcntl(control, F_SETFD, FD_CLOEXEC);
args[0] = (*argv)[0];
for (i = 1; i < 32; ++i) {
unsigned char bytes[2];
if (recv(control, &bytes[0], 1, 0) != 1 ||
recv(control, &bytes[1], 1, 0) != 1) {
do_plog(LLV_ERROR, "Cannot get argument length");
exit(1);
} else {
int length = bytes[0] << 8 | bytes[1];
int offset = 0;
if (length == 0xFFFF) {
break;
}
args[i] = malloc(length + 1);
while (offset < length) {
int n = recv(control, &args[i][offset], length - offset, 0);
if (n > 0) {
offset += n;
} else {
do_plog(LLV_ERROR, "Cannot get argument value");
exit(1);
}
}
args[i][length] = 0;
}
}
do_plog(LLV_DEBUG, "\n*Received %s Arguments");
*argc = i;
*argv = args;
return control;
}
fopen()
andmalloc()
succeeded.