Skip to content

Commit

Permalink
allow inetd like program exec
Browse files Browse the repository at this point in the history
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1060 c046a42c-6fe2-441c-8c8c-71466251a162
  • Loading branch information
bellard committed Sep 5, 2004
1 parent 9d728e8 commit a3d4af0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
2 changes: 2 additions & 0 deletions slirp/libslirp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ void slirp_output(const uint8_t *pkt, int pkt_len);

int slirp_redir(int is_udp, int host_port,
struct in_addr guest_addr, int guest_port);
int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
int guest_port);

extern const char *tftp_prefix;

Expand Down
20 changes: 18 additions & 2 deletions slirp/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,20 @@ strerror(error)
#endif


#if 0
#ifdef _WIN32

int
fork_exec(so, ex, do_pty)
struct socket *so;
char *ex;
int do_pty;
{
/* not implemented */
return 0;
}

#else

int
openpty(amaster, aslave)
int *amaster, *aslave;
Expand Down Expand Up @@ -301,7 +314,9 @@ fork_exec(so, ex, do_pty)
int opt;
int master;
char *argv[256];
#if 0
char buff[256];
#endif
/* don't want to clobber the original */
char *bptr;
char *curarg;
Expand Down Expand Up @@ -360,6 +375,7 @@ fork_exec(so, ex, do_pty)
connect(s, (struct sockaddr *)&addr, addrlen);
}

#if 0
if (x_port >= 0) {
#ifdef HAVE_SETENV
sprintf(buff, "%s:%d.%d", inet_ntoa(our_addr), x_port, x_screen);
Expand All @@ -369,7 +385,7 @@ fork_exec(so, ex, do_pty)
putenv(buff);
#endif
}

#endif
dup2(s, 0);
dup2(s, 1);
dup2(s, 2);
Expand Down
22 changes: 19 additions & 3 deletions slirp/slirp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ int do_slowtimo;
int link_up;
struct timeval tt;
FILE *lfd;
struct ex_list *exec_list;

/* XXX: suppress those select globals */
fd_set *global_readfds, *global_writefds, *global_xfds;
Expand Down Expand Up @@ -538,13 +539,20 @@ void arp_input(const uint8_t *pkt, int pkt_len)
struct ethhdr *reh = (struct ethhdr *)arp_reply;
struct arphdr *rah = (struct arphdr *)(arp_reply + ETH_HLEN);
int ar_op;
struct ex_list *ex_ptr;

ar_op = ntohs(ah->ar_op);
switch(ar_op) {
case ARPOP_REQUEST:
if (!memcmp(ah->ar_tip, &special_addr, 3) &&
(ah->ar_tip[3] == CTL_DNS || ah->ar_tip[3] == CTL_ALIAS)) {

if (!memcmp(ah->ar_tip, &special_addr, 3)) {
if (ah->ar_tip[3] == CTL_DNS || ah->ar_tip[3] == CTL_ALIAS)
goto arp_ok;
for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
if (ex_ptr->ex_addr == ah->ar_tip[3])
goto arp_ok;
}
return;
arp_ok:
/* XXX: make an ARP request to have the client address */
memcpy(client_ethaddr, eh->h_source, ETH_ALEN);

Expand Down Expand Up @@ -612,6 +620,7 @@ void if_encap(const uint8_t *ip_data, int ip_data_len)

memcpy(eh->h_dest, client_ethaddr, ETH_ALEN);
memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1);
/* XXX: not correct */
eh->h_source[5] = CTL_ALIAS;
eh->h_proto = htons(ETH_P_IP);
memcpy(buf + sizeof(struct ethhdr), ip_data, ip_data_len);
Expand All @@ -632,3 +641,10 @@ int slirp_redir(int is_udp, int host_port,
}
return 0;
}

int slirp_add_exec(int do_pty, const char *args, int addr_low_byte,
int guest_port)
{
return add_exec(&exec_list, do_pty, (char *)args,
addr_low_byte, htons(guest_port));
}
6 changes: 3 additions & 3 deletions slirp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,10 +658,11 @@ tcp_input(m, iphlen, inso)
if(lastbyte==CTL_CMD || lastbyte==CTL_EXEC) {
/* Command or exec adress */
so->so_state |= SS_CTL;
} else {
} else
#endif
{
/* May be an add exec */
struct ex_list *ex_ptr;

for(ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
if(ex_ptr->ex_fport == so->so_fport &&
lastbyte == ex_ptr->ex_addr) {
Expand All @@ -671,7 +672,6 @@ tcp_input(m, iphlen, inso)
}
}
if(so->so_state & SS_CTL) goto cont_input;
#endif
}
/* CTL_ALIAS: Do nothing, tcp_fconnect will be called on it */
}
Expand Down
9 changes: 4 additions & 5 deletions slirp/tcp_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,6 @@ int
tcp_ctl(so)
struct socket *so;
{
#if 0
struct sbuf *sb = &so->so_snd;
int command;
struct ex_list *ex_ptr;
Expand All @@ -1259,6 +1258,7 @@ tcp_ctl(so)
DEBUG_CALL("tcp_ctl");
DEBUG_ARG("so = %lx", (long )so);

#if 0
/*
* Check if they're authorised
*/
Expand All @@ -1267,7 +1267,7 @@ tcp_ctl(so)
sb->sb_wptr += sb->sb_cc;
return 0;
}

#endif
command = (ntohl(so->so_faddr.s_addr) & 0xff);

switch(command) {
Expand Down Expand Up @@ -1300,6 +1300,7 @@ tcp_ctl(so)
DEBUG_MISC((dfd, " executing %s \n",ex_ptr->ex_exec));
return(fork_exec(so, ex_ptr->ex_exec, do_pty));

#if 0
case CTL_CMD:
for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) {
if (tmpso->so_emu == EMU_CTL &&
Expand All @@ -1318,8 +1319,6 @@ tcp_ctl(so)
sb->sb_wptr += sb->sb_cc;
do_echo=-1;
return(2);
}
#else
return 0;
#endif
}
}

0 comments on commit a3d4af0

Please sign in to comment.