From bc3326e4ac44ead72ed2484726ca3b78d4702ec5 Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 11 May 2004 07:06:19 +0000 Subject: [PATCH 01/16] only set reuseaddr socket opt if regular bind call fails --- src/network.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/network.c b/src/network.c index 449dacf..3579f5a 100644 --- a/src/network.c +++ b/src/network.c @@ -27,17 +27,15 @@ int network_init(t_net *net) { addr.sin_port=htons(net->l_port); addr.sin_addr.s_addr=INADDR_ANY; - /* prevent addres in use error message */ - true=1; - if(setsockopt(net->l_fd,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(true))==-1) { - perror("[network] setsockopt call"); - return N_ERROR; - } - if(bind(net->l_fd,(struct sockaddr *)&addr, sizeof(struct sockaddr))==-1) { - perror("[network] bind call"); - return N_ERROR; + /* try harder ... */ + true=1; + if(setsockopt(net->l_fd,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(true))==-1) { + perror("[network] setsockopt call"); + return N_ERROR; + } + puts("[network] reused address"); } if(listen(net->l_fd,MAX_LISTEN_QUEUE)==-1) { -- 2.20.1 From b5512e7ee393a12bffc0b3fecabe515a2964c26b Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 11 May 2004 07:53:24 +0000 Subject: [PATCH 02/16] added quit msg to send before network close --- src/ivac.c | 36 +++++++++++++++++++++++++++++++----- src/ivac.h | 1 + 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/ivac.c b/src/ivac.c index 8b9c312..0108131 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -129,6 +129,22 @@ int ivac_send_info(int channel,t_ivac *ivac) { return SUCCESS; } +int ivac_send_quit(int channel,t_ivac *ivac) { + + char data[6]; + + data[0]=IVAC_SEND_QUIT; + data[1]=4; + strcpy(data+2,"quit"); + + if(network_send(ivac->net.connection[channel].fd,data,6)==N_ERROR) { + puts("[ivac] ivac_send_quit failed"); + return ERROR; + } + + return SUCCESS; +} + int ivac_receive_info(int channel,t_ivac *ivac) { char data[SEND_N_MAX]; @@ -158,6 +174,11 @@ int ivac_receive_info(int channel,t_ivac *ivac) { ivac->challenger[channel].av_cap|=data[count+3]; count+=4; break; + case IVAC_SEND_QUIT: + if(!(strncmp(data+count+2,"quit",data[1]))) + event_math(ivac->net.connection[channel].fd,&(ivac->event), + READ,REMOVE); + network_close(&(ivac->net),channel); default: puts("[ivac] ivac_receive_info, unknown character"); return ERROR; @@ -200,7 +221,7 @@ int ivac_event_cb(t_event *event,void *ptr) { /* 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); } } @@ -307,11 +328,16 @@ int ivac_parse_command(t_input *input,void *ptr) { if((arg[1][0]>='0')&&(arg[1][0]<='9')) channel=atoi(arg[1]); else channel=-1; if((channel>=0)&&(channelnet),channel); - if(i==N_E_NC) - sprintf(c_str,"channel %02d: no active connection",channel); - else + if(ivac->net.connection[channel].status&C_ESTABL) { + ivac_send_quit(channel,ivac); + event_math(ivac->net.connection[channel].fd,&(ivac->event), + READ,REMOVE); + network_close(&(ivac->net),channel); sprintf(c_str,"channel %02d: connection closed",channel); + memset(&(ivac->challenger[channel]),0,sizeof(t_challenger)); + } + else + sprintf(c_str,"channel %02d: no active connection",channel); } else sprintf(c_str,"invalid argument: '%s'",arg[1]); } diff --git a/src/ivac.h b/src/ivac.h index a946580..b635160 100644 --- a/src/ivac.h +++ b/src/ivac.h @@ -28,6 +28,7 @@ #define IVAC_SEND_NAME 'n' #define IVAC_SEND_G_CAP 'g' #define IVAC_SEND_AV_CAP 'c' +#define IVAC_SEND_QUIT 'q' #define NETWORK (1<<0) -- 2.20.1 From 1d24c5371e02647c8eeb4dc00ec6d667d169faa7 Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 11 May 2004 07:54:19 +0000 Subject: [PATCH 03/16] also memset challenger struct when receiving quit --- src/ivac.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ivac.c b/src/ivac.c index 0108131..4fede22 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -179,6 +179,7 @@ int ivac_receive_info(int channel,t_ivac *ivac) { event_math(ivac->net.connection[channel].fd,&(ivac->event), READ,REMOVE); network_close(&(ivac->net),channel); + memset(&(ivac->challenger[channel]),0,sizeof(t_challenger)); default: puts("[ivac] ivac_receive_info, unknown character"); return ERROR; -- 2.20.1 From 058fbd5c5879ffb26116276966465165b2fae19b Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 11 May 2004 09:40:09 +0000 Subject: [PATCH 04/16] increase count variable while parsing in ivac_receive_info --- src/ivac.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ivac.c b/src/ivac.c index 4fede22..0a29f21 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -180,6 +180,7 @@ int ivac_receive_info(int channel,t_ivac *ivac) { READ,REMOVE); network_close(&(ivac->net),channel); memset(&(ivac->challenger[channel]),0,sizeof(t_challenger)); + count+=6; default: puts("[ivac] ivac_receive_info, unknown character"); return ERROR; -- 2.20.1 From 25e53b7c9b49f76c122a7425f6533de17810759b Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 12 May 2004 07:52:19 +0000 Subject: [PATCH 05/16] added network_close_all function --- src/network.c | 10 ++++++++++ src/network.h | 1 + 2 files changed, 11 insertions(+) diff --git a/src/network.c b/src/network.c index 3579f5a..55fa2c6 100644 --- a/src/network.c +++ b/src/network.c @@ -163,6 +163,16 @@ int network_close(t_net *net,int channel) { return(network_manage_connection(net)); /* could be other channel too */ } +int network_close_all(t_net *net) { + + int channel; + + for(channel=0;channelconnection[channel].status&C_ESTABL) network_close(net,channel); + + return N_SUCCESS; +} + int network_set_connection_info(t_net *net,int channel,char *ip,int port) { if(net->connection[channel].status&C_IN_USE) { diff --git a/src/network.h b/src/network.h index 14168bf..25a9891 100644 --- a/src/network.h +++ b/src/network.h @@ -65,6 +65,7 @@ int network_set_listen_port(t_net *net,in_port_t port); int network_manage_connection(t_net *net); int network_connect(t_net *net,int channel); int network_close(t_net *net,int channel); +int network_close_all(t_net *net); int network_set_connection_info(t_net *net,int channel,char *ip,int port); int network_select(t_net *net,int channel); int network_deselect(t_net *net,int channel); -- 2.20.1 From c19ed5019b55ed603dc10ff6f8ea47bf25058589 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 12 May 2004 07:53:27 +0000 Subject: [PATCH 06/16] added usage function, added parsing of argv, some display tests .. --- src/ivac.c | 67 ++++++++++++++++++++++++++++++++++++++++++------------ src/ivac.h | 2 ++ 2 files changed, 55 insertions(+), 14 deletions(-) diff --git a/src/ivac.c b/src/ivac.c index 0a29f21..3aad599 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -25,6 +25,20 @@ #include "ivac.h" +int usage(void) { + + puts(""); + puts("usage: ivac "); + puts(""); + puts("options:"); + puts("-h \t\t show this help"); + puts("-n \t specify your name"); + puts("-p \t specify port to listen for incoming connections"); + puts(""); + + return SUCCESS; +} + int main(int argc,char **argv) { /* TESTING BY NOW */ @@ -32,13 +46,31 @@ int main(int argc,char **argv) { t_ivac ivac; int i; - if(argc!=2) { - printf("\nusage: %s \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;inet)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); - // display_shutdown(&(ivac->display)); +#ifdef USE_NCURSES + display_shutdown(&(ivac->display)); +#endif return SUCCESS; } @@ -131,7 +163,7 @@ int ivac_send_info(int channel,t_ivac *ivac) { 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; @@ -182,7 +214,8 @@ int ivac_receive_info(int channel,t_ivac *ivac) { 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; } @@ -223,7 +256,7 @@ int ivac_event_cb(t_event *event,void *ptr) { /* 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); } } @@ -286,6 +319,12 @@ int ivac_parse_command(t_input *input,void *ptr) { if(!(strncmp(arg[0],"quit",4))) { valid=1; sprintf(c_str,"ivac shutdown ..."); + for(i=0;inet.connection[i].status&C_ESTABL) { + ivac_send_quit(i,ivac); + network_close(&(ivac->net),i); + } + } ivac_shutdown(ivac); } if(!(strncmp(arg[0],"set",3))) { diff --git a/src/ivac.h b/src/ivac.h index b635160..af64d04 100644 --- a/src/ivac.h +++ b/src/ivac.h @@ -65,8 +65,10 @@ typedef struct s_ivac { } t_ivac; /* function prototypes */ +int usage(void); int ivac_shutdown(t_ivac *ivac); int ivac_send_info(int channel,t_ivac *ivac); +int ivac_send_quit(int channel,t_ivac *ivac); int ivac_receive_info(int channel,t_ivac *ivac); int ivac_event_cb(t_event *event,void *ptr); int ivac_regular_cb(t_event *event,void *ptr); -- 2.20.1 From c0de1cff899325f9a4a058d7544ddbef3a5c50b1 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 12 May 2004 14:21:38 +0000 Subject: [PATCH 07/16] some more monitor calls, fixed display when input event bug, todo: use gtk! :) --- src/ivac.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ivac.c b/src/ivac.c index 3aad599..56a687f 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" @@ -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,14 +211,19 @@ 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; } @@ -254,9 +262,10 @@ 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))) + if(FD_ISSET(ivac->net.connection[channel].fd,&(event->rfds))) { ivac_receive_info(channel,ivac); ivac_display_content(ivac); + } } } -- 2.20.1 From dce17a68190aa256fcc9ccee5059f659ae37a3a9 Mon Sep 17 00:00:00 2001 From: hackbard Date: Wed, 12 May 2004 16:52:10 +0000 Subject: [PATCH 08/16] fixed parsing error & detect broken pipes --- src/ivac.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ivac.c b/src/ivac.c index 56a687f..49fc97d 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -60,10 +60,10 @@ int main(int argc,char **argv) { usage(); break; 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(); @@ -229,7 +229,7 @@ int ivac_receive_info(int channel,t_ivac *ivac) { } } - return SUCCESS; + return length; } int ivac_event_cb(t_event *event,void *ptr) { @@ -263,7 +263,12 @@ int ivac_event_cb(t_event *event,void *ptr) { if(ivac->net.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(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); } } -- 2.20.1 From 44d1396bcdd42a518855981fc8aa0b0fbc665231 Mon Sep 17 00:00:00 2001 From: hackbard Date: Fri, 14 May 2004 17:27:04 +0000 Subject: [PATCH 09/16] fixed -h and wrong argv returns --- src/ivac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ivac.c b/src/ivac.c index 49fc97d..e3e2060 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -58,7 +58,7 @@ int main(int argc,char **argv) { switch(argv[i][1]) { case 'h': usage(); - break; + return SUCCESS; case 'n': strncpy(ivac.username,argv[++i],CHAR_USERNAME); break; @@ -67,7 +67,7 @@ int main(int argc,char **argv) { break; default: usage(); - break; + return ERROR; } } else usage(); -- 2.20.1 From 525f7820da4d77f38cd90287fe0982c617d7d754 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sat, 15 May 2004 13:08:21 +0000 Subject: [PATCH 10/16] checkin of incomplete audio.* -> "ice cream & notebook in the garden ..." ;) --- src/audio.c | 17 +++++++++++++++++ src/audio.h | 20 ++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/audio.c create mode 100644 src/audio.h diff --git a/src/audio.c b/src/audio.c new file mode 100644 index 0000000..8698ee9 --- /dev/null +++ b/src/audio.c @@ -0,0 +1,17 @@ +/* audio.c -- audio management stuff + * + * author: hackbard@hackdaworld.dyndns.org + * + */ + +#include "audio.h" + +int audio_init(t_audio *audio) { + + puts("[audio] initializing audio ..."); + + if((audio->fd=open(audio->device,O_RDONLY))==-1) { + perror("[audio] open call"); + return A_ERROR; + } + diff --git a/src/audio.h b/src/audio.h new file mode 100644 index 0000000..b0c01db --- /dev/null +++ b/src/audio.h @@ -0,0 +1,20 @@ +/* audio.h -- audio headers */ + +#ifndef AUDIO_H +#define AUDIO_H + +/* includes */ +#include + +/* defines */ +#define MAX_CHAR_DEVICE 32 +#define SOUND_DEVICE "/dev/dsp" + +/* audio specific variables */ +typedef struct s_audio { + int fd; + char device[MAX_CHAR_DEVICE]; + int cap; +} t_audio; + +#endif -- 2.20.1 From 16b3789b687a3002b80a38f58c07b7a46ac89c6c Mon Sep 17 00:00:00 2001 From: hackbard Date: Sat, 15 May 2004 17:51:58 +0000 Subject: [PATCH 11/16] incredible work done outside in the garden! :) --- src/audio.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/audio.c b/src/audio.c index 8698ee9..bd47644 100644 --- a/src/audio.c +++ b/src/audio.c @@ -15,3 +15,9 @@ int audio_init(t_audio *audio) { return A_ERROR; } + if(ioctl(audio->fd,SNDCTL_DSP_GETCAPS,&(audio->cap))==-1) { + perror("[audio] ioctl call"); + return A_ERROR; + } + + -- 2.20.1 From 51804c822aba850ad3d1589b4dc3dc2709d980f5 Mon Sep 17 00:00:00 2001 From: hackbard Date: Sun, 16 May 2004 08:28:00 +0000 Subject: [PATCH 12/16] completely removed ncurses, added minimal audio functions --- src/Makefile | 4 +- src/audio.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/audio.h | 39 +++++++++++++++++-- src/display.c | 11 +----- src/display.h | 1 - src/ivac.c | 103 +++++++----------------------------------------- src/ivac.h | 2 + 7 files changed, 158 insertions(+), 108 deletions(-) diff --git a/src/Makefile b/src/Makefile index f3b4e06..22c8045 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,9 +3,9 @@ INCLUDEDIR = /usr/include CFLAGS = -DDISPLAY -DDEBUG -O3 -Wall -LIBS = -lncurses +LIBS = -OBJS = network.o event.o input.o display.o +OBJS = network.o event.o input.o display.o audio.o ivac: $(OBJS) $(CC) -o $@ $(OBJS) ivac.c $(LIBS) diff --git a/src/audio.c b/src/audio.c index bd47644..9c8ca4a 100644 --- a/src/audio.c +++ b/src/audio.c @@ -10,14 +10,114 @@ int audio_init(t_audio *audio) { puts("[audio] initializing audio ..."); - if((audio->fd=open(audio->device,O_RDONLY))==-1) { + if((audio->dsp_fd=open(audio->dsp_dev,O_RDWR))==-1) { perror("[audio] open call"); return A_ERROR; } - if(ioctl(audio->fd,SNDCTL_DSP_GETCAPS,&(audio->cap))==-1) { + if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETCAPS,&(audio->dsp_cap))==-1) { perror("[audio] ioctl call"); return A_ERROR; } - + if(!(audio->dsp_cap&DSP_CAP_DUPLEX)) { + puts("[audio] no duplex support"); + return A_ERROR; + } + + return A_SUCCESS; +} + +int audio_setup(t_audio *audio) { + + int tmp; + + puts("[audio] setting up sound device & allocating record/playback buffer"); + + tmp=audio->fmt; + if(ioctl(audio->dsp_fd,SNDCTL_DSP_SETFMT,&tmp)==-1) { + perror("[audio] ioctl call (SNDCTL_DSP_SETFMT)"); + return A_ERROR; + } + if(tmp!=audio->fmt) { + puts("[audio] FMT not supported"); + return A_ERROR; + } + + tmp=audio->speed; + if(ioctl(audio->dsp_fd,SNDCTL_DSP_SPEED,&tmp)==-1) { + perror("[audio] ioctl call (SNDCTL_DSP_SPEED)"); + return A_ERROR; + } + if(tmp!=audio->speed) { + puts("[audio] SPEED not supported"); + return A_ERROR; + } + + if(ioctl(audio->dsp_fd,SNDCTL_DSP_GETBLKSIZE,&(audio->blksize))==-1) { + perror("[audio] ioctl call (SNDCTL_DSP_GETBLKSIZE)"); + return A_ERROR; + } + + if((audio->play_data=(unsigned char *)malloc(audio->blksize))==NULL) { + perror("[audio] malloc call"); + return A_ERROR; + } + if((audio->rec_data=(unsigned char *)malloc(audio->blksize))==NULL) { + perror("[audio] malloc call"); + return A_ERROR; + } + + return A_SUCCESS; +} + +int audio_shutdown(t_audio *audio) { + + puts("[audio] shutdown"); + + free(audio->play_data); + free(audio->rec_data); + + if(close(audio->dsp_fd)==-1) { + perror("[audio] close call"); + return A_ERROR; + } + + return A_SUCCESS; +} + +int audio_play(t_audio *audio,int len) { + + int count,left; + + count=0; + left=len; + + while(left) { + if((count=write(audio->dsp_fd,audio->play_data+len-left,left))==-1) { + perror("[audio] write call"); + return A_ERROR; + } + left-=count; + } + + return A_SUCCESS; +} + +int audio_record(t_audio *audio,int len) { + + int count,left; + + count=0; + left=len; + + while(left) { + if((count=read(audio->dsp_fd,audio->rec_data+len-left,left))==-1) { + perror("[audio] read call"); + return A_ERROR; + } + left-=count; + } + + return A_SUCCESS; +} diff --git a/src/audio.h b/src/audio.h index b0c01db..33e90cb 100644 --- a/src/audio.h +++ b/src/audio.h @@ -4,17 +4,50 @@ #define AUDIO_H /* includes */ +#include +#include +#include +#include +#include +#include +#include +#include #include /* defines */ #define MAX_CHAR_DEVICE 32 #define SOUND_DEVICE "/dev/dsp" +#define A_SUCCESS 1 +#define A_ERROR -1 + +#define BIT_8 AFMT_U8 +#define BIT_16 AFMT_S16_LE +#define MONO 1 +#define STEREO 2 + /* audio specific variables */ typedef struct s_audio { - int fd; - char device[MAX_CHAR_DEVICE]; - int cap; + int dsp_fd; + int mixer_fd; + char dsp_dev[MAX_CHAR_DEVICE]; + char mixer_dev[MAX_CHAR_DEVICE]; + int dsp_cap; + int fmt; + int channels; + int speed; + int blksize; + int mixer_cap; + unsigned char volume; + unsigned char *play_data; + unsigned char *rec_data; } t_audio; +/* function prototypes */ +int audio_init(t_audio *audio); +int audio_setup(t_audio *audio); +int audio_shutdown(t_audio *audio); +int audio_play(t_audio *audio,int len); +int audio_record(t_audio *audio,int len); + #endif diff --git a/src/display.c b/src/display.c index 9390fbc..914ab63 100644 --- a/src/display.c +++ b/src/display.c @@ -10,27 +10,18 @@ int display_init(t_display *display) { puts("[display] initializing display ..."); - initscr(); - raw(); - noecho(); - keypad(stdscr,TRUE); - getmaxyx(stdscr,display->max_y,display->max_x); + /* init stuff next .. */ return D_SUCCESS; } int display_refresh(t_display *display) { - getmaxyx(stdscr,display->max_y,display->max_x); - return D_SUCCESS; } int display_shutdown(t_display *display) { - noraw(); - echo(); - puts("[display] shutdown"); return D_SUCCESS; diff --git a/src/display.h b/src/display.h index 7ec779e..113e892 100644 --- a/src/display.h +++ b/src/display.h @@ -2,7 +2,6 @@ /* includes */ #include -#include /* defines */ #define D_SUCCESS 1 diff --git a/src/ivac.c b/src/ivac.c index e3e2060..98fc8c2 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -21,9 +21,7 @@ * */ -// #define USE_NCURSES -/* dont care about ncurses .. go for gtk(2)! */ -#define USE_GTK +// #define USE_GTK #include "ivac.h" @@ -36,6 +34,7 @@ int usage(void) { puts("-h \t\t show this help"); puts("-n \t specify your name"); puts("-p \t specify port to listen for incoming connections"); + puts("-d \t specify audio device"); puts(""); return SUCCESS; @@ -51,6 +50,7 @@ int main(int argc,char **argv) { /* default values */ strcpy(ivac.username,"ivac"); ivac.net.l_port=IVAC_LISTEN_PORT; + strcpy(ivac.audio.dsp_dev,SOUND_DEVICE); /* parse argv and change default values */ for(i=1;inet)); input_shutdown(&(ivac->input)); event_stop(&(ivac->event)); -#ifdef USE_NCURSES + audio_shutdown(&(ivac->audio)); display_shutdown(&(ivac->display)); -#endif return SUCCESS; } @@ -448,37 +455,15 @@ int ivac_parse_command(t_input *input,void *ptr) { int ivac_display_head(t_display *display) { -#ifdef USE_NCURSES - int x,y; - - move(0,0); - for(x=0;xmax_x;x++) addch('#'); - mvaddstr(1,0,"##"); - mvaddstr(1,(display->max_x-4)/2-4,"- ivac -"); - mvaddstr(1,(display->max_x-2),"##"); - move(2,0); - for(x=0;xmax_x;x++) addch('#'); - refresh(); -#else puts("#########################################################"); puts("##### ivac - - Copyright (C) 2004 Frank Zirkelbach #####"); puts("#########################################################"); -#endif return SUCCESS; } int ivac_display_box(t_display *display) { -#ifdef USE_NCURSES - int x,y; - - for(y=IVAC_PROMPT_LEN;ymax_y-IVAC_PROMPT_LEN;y++) { - mvaddch(y,0,'#'); - mvaddch(y,display->max_x-1,'#'); - } -#endif - return SUCCESS; } @@ -491,93 +476,33 @@ int ivac_display_box_content(t_ivac *ivac) { if(ivac->challenger[channel].name[0]==0) strcpy(ivac->challenger[channel].name,""); -#ifdef USE_NCURSES -#else - for(channel=0;channelnet.connection[channel].status&C_INFO_A) - printf("channel %02d: ip:%s port:%d status: %02x - name: %s\n",channel, - ivac->net.connection[channel].ip, - ivac->net.connection[channel].port, - ivac->net.connection[channel].status, - ivac->challenger[channel].name); - } -#endif - return SUCCESS; } int ivac_display_console(t_display *display) { -#ifdef USE_NCURSES - int x,y; - - move(display->max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN-1,0); - for(x=0;xmax_x;x++) addch('#'); -#endif - return SUCCESS; } int ivac_display_console_content(t_ivac *ivac) { -#ifdef USE_NCURSES - int x,y; - int len; - - for(y=0;yconsole[y]); - move(ivac->display.max_y-IVAC_CONSOLE_LEN-IVAC_PROMPT_LEN+y,2); - for(x=0;xconsole[y][x]>' ')||(ivac->console[y][x]<='~')) - ?ivac->console[y][x]:' '); - for(x=len;xconsole[i]); -#endif return SUCCESS; } int ivac_display_prompt(t_display *display) { -#ifdef USE_NCURSES - int x,y; - - move(display->max_y-3,0); - for(x=0;xmax_x;x++) addch('#'); - mvaddstr(display->max_y-2,0,"## command: "); - mvaddstr(display->max_y-2,display->max_x-2,"##"); - move(display->max_y-1,0); - for(x=0;xmax_x;x++) addch('#'); - refresh(); -#endif - return SUCCESS; } int ivac_display_prompt_content(t_ivac *ivac) { -#ifdef USE_NCURSES - int x,y; - - /* delete old command */ - if(ivac->input.c_count==0) { - move(ivac->display.max_y-2,12); - for(x=12;xdisplay.max_x-1;x++) addch(' '); - } - - for(x=0;xinput.c_count;x++) - mvaddch(ivac->display.max_y-2,x+12,ivac->input.content[x]); - refresh(); -#else printf("%c",ivac->input.content[ivac->input.c_count-1]); fflush(NULL); -#endif return SUCCESS; } diff --git a/src/ivac.h b/src/ivac.h index af64d04..7acb2e6 100644 --- a/src/ivac.h +++ b/src/ivac.h @@ -14,6 +14,7 @@ #include "event.h" #include "input.h" #include "display.h" +#include "audio.h" /* defines */ #define CHAR_USERNAME 32 @@ -62,6 +63,7 @@ typedef struct s_ivac { t_display display; t_challenger challenger[MAX_CONNECTIONS]; char console[IVAC_CONSOLE_LEN][IVAC_CONSOLE_STRING_LEN]; + t_audio audio; } t_ivac; /* function prototypes */ -- 2.20.1 From 9fb0ced14058a258508a61f998059a0f9ab005de Mon Sep 17 00:00:00 2001 From: hackbard Date: Mon, 17 May 2004 18:19:31 +0000 Subject: [PATCH 13/16] implemented some udp features (untested) VS: ---------------------------------------------------------------------- --- src/network.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/network.h | 14 ++++++-- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/network.c b/src/network.c index 55fa2c6..b9c68aa 100644 --- a/src/network.c +++ b/src/network.c @@ -265,3 +265,97 @@ int network_receive(int fd,unsigned char *data,int datasize) { return count; } + +int network_udp_listen_init(t_net *net,int port) { + + struct sockaddr_in addr; + + if((net->l_udp_fd=socket(AF_INET,SOCK_DGRAM,0))==-1) { + perror("[network] socket call (udp-receive)"); + return N_ERROR; + } + + memset(&addr,0,sizeof(struct sockaddr)); + addr.sin_family=AF_INET; + addr.sin_port=htons(net->l_udp_port); + addr.sin_addr.s_addr=INADDR_ANY; + if(bind(net->l_udp_fd,(struct sockaddr *)&addr,sizeof(struct sockaddr))==-1) { + perror("[network] bind call (udp)"); + return N_ERROR; + } + + printf("[network] listening on port %d (udp)\n",net->l_udp_port); + + if((net->s_udp_fd=socket(AF_INET,SOCK_DGRAM,0))==-1) { + perror("[network] socket call (udp-send)"); + return N_ERROR; + } + + return N_SUCCESS; +} + +int network_set_udp_ports(t_net *net,int port) { + + net->l_udp_port=port; + + return N_SUCCESS; +} + +int network_udp_receive(t_net *net,int channel, unsigned char *data,int count) { + + struct sockaddr_in addr; + socklen_t len; + + if((count=recvfrom(net->l_udp_fd,data,count,0, + (struct sockaddr *)&addr,&len))==-1) { + perror("[network] recvfrom call"); + return N_ERROR; + } + + if(strncmp(net->connection[channel].ip,inet_ntoa(addr.sin_addr),IP_DIGITS)) { + printf("[network] packet from unknown: %s\n",inet_ntoa(addr.sin_addr)); + return N_UDP_WRONG_SENDER; + } + + return N_SUCCESS; +} + +int network_udp_send(t_net *net,int channel, unsigned char *data,int size) { + + int count,left; + struct sockaddr_in addr; + + count=0; + left=count; + + memset(&addr,0,sizeof(struct sockaddr)); + addr.sin_family=AF_INET; + addr.sin_port=htons(net->l_udp_port); + inet_aton(net->connection[channel].ip,&(addr.sin_addr)); + + while(left) { + if((count=sendto(net->s_udp_fd,data+size-left,left,0, + (struct sockaddr *)&addr,sizeof(struct sockaddr)))==-1) { + perror("[network] sendto call"); + return N_ERROR; + } + left-=count; + } + + return N_SUCCESS; +} + +int network_udp_shutdown(t_net *net) { + + if(close(net->l_udp_fd)==-1) { + perror("[network] close call (udp-receive)"); + return N_ERROR; + } + + if(close(net->s_udp_fd)==-1) { + perror("[network] close call (udp-send)"); + return N_ERROR; + } + + return N_SUCCESS; +} diff --git a/src/network.h b/src/network.h index 25a9891..5253191 100644 --- a/src/network.h +++ b/src/network.h @@ -37,6 +37,8 @@ #define N_E_ACCEPT -7 #define N_E_MAXC -8 +#define N_UDP_WRONG_SENDER -9 + #define MAX_LISTEN_QUEUE 32 /* net specific variables */ @@ -49,8 +51,11 @@ typedef struct s_connection { } t_connection; typedef struct s_net { - int l_fd; /* listen file descriptor */ - in_port_t l_port; + int l_fd; /* fd for tcp conn */ + int l_udp_fd; /* fd for udp data receive */ + int s_udp_fd; /* fd for udp data send */ + in_port_t l_port; /* tcp port */ + int l_udp_port; /* udp listen port */ unsigned short cap; /* limited connections by now -- replaced by list management later */ int c_count; @@ -72,5 +77,10 @@ int network_deselect(t_net *net,int channel); int network_manage_incoming(t_net *net); int network_send(int fd,unsigned char *data,int datasize); int network_receive(int fd,unsigned char *data,int datasize); +int network_udp_listen_init(t_net *net,int port); +int network_set_udp_ports(t_net *net,int port); +int network_udp_receive(t_net *net,int channel, unsigned char *data,int count); +int network_udp_send(t_net *net,int channel, unsigned char *data,int size); +int network_udp_shutdown(t_net *net); #endif -- 2.20.1 From 8ada0b2c57ad21e9b3bcbd10328faedf996f5c22 Mon Sep 17 00:00:00 2001 From: hackbard Date: Mon, 17 May 2004 18:19:48 +0000 Subject: [PATCH 14/16] do audio_setup(); --- src/ivac.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ivac.c b/src/ivac.c index 98fc8c2..9d2b216 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -118,6 +118,7 @@ int main(int argc,char **argv) { ivac.audio.speed=8000; /* audio init */ audio_init(&(ivac.audio)); + audio_setup(&(ivac.audio)); /* display */ ivac_display(&(ivac.display)); -- 2.20.1 From 96de943f627fd11376a3166af90ed6665a9309eb Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 18 May 2004 10:27:31 +0000 Subject: [PATCH 15/16] remove ncurses.h include --- src/ivac.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ivac.h b/src/ivac.h index 7acb2e6..c8ac919 100644 --- a/src/ivac.h +++ b/src/ivac.h @@ -7,9 +7,6 @@ #define _GNU_SOURCE #include -/* for ui */ -#include - #include "network.h" #include "event.h" #include "input.h" -- 2.20.1 From b5b0be927dd4400a2edb46efe7aba20331dff547 Mon Sep 17 00:00:00 2001 From: hackbard Date: Tue, 18 May 2004 12:34:09 +0000 Subject: [PATCH 16/16] copy timeout into seperate timeval struct for select call --- src/event.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/event.c b/src/event.c index 398e156..03e9656 100644 --- a/src/event.c +++ b/src/event.c @@ -43,6 +43,7 @@ int event_start(t_event *event,void *ptr, int (*callback1)(t_event *event,void *ptr)) { int s_ret; + struct timeval tv; /* switch on event system */ event->status=ENABLED; @@ -51,9 +52,10 @@ int event_start(t_event *event,void *ptr, event->rfds=event->rfds_o; event->wfds=event->wfds_o; + tv=event->timeout; if((s_ret=select(event->maxfd+1,&(event->rfds),&(event->wfds),NULL, - &(event->timeout)))==-1) { + &tv))==-1) { perror("[event] select call"); return E_ERROR; } -- 2.20.1