Parcourir la source

- added bind_address (per process listen socket ip address)

Andrei Pelinescu-Onciul il y a 23 ans
Parent
commit
1d597ac383
4 fichiers modifiés avec 10 ajouts et 6 suppressions
  1. 2 1
      globals.h
  2. 5 4
      main.c
  3. 1 0
      receive.c
  4. 2 1
      udp_server.c

+ 2 - 1
globals.h

@@ -24,8 +24,9 @@ extern int port_no_str_len;
 extern unsigned int maxbuffer;
 extern char * names[];
 extern int names_len[];
-extern unsigned long addresses[];
+extern unsigned int addresses[];
 extern int addresses_no;
+extern unsigned int bind_address;
 extern int children_no;
 extern int debug;
 extern int dont_fork;

+ 5 - 4
main.c

@@ -194,10 +194,11 @@ char* chroot_dir = 0;
 int uid = 0;
 int gid = 0;
 
-char* names[MAX_LISTEN];               /* our names */
-int names_len[MAX_LISTEN];    /* lengths of the names*/
-unsigned long addresses[MAX_LISTEN];   /* our ips */
-int addresses_no=0;                    /* number of names/ips */
+char* names[MAX_LISTEN];              /* our names */
+int names_len[MAX_LISTEN];            /* lengths of the names*/
+unsigned int addresses[MAX_LISTEN];   /* our ips */
+int addresses_no=0;                   /* number of names/ips */
+unsigned int bind_address=0;          /* listen address of the crt. process */
 
 /* ipc related globals */
 int process_no = 0;

+ 1 - 0
receive.c

@@ -41,6 +41,7 @@ int receive_msg(char* buf, unsigned int len, unsigned long src_ip)
 	msg->buf=buf;
 	msg->len=len;
 	msg->src_ip=src_ip;
+	msg->dst_ip=bind_address; /* won't work if listening on 0.0.0.0 */
 	msg->id=msg_no;
 	/* make a copy of the message */
 	msg->orig=(char*) pkg_malloc(len+1);

+ 2 - 1
udp_server.c

@@ -120,6 +120,7 @@ int udp_init(unsigned long ip, unsigned short port)
 	addr->sin_port=htons(port);
 	addr->sin_addr.s_addr=ip;
 
+	
 	udp_sock = socket(PF_INET, SOCK_DGRAM, 0);
 	if (udp_sock==-1){
 		LOG(L_ERR, "ERROR: udp_init: socket: %s\n", strerror(errno));
@@ -135,7 +136,7 @@ int udp_init(unsigned long ip, unsigned short port)
 	}
 
 	if ( probe_max_receive_buffer(udp_sock)==-1) goto error;
-
+	bind_address=ip;
 
 	if (bind(udp_sock, (struct sockaddr*) addr, sizeof(struct sockaddr))==-1){
 		LOG(L_ERR, "ERROR: udp_init: bind: %s\n", strerror(errno));