Commit a3d4af03bbedccb5c777562284c1098b9df7fe8a

Authored by bellard
1 parent 9d728e8c

allow inetd like program exec


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1060 c046a42c-6fe2-441c-8c8c-71466251a162
slirp/libslirp.h
@@ -24,6 +24,8 @@ void slirp_output(const uint8_t *pkt, int pkt_len); @@ -24,6 +24,8 @@ void slirp_output(const uint8_t *pkt, int pkt_len);
24 24
25 int slirp_redir(int is_udp, int host_port, 25 int slirp_redir(int is_udp, int host_port,
26 struct in_addr guest_addr, int guest_port); 26 struct in_addr guest_addr, int guest_port);
  27 +int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
  28 + int guest_port);
27 29
28 extern const char *tftp_prefix; 30 extern const char *tftp_prefix;
29 31
slirp/misc.c
@@ -212,7 +212,20 @@ strerror(error) @@ -212,7 +212,20 @@ strerror(error)
212 #endif 212 #endif
213 213
214 214
215 -#if 0 215 +#ifdef _WIN32
  216 +
  217 +int
  218 +fork_exec(so, ex, do_pty)
  219 + struct socket *so;
  220 + char *ex;
  221 + int do_pty;
  222 +{
  223 + /* not implemented */
  224 + return 0;
  225 +}
  226 +
  227 +#else
  228 +
216 int 229 int
217 openpty(amaster, aslave) 230 openpty(amaster, aslave)
218 int *amaster, *aslave; 231 int *amaster, *aslave;
@@ -301,7 +314,9 @@ fork_exec(so, ex, do_pty) @@ -301,7 +314,9 @@ fork_exec(so, ex, do_pty)
301 int opt; 314 int opt;
302 int master; 315 int master;
303 char *argv[256]; 316 char *argv[256];
  317 +#if 0
304 char buff[256]; 318 char buff[256];
  319 +#endif
305 /* don't want to clobber the original */ 320 /* don't want to clobber the original */
306 char *bptr; 321 char *bptr;
307 char *curarg; 322 char *curarg;
@@ -360,6 +375,7 @@ fork_exec(so, ex, do_pty) @@ -360,6 +375,7 @@ fork_exec(so, ex, do_pty)
360 connect(s, (struct sockaddr *)&addr, addrlen); 375 connect(s, (struct sockaddr *)&addr, addrlen);
361 } 376 }
362 377
  378 +#if 0
363 if (x_port >= 0) { 379 if (x_port >= 0) {
364 #ifdef HAVE_SETENV 380 #ifdef HAVE_SETENV
365 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen); 381 sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
@@ -369,7 +385,7 @@ fork_exec(so, ex, do_pty) @@ -369,7 +385,7 @@ fork_exec(so, ex, do_pty)
369 putenv(buff); 385 putenv(buff);
370 #endif 386 #endif
371 } 387 }
372 - 388 +#endif
373 dup2(s, 0); 389 dup2(s, 0);
374 dup2(s, 1); 390 dup2(s, 1);
375 dup2(s, 2); 391 dup2(s, 2);
slirp/slirp.c
@@ -20,6 +20,7 @@ int do_slowtimo; @@ -20,6 +20,7 @@ int do_slowtimo;
20 int link_up; 20 int link_up;
21 struct timeval tt; 21 struct timeval tt;
22 FILE *lfd; 22 FILE *lfd;
  23 +struct ex_list *exec_list;
23 24
24 /* XXX: suppress those select globals */ 25 /* XXX: suppress those select globals */
25 fd_set *global_readfds, *global_writefds, *global_xfds; 26 fd_set *global_readfds, *global_writefds, *global_xfds;
@@ -538,13 +539,20 @@ void arp_input(const uint8_t *pkt, int pkt_len) @@ -538,13 +539,20 @@ void arp_input(const uint8_t *pkt, int pkt_len)
538 struct ethhdr *reh = (struct ethhdr *)arp_reply; 539 struct ethhdr *reh = (struct ethhdr *)arp_reply;
539 struct arphdr *rah = (struct arphdr *)(arp_reply + ETH_HLEN); 540 struct arphdr *rah = (struct arphdr *)(arp_reply + ETH_HLEN);
540 int ar_op; 541 int ar_op;
  542 + struct ex_list *ex_ptr;
541 543
542 ar_op = ntohs(ah->ar_op); 544 ar_op = ntohs(ah->ar_op);
543 switch(ar_op) { 545 switch(ar_op) {
544 case ARPOP_REQUEST: 546 case ARPOP_REQUEST:
545 - if (!memcmp(ah->ar_tip, &special_addr, 3) &&  
546 - (ah->ar_tip[3] == CTL_DNS || ah->ar_tip[3] == CTL_ALIAS)) {  
547 - 547 + if (!memcmp(ah->ar_tip, &special_addr, 3)) {
  548 + if (ah->ar_tip[3] == CTL_DNS || ah->ar_tip[3] == CTL_ALIAS)
  549 + goto arp_ok;
  550 + for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
  551 + if (ex_ptr->ex_addr == ah->ar_tip[3])
  552 + goto arp_ok;
  553 + }
  554 + return;
  555 + arp_ok:
548 /* XXX: make an ARP request to have the client address */ 556 /* XXX: make an ARP request to have the client address */
549 memcpy(client_ethaddr, eh->h_source, ETH_ALEN); 557 memcpy(client_ethaddr, eh->h_source, ETH_ALEN);
550 558
@@ -612,6 +620,7 @@ void if_encap(const uint8_t *ip_data, int ip_data_len) @@ -612,6 +620,7 @@ void if_encap(const uint8_t *ip_data, int ip_data_len)
612 620
613 memcpy(eh->h_dest, client_ethaddr, ETH_ALEN); 621 memcpy(eh->h_dest, client_ethaddr, ETH_ALEN);
614 memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1); 622 memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1);
  623 + /* XXX: not correct */
615 eh->h_source[5] = CTL_ALIAS; 624 eh->h_source[5] = CTL_ALIAS;
616 eh->h_proto = htons(ETH_P_IP); 625 eh->h_proto = htons(ETH_P_IP);
617 memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len); 626 memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len);
@@ -632,3 +641,10 @@ int slirp_redir(int is_udp, int host_port, @@ -632,3 +641,10 @@ int slirp_redir(int is_udp, int host_port,
632 } 641 }
633 return 0; 642 return 0;
634 } 643 }
  644 +
  645 +int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
  646 + int guest_port)
  647 +{
  648 + return add_exec(&exec_list, do_pty, (char *)args,
  649 + addr_low_byte, htons(guest_port));
  650 +}
slirp/tcp_input.c
@@ -658,10 +658,11 @@ findso: @@ -658,10 +658,11 @@ findso:
658 if(lastbyte==CTL_CMD || lastbyte==CTL_EXEC) { 658 if(lastbyte==CTL_CMD || lastbyte==CTL_EXEC) {
659 /* Command or exec adress */ 659 /* Command or exec adress */
660 so->so_state |= SS_CTL; 660 so->so_state |= SS_CTL;
661 - } else { 661 + } else
  662 +#endif
  663 + {
662 /* May be an add exec */ 664 /* May be an add exec */
663 struct ex_list *ex_ptr; 665 struct ex_list *ex_ptr;
664 -  
665 for(ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { 666 for(ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
666 if(ex_ptr->ex_fport == so->so_fport && 667 if(ex_ptr->ex_fport == so->so_fport &&
667 lastbyte == ex_ptr->ex_addr) { 668 lastbyte == ex_ptr->ex_addr) {
@@ -671,7 +672,6 @@ findso: @@ -671,7 +672,6 @@ findso:
671 } 672 }
672 } 673 }
673 if(so->so_state & SS_CTL) goto cont_input; 674 if(so->so_state & SS_CTL) goto cont_input;
674 -#endif  
675 } 675 }
676 /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */ 676 /* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */
677 } 677 }
slirp/tcp_subr.c
@@ -1249,7 +1249,6 @@ int @@ -1249,7 +1249,6 @@ int
1249 tcp_ctl(so) 1249 tcp_ctl(so)
1250 struct socket *so; 1250 struct socket *so;
1251 { 1251 {
1252 -#if 0  
1253 struct sbuf *sb = &so->so_snd; 1252 struct sbuf *sb = &so->so_snd;
1254 int command; 1253 int command;
1255 struct ex_list *ex_ptr; 1254 struct ex_list *ex_ptr;
@@ -1259,6 +1258,7 @@ tcp_ctl(so) @@ -1259,6 +1258,7 @@ tcp_ctl(so)
1259 DEBUG_CALL("tcp_ctl"); 1258 DEBUG_CALL("tcp_ctl");
1260 DEBUG_ARG("so = %lx", (long )so); 1259 DEBUG_ARG("so = %lx", (long )so);
1261 1260
  1261 +#if 0
1262 /* 1262 /*
1263 * Check if they're authorised 1263 * Check if they're authorised
1264 */ 1264 */
@@ -1267,7 +1267,7 @@ tcp_ctl(so) @@ -1267,7 +1267,7 @@ tcp_ctl(so)
1267 sb->sb_wptr += sb->sb_cc; 1267 sb->sb_wptr += sb->sb_cc;
1268 return 0; 1268 return 0;
1269 } 1269 }
1270 - 1270 +#endif
1271 command = (ntohl(so->so_faddr.s_addr) & 0xff); 1271 command = (ntohl(so->so_faddr.s_addr) & 0xff);
1272 1272
1273 switch(command) { 1273 switch(command) {
@@ -1300,6 +1300,7 @@ tcp_ctl(so) @@ -1300,6 +1300,7 @@ tcp_ctl(so)
1300 DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec)); 1300 DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec));
1301 return(fork_exec(so, ex_ptr->ex_exec, do_pty)); 1301 return(fork_exec(so, ex_ptr->ex_exec, do_pty));
1302 1302
  1303 +#if 0
1303 case CTL_CMD: 1304 case CTL_CMD:
1304 for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) { 1305 for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) {
1305 if (tmpso->so_emu == EMU_CTL && 1306 if (tmpso->so_emu == EMU_CTL &&
@@ -1318,8 +1319,6 @@ tcp_ctl(so) @@ -1318,8 +1319,6 @@ tcp_ctl(so)
1318 sb->sb_wptr += sb->sb_cc; 1319 sb->sb_wptr += sb->sb_cc;
1319 do_echo=-1; 1320 do_echo=-1;
1320 return(2); 1321 return(2);
1321 - }  
1322 -#else  
1323 - return 0;  
1324 #endif 1322 #endif
  1323 + }
1325 } 1324 }