#include "ivac.h"
+int usage(void) {
+
+ puts("");
+ puts("usage: ivac <options>");
+ puts("");
+ puts("options:");
+ puts("-h \t\t show this help");
+ puts("-n <name> \t specify your name");
+ puts("-p <port> \t specify port to listen for incoming connections");
+ puts("");
+
+ return SUCCESS;
+}
+
int main(int argc,char **argv) {
/* TESTING BY NOW */
t_ivac ivac;
int i;
- if(argc!=2) {
- printf("\nusage: %s <username>\n\n",argv[0]);
- return ERROR;
+ /* default values */
+ strcpy(ivac.username,"ivac");
+ ivac.net.l_port=IVAC_LISTEN_PORT;
+
+ /* parse argv and change default values */
+ for(i=1;i<argc;i++) {
+ if(argv[i][0]=='-') {
+ switch(argv[i][1]) {
+ case 'h':
+ usage();
+ break;
+ case 'n':
+ strncpy(ivac.username,argv[i+1],CHAR_USERNAME);
+ break;
+ case 'p':
+ ivac.net.l_port=atoi(argv[i+1]);
+ break;
+ default:
+ usage();
+ break;
+ }
+ }
+ else usage();
}
- /* set username */
- strncpy(ivac.username,argv[1],CHAR_USERNAME);
/* clear challenger struct */
for(i=0;i<MAX_CONNECTIONS;i++)
memset(&(ivac.challenger[i]),0,sizeof(t_challenger));
ivac.input.mode=CONTENT_BUFFER;
input_init(&(ivac.input));
- /* set listen port (futur: read from config or entered later) */
- network_set_listen_port(&(ivac.net),IVAC_LISTEN_PORT);
/* network init */
if(network_init(&(ivac.net))==N_ERROR) {
printf("[ivac] use 'fuser -n tcp %d' to determine the process to kill!\n",
event_math(ivac.net.l_fd,&(ivac.event),READ,ADD);
event_math(0,&(ivac.event),READ,ADD);
+#ifdef USE_NCURSES
/* display init */
- // display_init(&(ivac.display));
+ display_init(&(ivac.display));
+#endif
/* display */
ivac_display(&(ivac.display));
/* start event system - callbacks used: ivac_event_cb + ivac_regular_cb */
event_start(&(ivac.event),(void *)&ivac,ivac_event_cb,ivac_regular_cb);
- // ivac_shutdown(&ivac);
-
return SUCCESS;
}
network_shutdown(&(ivac->net));
input_shutdown(&(ivac->input));
event_stop(&(ivac->event));
- // display_shutdown(&(ivac->display));
+#ifdef USE_NCURSES
+ display_shutdown(&(ivac->display));
+#endif
return SUCCESS;
}
int ivac_send_quit(int channel,t_ivac *ivac) {
- char data[6];
+ char data[7]; /* one more for \0 */
data[0]=IVAC_SEND_QUIT;
data[1]=4;
memset(&(ivac->challenger[channel]),0,sizeof(t_challenger));
count+=6;
default:
- puts("[ivac] ivac_receive_info, unknown character");
+ printf("[ivac] ivac_receive_info, unknown character: (%c,%02x\n",
+ data[count]);
return ERROR;
break;
}
/* remote is sending info */
if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds)))
ivac_receive_info(channel,ivac);
- // ivac_display_content(ivac);
+ ivac_display_content(ivac);
}
}
if(!(strncmp(arg[0],"quit",4))) {
valid=1;
sprintf(c_str,"ivac shutdown ...");
+ for(i=0;i<MAX_CONNECTIONS;i++) {
+ if(ivac->net.connection[i].status&C_ESTABL) {
+ ivac_send_quit(i,ivac);
+ network_close(&(ivac->net),i);
+ }
+ }
ivac_shutdown(ivac);
}
if(!(strncmp(arg[0],"set",3))) {