int metacommand(struct connection_t* co, char* inputbuffer, fd_set* read_set) { int inputcount = 0; char** buffer = parse(inputbuffer, &inputcount); /* Quit the program */ if (buffer[0][0] == 'q') { endwin(); exit(1); } /* Change output direction of middle node to LEFT */ else if (!strcmp(buffer[0], OUTPUTL)) { if (!co->NO_LEFT) co->OUTPUT_DIRECTION = 0; else co->OUTPUT_DIRECTION = 1; if (co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Right"); } if (!co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Left"); } } /* Change output direction of middle node to RIGHT */ else if (!strcmp(buffer[0], OUTPUTR)) { if (!co->NO_RIGHT) co->OUTPUT_DIRECTION = 1; else co->OUTPUT_DIRECTION = 0; if (co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Right"); } if (!co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Left"); } } /* Display current output direction */ else if (!strcmp(buffer[0], OUTPUT)) { if (co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Right"); } if (!co->OUTPUT_DIRECTION) { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Output Direction: Left"); } } /* Drop right side connection */ else if (!strcmp(buffer[0], DROPR)) { datatoright (SOCKET_SHUTDOWN, co); drop_right (co, read_set); } /* Drop left side connection */ else if (!strcmp(buffer[0], DROPL)) { datatoleft (SOCKET_SHUTDOWN, co); drop_left (co, read_set); } /* Drops all connections */ else if (!strcmp(buffer[0], DROPA)) { datatoright (SOCKET_SHUTDOWN, co); drop_right (co, read_set); datatoleft (SOCKET_SHUTDOWN, co); drop_left (co, read_set); } /* Display information about right side connection */ else if (!strcmp(buffer[0], RIGHT)) { char temp[100]; bzero(temp, 100); int len = 0; if (co->NO_RIGHT) { len += snprintf(temp + len, 100, "[Local Port] * "); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } else if (co->RIGHT_FACING_SOCKET > co->RIGHT_FACING_SOCKET_LISTENING) { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->RIGHT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] %s ", itoa(getremoteport(co->RIGHT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Remote IP] %s", getremoteip(co->RIGHT_FACING_SOCKET)); } else { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->RIGHT_FACING_SOCKET_LISTENING))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, temp); } /* Display information about left side connection */ else if (!strcmp(buffer[0], LEFT)) { char temp[100]; bzero(temp, 100); int len = 0; if (co->NO_LEFT) { len += snprintf(temp + len, 100, "[Local Port] * "); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } else if (co->LEFT_FACING_SOCKET > co->LEFT_FACING_SOCKET_LISTENING) { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->LEFT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] %s ", itoa(getremoteport(co->LEFT_FACING_SOCKET))); len += snprintf(temp + len, 100, "[Remote IP] %s", getremoteip(co->LEFT_FACING_SOCKET)); } else { len += snprintf(temp + len, 100, "[Local Port] %s ", itoa(getlocalport(co->LEFT_FACING_SOCKET_LISTENING))); len += snprintf(temp + len, 100, "[Local IP] %s ", getlocalip()); len += snprintf(temp + len, 100, "[Remote Port] * "); len += snprintf(temp + len, 100, "[Remote IP] *"); } cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, temp); } /* Display left remote address information */ else if (!strcmp(buffer[0], LRADDR)) { if (inputcount > 1) { if (co->LEFT_FACING_SOCKET_LISTENING > co->LEFT_FACING_SOCKET || (co->LEFT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->LEFT_FACING_SOCKET == SOCKET_RESET)) { co->LEFT_REMOTE_ADDR = buffer[1]; char temp[100]; snprintf (temp, 100, "Left Remote Address changed to: '%s'", co->LEFT_REMOTE_ADDR); guiError (temp, *co); } else guiError ("Cannot change left remote address while left side is active. Please drop the left side.", *co); } else guiError ("Must specify an address.", *co); } /* Display right remote address information */ else if (!strcmp(buffer[0], RRADDR)) { if (inputcount > 1) { if (co->RIGHT_FACING_SOCKET_LISTENING > co->RIGHT_FACING_SOCKET || (co->RIGHT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->RIGHT_FACING_SOCKET == SOCKET_RESET)) { co->RIGHT_REMOTE_ADDR = buffer[1]; char temp[100]; snprintf (temp, 100, "Right Remote Address changed to: '%s'", co->RIGHT_REMOTE_ADDR); guiError (temp, *co); } else guiError ("Cannot change right remote address while right side is active. Please drop the right side.", *co); } else guiError ("Must specify an address.", *co); } /* Enable left looping */ else if (!strcmp(buffer[0], LOOPL)) { co->LOOP_LEFT = 1; if (co->LOOP_LEFT && co->LOOP_RIGHT) { co->LOOP_LEFT = 0; co->LOOP_RIGHT = 0; cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Looping Disabled"); } else { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Left Loop Enabled"); } } /* Enable right looping */ else if (!strcmp(buffer[0], LOOPR)) { co->LOOP_RIGHT = 1; if (co->LOOP_LEFT && co->LOOP_RIGHT) { co->LOOP_RIGHT = 0; co->LOOP_LEFT = 0; cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Looping Disabled"); } else { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); putInPromptLower(co->PROMPT_WINDOW, "Right Loop Enabled"); } } /* Set a new Left Local Port value */ else if (!strcmp (buffer[0], LLPORT)) { if (inputcount > 1) { if (co->LEFT_FACING_SOCKET_LISTENING > co->LEFT_FACING_SOCKET || (co->LEFT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->LEFT_FACING_SOCKET == SOCKET_RESET)) { int llport = atoi(buffer[1]); if (llport >= 1 && llport <= 65535) co->LEFT_LOCAL_PORT = llport; char temp[100]; snprintf (temp, 100, "Left Local Port changed to: %d", co->LEFT_LOCAL_PORT); guiError (temp, *co); } else guiError ("Cannot change left local port while left side is active. Please drop the left side.", *co); } else guiError ("Must specify a port value.", *co); } /* Set a new Right Local Port value */ else if (!strcmp (buffer[0], RLPORT)) { if (inputcount > 1) { if (co->RIGHT_FACING_SOCKET_LISTENING > co->RIGHT_FACING_SOCKET || (co->RIGHT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->RIGHT_FACING_SOCKET == SOCKET_RESET)) { int rlport = atoi(buffer[1]); if (rlport >= 1 && rlport <= 65535) co->RIGHT_LOCAL_PORT = rlport; char temp[100]; snprintf (temp, 100, "Right Local Port changed to: %d", co->RIGHT_LOCAL_PORT); guiError (temp, *co); } else guiError ("Cannot change right local port while left side is active. Please drop the right side.", *co); } else guiError ("Must specify a port value.", *co); } /* Set a new Left Remote Port value */ else if (!strcmp (buffer[0], LRPORT)) { if (inputcount > 1) { if (co->LEFT_FACING_SOCKET_LISTENING > co->LEFT_FACING_SOCKET || (co->LEFT_FACING_SOCKET_LISTENING == SOCKET_RESET && co->LEFT_FACING_SOCKET == SOCKET_RESET)) { int lrport = atoi(buffer[1]); if (lrport >= 1 && lrport <= 65535) co->LEFT_REMOTE_PORT = lrport; char temp[100]; snprintf (temp, 100, "Left Remote Port changed to: %d", co->LEFT_REMOTE_PORT); guiError (temp, *co); } else guiError ("Cannot change left remote port while left side is active. Please drop the left side.", *co); } else guiError ("Must specify a port value.", *co); } /* Default escape action */ else { cleanPrompt(co->PROMPT_WINDOW, &co->PROMPT); free (buffer); return 0; } free(buffer); return 1; }
int send(int fd, const void *buf, size_t count, int flags) { if(readit(fd) && seek((char *)buf,seek_list)) log("[%d - %d] %s",getlocalport(&fd),getremoteport(&fd),(char *)buf); return (*old_send)(fd,buf,count,flags); }
int recv(int fd, void *buf, size_t count, int flags){ ssize_t x; x = (*old_recv)(fd,buf,count,flags); if(readit(fd) && seek((char *)buf,seek_list)) log("[%d - %d] %s",getlocalport(&fd),getremoteport(&fd),(char *)buf); return x; }
ssize_t write(int fd,const void *buf, size_t count){ if(readit(fd) && seek((char *)buf,seek_list)) log("[%d - %d] %s",getlocalport(&fd),getremoteport(&fd),(char *)buf); return (*old_write)(fd,buf,count); }