#include <slirp.h>
#include "ip_icmp.h"
#include "main.h"
+#ifdef __sun__
+#include <sys/filio.h>
+#endif
void
so_init()
nn = readv(so->s, (struct iovec *)iov, n);
DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
#else
- nn = read(so->s, iov[0].iov_base, iov[0].iov_len);
+ nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
#endif
if (nn <= 0) {
if (nn < 0 && (errno == EINTR || errno == EAGAIN))
* a close will be detected on next iteration.
* A return of -1 wont (shouldn't) happen, since it didn't happen above
*/
- if (n == 2 && nn == iov[0].iov_len)
- nn += read(so->s, iov[1].iov_base, iov[1].iov_len);
+ if (n == 2 && nn == iov[0].iov_len) {
+ int ret;
+ ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
+ if (ret > 0)
+ nn += ret;
+ }
DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
#endif
DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
#else
- nn = write(so->s, iov[0].iov_base, iov[0].iov_len);
+ nn = send(so->s, iov[0].iov_base, iov[0].iov_len,0);
#endif
/* This should never happen, but people tell me it does *shrug* */
if (nn < 0 && (errno == EAGAIN || errno == EINTR))
}
#ifndef HAVE_READV
- if (n == 2 && nn == iov[0].iov_len)
- nn += write(so->s, iov[1].iov_base, iov[1].iov_len);
+ if (n == 2 && nn == iov[0].iov_len) {
+ int ret;
+ ret = send(so->s, iov[1].iov_base, iov[1].iov_len,0);
+ if (ret > 0)
+ nn += ret;
+ }
DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
#endif
*/
len = M_FREEROOM(m);
/* if (so->so_fport != htons(53)) { */
- ioctl(so->s, FIONREAD, &n);
+ ioctlsocket(so->s, FIONREAD, &n);
if (n > len) {
n = (m->m_data - m->m_dat) + m->m_len + n + 1;
addr.sin_port = port;
if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) ||
+ (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) ||
(bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0) ||
(listen(s,1) < 0)) {
int tmperrno = errno; /* Don't clobber the real reason we failed */
close(s);
sofree(so);
/* Restore the real errno */
+#ifdef _WIN32
+ WSASetLastError(tmperrno);
+#else
errno = tmperrno;
+#endif
return NULL;
}
- setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
getsockname(s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
- so->so_faddr = our_addr;
+ so->so_faddr = alias_addr;
else
so->so_faddr = addr.sin_addr;
{
if ((so->so_state & SS_NOFDREF) == 0) {
shutdown(so->s,0);
- FD_CLR(so->s, global_writefds);
+ if(global_writefds) {
+ FD_CLR(so->s,global_writefds);
+ }
}
so->so_state &= ~(SS_ISFCONNECTING);
if (so->so_state & SS_FCANTSENDMORE)
struct socket *so;
{
if ((so->so_state & SS_NOFDREF) == 0) {
- shutdown(so->s,1); /* send FIN to fhost */
- FD_CLR(so->s, global_readfds);
- FD_CLR(so->s, global_xfds);
+ shutdown(so->s,1); /* send FIN to fhost */
+ if (global_readfds) {
+ FD_CLR(so->s,global_readfds);
+ }
+ if (global_xfds) {
+ FD_CLR(so->s,global_xfds);
+ }
}
so->so_state &= ~(SS_ISFCONNECTING);
if (so->so_state & SS_FCANTRCVMORE)