Revision 460fec67 slirp/tcp_subr.c
b/slirp/tcp_subr.c | ||
---|---|---|
48 | 48 |
* Tcp initialization |
49 | 49 |
*/ |
50 | 50 |
void |
51 |
tcp_init(void)
|
|
51 |
tcp_init(Slirp *slirp)
|
|
52 | 52 |
{ |
53 |
tcp_iss = 1; /* wrong */ |
|
54 |
tcb.so_next = tcb.so_prev = &tcb; |
|
53 |
slirp->tcp_iss = 1; /* wrong */ |
|
54 |
slirp->tcb.so_next = slirp->tcb.so_prev = &slirp->tcb; |
|
55 |
slirp->tcp_last_so = &slirp->tcb; |
|
55 | 56 |
} |
56 | 57 |
|
57 | 58 |
/* |
... | ... | |
116 | 117 |
if (tp) |
117 | 118 |
win = sbspace(&tp->t_socket->so_rcv); |
118 | 119 |
if (m == NULL) { |
119 |
if ((m = m_get()) == NULL) |
|
120 |
if ((m = m_get(tp->t_socket->slirp)) == NULL)
|
|
120 | 121 |
return; |
121 | 122 |
tlen = 0; |
122 | 123 |
m->m_data += IF_MAXLINKHDR; |
... | ... | |
237 | 238 |
{ |
238 | 239 |
register struct tcpiphdr *t; |
239 | 240 |
struct socket *so = tp->t_socket; |
241 |
Slirp *slirp = so->slirp; |
|
240 | 242 |
register struct mbuf *m; |
241 | 243 |
|
242 | 244 |
DEBUG_CALL("tcp_close"); |
... | ... | |
253 | 255 |
free(tp); |
254 | 256 |
so->so_tcpcb = NULL; |
255 | 257 |
/* clobber input socket cache if we're closing the cached connection */ |
256 |
if (so == tcp_last_so) |
|
257 |
tcp_last_so = &tcb;
|
|
258 |
if (so == slirp->tcp_last_so)
|
|
259 |
slirp->tcp_last_so = &slirp->tcb;
|
|
258 | 260 |
closesocket(so->s); |
259 | 261 |
sbfree(&so->so_rcv); |
260 | 262 |
sbfree(&so->so_snd); |
... | ... | |
317 | 319 |
*/ |
318 | 320 |
int tcp_fconnect(struct socket *so) |
319 | 321 |
{ |
322 |
Slirp *slirp = so->slirp; |
|
320 | 323 |
int ret=0; |
321 | 324 |
|
322 | 325 |
DEBUG_CALL("tcp_fconnect"); |
... | ... | |
333 | 336 |
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt )); |
334 | 337 |
|
335 | 338 |
addr.sin_family = AF_INET; |
336 |
if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) == vnetwork_addr.s_addr) { |
|
339 |
if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) == |
|
340 |
slirp->vnetwork_addr.s_addr) { |
|
337 | 341 |
/* It's an alias */ |
338 |
if (so->so_faddr.s_addr == vnameserver_addr.s_addr) { |
|
342 |
if (so->so_faddr.s_addr == slirp->vnameserver_addr.s_addr) {
|
|
339 | 343 |
addr.sin_addr = dns_addr; |
340 | 344 |
} else { |
341 | 345 |
addr.sin_addr = loopback_addr; |
... | ... | |
375 | 379 |
void |
376 | 380 |
tcp_connect(struct socket *inso) |
377 | 381 |
{ |
382 |
Slirp *slirp = inso->slirp; |
|
378 | 383 |
struct socket *so; |
379 | 384 |
struct sockaddr_in addr; |
380 | 385 |
socklen_t addrlen = sizeof(struct sockaddr_in); |
... | ... | |
392 | 397 |
/* FACCEPTONCE already have a tcpcb */ |
393 | 398 |
so = inso; |
394 | 399 |
} else { |
395 |
if ((so = socreate()) == NULL) { |
|
400 |
if ((so = socreate(slirp)) == NULL) {
|
|
396 | 401 |
/* If it failed, get rid of the pending connection */ |
397 | 402 |
closesocket(accept(inso->s,(struct sockaddr *)&addr,&addrlen)); |
398 | 403 |
return; |
... | ... | |
423 | 428 |
so->so_faddr = addr.sin_addr; |
424 | 429 |
/* Translate connections from localhost to the real hostname */ |
425 | 430 |
if (so->so_faddr.s_addr == 0 || so->so_faddr.s_addr == loopback_addr.s_addr) |
426 |
so->so_faddr = vhost_addr; |
|
431 |
so->so_faddr = slirp->vhost_addr;
|
|
427 | 432 |
|
428 | 433 |
/* Close the accept() socket, set right state */ |
429 | 434 |
if (inso->so_state & SS_FACCEPTONCE) { |
... | ... | |
441 | 446 |
|
442 | 447 |
tp->t_state = TCPS_SYN_SENT; |
443 | 448 |
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; |
444 |
tp->iss = tcp_iss; |
|
445 |
tcp_iss += TCP_ISSINCR/2; |
|
449 |
tp->iss = slirp->tcp_iss;
|
|
450 |
slirp->tcp_iss += TCP_ISSINCR/2;
|
|
446 | 451 |
tcp_sendseqinit(tp); |
447 | 452 |
tcp_output(tp); |
448 | 453 |
} |
... | ... | |
456 | 461 |
if ((so->so_tcpcb = tcp_newtcpcb(so)) == NULL) |
457 | 462 |
return -1; |
458 | 463 |
|
459 |
insque(so, &tcb); |
|
464 |
insque(so, &so->slirp->tcb);
|
|
460 | 465 |
|
461 | 466 |
return 0; |
462 | 467 |
} |
... | ... | |
539 | 544 |
int |
540 | 545 |
tcp_emu(struct socket *so, struct mbuf *m) |
541 | 546 |
{ |
547 |
Slirp *slirp = so->slirp; |
|
542 | 548 |
u_int n1, n2, n3, n4, n5, n6; |
543 | 549 |
char buff[257]; |
544 | 550 |
u_int32_t laddr; |
... | ... | |
572 | 578 |
HTONS(n1); |
573 | 579 |
HTONS(n2); |
574 | 580 |
/* n2 is the one on our host */ |
575 |
for (tmpso = tcb.so_next; tmpso != &tcb; tmpso = tmpso->so_next) { |
|
581 |
for (tmpso = slirp->tcb.so_next; |
|
582 |
tmpso != &slirp->tcb; |
|
583 |
tmpso = tmpso->so_next) { |
|
576 | 584 |
if (tmpso->so_laddr.s_addr == so->so_laddr.s_addr && |
577 | 585 |
tmpso->so_lport == n2 && |
578 | 586 |
tmpso->so_faddr.s_addr == so->so_faddr.s_addr && |
... | ... | |
608 | 616 |
laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); |
609 | 617 |
lport = htons((n5 << 8) | (n6)); |
610 | 618 |
|
611 |
if ((so = tcp_listen(INADDR_ANY, 0, laddr, lport, SS_FACCEPTONCE)) == NULL) |
|
619 |
if ((so = tcp_listen(slirp, INADDR_ANY, 0, laddr, |
|
620 |
lport, SS_FACCEPTONCE)) == NULL) { |
|
612 | 621 |
return 1; |
613 |
|
|
622 |
} |
|
614 | 623 |
n6 = ntohs(so->so_fport); |
615 | 624 |
|
616 | 625 |
n5 = (n6 >> 8) & 0xff; |
... | ... | |
640 | 649 |
laddr = htonl((n1 << 24) | (n2 << 16) | (n3 << 8) | (n4)); |
641 | 650 |
lport = htons((n5 << 8) | (n6)); |
642 | 651 |
|
643 |
if ((so = tcp_listen(INADDR_ANY, 0, laddr, lport, SS_FACCEPTONCE)) == NULL) |
|
652 |
if ((so = tcp_listen(slirp, INADDR_ANY, 0, laddr, |
|
653 |
lport, SS_FACCEPTONCE)) == NULL) { |
|
644 | 654 |
return 1; |
645 |
|
|
655 |
} |
|
646 | 656 |
n6 = ntohs(so->so_fport); |
647 | 657 |
|
648 | 658 |
n5 = (n6 >> 8) & 0xff; |
... | ... | |
680 | 690 |
lport += m->m_data[i] - '0'; |
681 | 691 |
} |
682 | 692 |
if (m->m_data[m->m_len-1] == '\0' && lport != 0 && |
683 |
(so = tcp_listen(INADDR_ANY, 0, so->so_laddr.s_addr, htons(lport), SS_FACCEPTONCE)) != NULL) |
|
693 |
(so = tcp_listen(slirp, INADDR_ANY, 0, so->so_laddr.s_addr, |
|
694 |
htons(lport), SS_FACCEPTONCE)) != NULL) |
|
684 | 695 |
m->m_len = snprintf(m->m_data, m->m_hdr.mh_size, "%d", |
685 | 696 |
ntohs(so->so_fport)) + 1; |
686 | 697 |
return 1; |
... | ... | |
695 | 706 |
|
696 | 707 |
/* The %256s is for the broken mIRC */ |
697 | 708 |
if (sscanf(bptr, "DCC CHAT %256s %u %u", buff, &laddr, &lport) == 3) { |
698 |
if ((so = tcp_listen(INADDR_ANY, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) |
|
709 |
if ((so = tcp_listen(slirp, INADDR_ANY, 0, |
|
710 |
htonl(laddr), htons(lport), |
|
711 |
SS_FACCEPTONCE)) == NULL) { |
|
699 | 712 |
return 1; |
700 |
|
|
713 |
} |
|
701 | 714 |
m->m_len = bptr - m->m_data; /* Adjust length */ |
702 | 715 |
m->m_len += snprintf(bptr, m->m_hdr.mh_size, |
703 | 716 |
"DCC CHAT chat %lu %u%c\n", |
704 | 717 |
(unsigned long)ntohl(so->so_faddr.s_addr), |
705 | 718 |
ntohs(so->so_fport), 1); |
706 | 719 |
} else if (sscanf(bptr, "DCC SEND %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) { |
707 |
if ((so = tcp_listen(INADDR_ANY, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) |
|
720 |
if ((so = tcp_listen(slirp, INADDR_ANY, 0, |
|
721 |
htonl(laddr), htons(lport), |
|
722 |
SS_FACCEPTONCE)) == NULL) { |
|
708 | 723 |
return 1; |
709 |
|
|
724 |
} |
|
710 | 725 |
m->m_len = bptr - m->m_data; /* Adjust length */ |
711 | 726 |
m->m_len += snprintf(bptr, m->m_hdr.mh_size, |
712 | 727 |
"DCC SEND %s %lu %u %u%c\n", buff, |
713 | 728 |
(unsigned long)ntohl(so->so_faddr.s_addr), |
714 | 729 |
ntohs(so->so_fport), n1, 1); |
715 | 730 |
} else if (sscanf(bptr, "DCC MOVE %256s %u %u %u", buff, &laddr, &lport, &n1) == 4) { |
716 |
if ((so = tcp_listen(INADDR_ANY, 0, htonl(laddr), htons(lport), SS_FACCEPTONCE)) == NULL) |
|
731 |
if ((so = tcp_listen(slirp, INADDR_ANY, 0, |
|
732 |
htonl(laddr), htons(lport), |
|
733 |
SS_FACCEPTONCE)) == NULL) { |
|
717 | 734 |
return 1; |
718 |
|
|
735 |
} |
|
719 | 736 |
m->m_len = bptr - m->m_data; /* Adjust length */ |
720 | 737 |
m->m_len += snprintf(bptr, m->m_hdr.mh_size, |
721 | 738 |
"DCC MOVE %s %lu %u %u%c\n", buff, |
... | ... | |
828 | 845 |
|
829 | 846 |
/* try to get udp port between 6970 - 7170 */ |
830 | 847 |
for (p = 6970; p < 7071; p++) { |
831 |
if (udp_listen(INADDR_ANY, |
|
848 |
if (udp_listen(slirp, INADDR_ANY,
|
|
832 | 849 |
htons(p), |
833 | 850 |
so->so_laddr.s_addr, |
834 | 851 |
htons(lport), |
... | ... | |
865 | 882 |
*/ |
866 | 883 |
int tcp_ctl(struct socket *so) |
867 | 884 |
{ |
885 |
Slirp *slirp = so->slirp; |
|
868 | 886 |
struct sbuf *sb = &so->so_snd; |
869 | 887 |
struct ex_list *ex_ptr; |
870 | 888 |
int do_pty; |
... | ... | |
872 | 890 |
DEBUG_CALL("tcp_ctl"); |
873 | 891 |
DEBUG_ARG("so = %lx", (long )so); |
874 | 892 |
|
875 |
if (so->so_faddr.s_addr != vhost_addr.s_addr) { |
|
893 |
if (so->so_faddr.s_addr != slirp->vhost_addr.s_addr) {
|
|
876 | 894 |
/* Check if it's pty_exec */ |
877 |
for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) { |
|
895 |
for (ex_ptr = slirp->exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {
|
|
878 | 896 |
if (ex_ptr->ex_fport == so->so_fport && |
879 | 897 |
so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { |
880 | 898 |
if (ex_ptr->ex_pty == 3) { |
Also available in: Unified diff