From: hackbard Date: Tue, 18 May 2004 15:31:07 +0000 (+0000) Subject: fixed udp "addtess already used" thing + introduced nic device string (used later) X-Git-Url: https://hackdaworld.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d525cc402e67386372745a4bc3c04a488ea264f7;p=my-code%2Fivac.git fixed udp "addtess already used" thing + introduced nic device string (used later) --- diff --git a/src/ivac.c b/src/ivac.c index 47d1892..44e831c 100644 --- a/src/ivac.c +++ b/src/ivac.c @@ -34,6 +34,7 @@ int usage(void) { puts("-p \t specify port to listen for incoming connections"); puts("-u \t specify udp data port"); puts("-d \t specify audio device"); + puts("-i \t specify network interface"); puts(""); return SUCCESS; @@ -51,6 +52,7 @@ int main(int argc,char **argv) { ivac.net.l_port=IVAC_LISTEN_PORT; ivac.net.l_udp_port=IVAC_UDP_PORT; strcpy(ivac.audio.dsp_dev,SOUND_DEVICE); + strcpy(ivac.net.nic,"eth0"); /* parse argv and change default values */ for(i=1;il_udp_fd=socket(AF_INET,SOCK_DGRAM,0))==-1) { perror("[network] socket call (udp-receive)"); @@ -280,8 +281,14 @@ int network_udp_listen_init(t_net *net) { 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; + /* try harder ... */ + true=1; + if(setsockopt(net->l_udp_fd,SOL_SOCKET,SO_REUSEADDR, + &true,sizeof(true))==-1) { + perror("[network] setsockopt call (udp)"); + return N_ERROR; + } + puts("[network] reused address (udp)"); } printf("[network] listening on port %d (udp)\n",net->l_udp_port); diff --git a/src/network.h b/src/network.h index 60ae773..079cea3 100644 --- a/src/network.h +++ b/src/network.h @@ -17,6 +17,7 @@ /* defines */ #define MAX_CONNECTIONS 32 +#define MAX_NIC_DEVICE 32 #define IP_DIGITS 16 #define C_IN_USE (1<<0) @@ -61,6 +62,7 @@ typedef struct s_net { int c_count; t_connection connection[MAX_CONNECTIONS]; unsigned int sendmask; /* 32 bits for maximum of 32 connections */ + char nic[MAX_NIC_DEVICE]; } t_net; /* function prototypes */