X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fivac.git;a=blobdiff_plain;f=src%2Fivac.c;h=e3e206013aee7ba74ef556cb7ec53bbf1df44418;hp=3aad5998c56104ef3a7a598d26ba7c54d61ab3e7;hb=44d1396bcdd42a518855981fc8aa0b0fbc665231;hpb=c19ed5019b55ed603dc10ff6f8ea47bf25058589 diff --git a/src/ivac.c b/src/ivac.c index 3aad599..e3e2060 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -22,6 +22,8 @@ */ // #define USE_NCURSES +/* dont care about ncurses .. go for gtk(2)! */ +#define USE_GTK #include "ivac.h" @@ -56,16 +58,16 @@ int main(int argc,char **argv) { switch(argv[i][1]) { case 'h': usage(); - break; + return SUCCESS; case 'n': - strncpy(ivac.username,argv[i+1],CHAR_USERNAME); + strncpy(ivac.username,argv[++i],CHAR_USERNAME); break; case 'p': - ivac.net.l_port=atoi(argv[i+1]); + ivac.net.l_port=atoi(argv[++i]); break; default: usage(); - break; + return ERROR; } } else usage(); @@ -180,6 +182,7 @@ int ivac_send_quit(int channel,t_ivac *ivac) { int ivac_receive_info(int channel,t_ivac *ivac) { char data[SEND_N_MAX]; + char c_str[IVAC_CONSOLE_STRING_LEN]; int count,length; count=0; @@ -208,20 +211,25 @@ int ivac_receive_info(int channel,t_ivac *ivac) { break; case IVAC_SEND_QUIT: if(!(strncmp(data+count+2,"quit",data[1]))) + sprintf(c_str,"channel %02d: connection closed by remote host", + channel); event_math(ivac->net.connection[channel].fd,&(ivac->event), READ,REMOVE); network_close(&(ivac->net),channel); memset(&(ivac->challenger[channel]),0,sizeof(t_challenger)); + ivac_add_to_monitor(ivac,c_str); count+=6; + break; default: - printf("[ivac] ivac_receive_info, unknown character: (%c,%02x\n", + sprintf(c_str,"ivac_receive_info, unknown character: 0x%02x\n", data[count]); + ivac_add_to_monitor(ivac,c_str); return ERROR; break; } } - return SUCCESS; + return length; } int ivac_event_cb(t_event *event,void *ptr) { @@ -254,9 +262,15 @@ int ivac_event_cb(t_event *event,void *ptr) { for(channel=0;channelnet.connection[channel].status&C_ESTABL) { /* remote is sending info */ - if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) - ivac_receive_info(channel,ivac); + if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) { + if(ivac_receive_info(channel,ivac)==0) { + event_math(ivac->net.connection[channel].fd,event,READ,REMOVE); + network_close(&(ivac->net),channel); + sprintf(c_str,"channel %02d: broken pipe - disconnected",channel); + ivac_add_to_monitor(ivac,c_str); + } ivac_display_content(ivac); + } } }