slirp/tcp_subr.c: fix coding style in tcp_connect
Fix coding style in tcp_connect before the next patch. Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
2c20e711de
commit
4ef7b8944c
142
slirp/tcp_subr.c
142
slirp/tcp_subr.c
@ -384,83 +384,87 @@ int tcp_fconnect(struct socket *so)
|
|||||||
* the time it gets to accept(), so... We simply accept
|
* the time it gets to accept(), so... We simply accept
|
||||||
* here and SYN the local-host.
|
* here and SYN the local-host.
|
||||||
*/
|
*/
|
||||||
void
|
void tcp_connect(struct socket *inso)
|
||||||
tcp_connect(struct socket *inso)
|
|
||||||
{
|
{
|
||||||
Slirp *slirp = inso->slirp;
|
Slirp *slirp = inso->slirp;
|
||||||
struct socket *so;
|
struct socket *so;
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
socklen_t addrlen = sizeof(struct sockaddr_in);
|
socklen_t addrlen = sizeof(struct sockaddr_in);
|
||||||
struct tcpcb *tp;
|
struct tcpcb *tp;
|
||||||
int s, opt;
|
int s, opt;
|
||||||
|
|
||||||
DEBUG_CALL("tcp_connect");
|
DEBUG_CALL("tcp_connect");
|
||||||
DEBUG_ARG("inso = %lx", (long)inso);
|
DEBUG_ARG("inso = %lx", (long)inso);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If it's an SS_ACCEPTONCE socket, no need to socreate()
|
* If it's an SS_ACCEPTONCE socket, no need to socreate()
|
||||||
* another socket, just use the accept() socket.
|
* another socket, just use the accept() socket.
|
||||||
*/
|
*/
|
||||||
if (inso->so_state & SS_FACCEPTONCE) {
|
if (inso->so_state & SS_FACCEPTONCE) {
|
||||||
/* FACCEPTONCE already have a tcpcb */
|
/* FACCEPTONCE already have a tcpcb */
|
||||||
so = inso;
|
so = inso;
|
||||||
} else {
|
} else {
|
||||||
if ((so = socreate(slirp)) == NULL) {
|
so = socreate(slirp);
|
||||||
/* If it failed, get rid of the pending connection */
|
if (so == NULL) {
|
||||||
closesocket(accept(inso->s,(struct sockaddr *)&addr,&addrlen));
|
/* If it failed, get rid of the pending connection */
|
||||||
return;
|
closesocket(accept(inso->s, (struct sockaddr *)&addr, &addrlen));
|
||||||
}
|
return;
|
||||||
if (tcp_attach(so) < 0) {
|
|
||||||
free(so); /* NOT sofree */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
so->so_laddr = inso->so_laddr;
|
|
||||||
so->so_lport = inso->so_lport;
|
|
||||||
}
|
|
||||||
|
|
||||||
(void) tcp_mss(sototcpcb(so), 0);
|
|
||||||
|
|
||||||
if ((s = accept(inso->s,(struct sockaddr *)&addr,&addrlen)) < 0) {
|
|
||||||
tcp_close(sototcpcb(so)); /* This will sofree() as well */
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
socket_set_nonblock(s);
|
|
||||||
opt = 1;
|
|
||||||
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
|
|
||||||
opt = 1;
|
|
||||||
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
|
|
||||||
opt = 1;
|
|
||||||
setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&opt,sizeof(int));
|
|
||||||
|
|
||||||
so->so_fport = addr.sin_port;
|
|
||||||
so->so_faddr = addr.sin_addr;
|
|
||||||
/* Translate connections from localhost to the real hostname */
|
|
||||||
if (so->so_faddr.s_addr == 0 ||
|
|
||||||
(so->so_faddr.s_addr & loopback_mask) ==
|
|
||||||
(loopback_addr.s_addr & loopback_mask)) {
|
|
||||||
so->so_faddr = slirp->vhost_addr;
|
|
||||||
}
|
}
|
||||||
|
if (tcp_attach(so) < 0) {
|
||||||
|
free(so); /* NOT sofree */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
so->so_laddr = inso->so_laddr;
|
||||||
|
so->so_lport = inso->so_lport;
|
||||||
|
}
|
||||||
|
|
||||||
/* Close the accept() socket, set right state */
|
tcp_mss(sototcpcb(so), 0);
|
||||||
if (inso->so_state & SS_FACCEPTONCE) {
|
|
||||||
closesocket(so->s); /* If we only accept once, close the accept() socket */
|
|
||||||
so->so_state = SS_NOFDREF; /* Don't select it yet, even though we have an FD */
|
|
||||||
/* if it's not FACCEPTONCE, it's already NOFDREF */
|
|
||||||
}
|
|
||||||
so->s = s;
|
|
||||||
so->so_state |= SS_INCOMING;
|
|
||||||
|
|
||||||
so->so_iptos = tcp_tos(so);
|
s = accept(inso->s, (struct sockaddr *)&addr, &addrlen);
|
||||||
tp = sototcpcb(so);
|
if (s < 0) {
|
||||||
|
tcp_close(sototcpcb(so)); /* This will sofree() as well */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
socket_set_nonblock(s);
|
||||||
|
opt = 1;
|
||||||
|
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof(int));
|
||||||
|
opt = 1;
|
||||||
|
setsockopt(s, SOL_SOCKET, SO_OOBINLINE, (char *)&opt, sizeof(int));
|
||||||
|
opt = 1;
|
||||||
|
setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&opt, sizeof(int));
|
||||||
|
|
||||||
tcp_template(tp);
|
so->so_fport = addr.sin_port;
|
||||||
|
so->so_faddr = addr.sin_addr;
|
||||||
|
/* Translate connections from localhost to the real hostname */
|
||||||
|
if (so->so_faddr.s_addr == 0 ||
|
||||||
|
(so->so_faddr.s_addr & loopback_mask) ==
|
||||||
|
(loopback_addr.s_addr & loopback_mask)) {
|
||||||
|
so->so_faddr = slirp->vhost_addr;
|
||||||
|
}
|
||||||
|
|
||||||
tp->t_state = TCPS_SYN_SENT;
|
/* Close the accept() socket, set right state */
|
||||||
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
|
if (inso->so_state & SS_FACCEPTONCE) {
|
||||||
tp->iss = slirp->tcp_iss;
|
/* If we only accept once, close the accept() socket */
|
||||||
slirp->tcp_iss += TCP_ISSINCR/2;
|
closesocket(so->s);
|
||||||
tcp_sendseqinit(tp);
|
|
||||||
tcp_output(tp);
|
/* Don't select it yet, even though we have an FD */
|
||||||
|
/* if it's not FACCEPTONCE, it's already NOFDREF */
|
||||||
|
so->so_state = SS_NOFDREF;
|
||||||
|
}
|
||||||
|
so->s = s;
|
||||||
|
so->so_state |= SS_INCOMING;
|
||||||
|
|
||||||
|
so->so_iptos = tcp_tos(so);
|
||||||
|
tp = sototcpcb(so);
|
||||||
|
|
||||||
|
tcp_template(tp);
|
||||||
|
|
||||||
|
tp->t_state = TCPS_SYN_SENT;
|
||||||
|
tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT;
|
||||||
|
tp->iss = slirp->tcp_iss;
|
||||||
|
slirp->tcp_iss += TCP_ISSINCR/2;
|
||||||
|
tcp_sendseqinit(tp);
|
||||||
|
tcp_output(tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user