socket.c revision e590d0cde1cc5c94333f97c13b9f12ae56fbf8bc
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Copyright (c) 1995 Danny Gasparovski.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Please read the file COPYRIGHT for the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * terms and conditions of the copyright.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(VBOX_WITH_SLIRP_ICMP) && defined (RT_OS_WINDOWS)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic void send_icmp_to_guest(PNATState, char *, size_t, struct socket *, const struct sockaddr_in *);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic void sorecvfrom_icmp_win(PNATState, struct socket *);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic void sorecvfrom_icmp_unix(PNATState, struct socket *);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync for (so = head->so_next; so != head; so = so->so_next)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Create a new socket, initialise the fields
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * It is the responsibility of the caller to
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * insque() it into the correct linked-list
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so = (struct socket *)malloc(sizeof(struct socket));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * remque and free a socket, clobber cache
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync remque(pData, so); /* crashes if so is not in a queue */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Read from so's socket into sb_snd, updating all relevant sbuf fields
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * NOTE: This will only be called if it is select()ed for reading, so
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * a read() of 0 (or less) means it's disconnected
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncsoread(PNATState pData, struct socket *so, int fCloseIfNothingRead)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * No need to check if there's enough room to read.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * soread wouldn't have been called if there weren't
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Should never succeed, but... */
11b175175a0ed424b8e8354acda681ad0adde0f8vboxsync iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_wptr;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Should never succeed, but... */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync nn = recv(so->s, iov[0].iov_base, iov[0].iov_len,0);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Special case for WSAEnumNetworkEvents: If we receive 0 bytes that
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * _could_ mean that the connection is closed. But we will receive an
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * FD_CLOSE event later if the connection was _really_ closed. With
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * www.youtube.com I see this very often. Closing the socket too early
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * would be dangerous.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (nn < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* nn == 0 means peer has performed an orderly shutdown */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * If there was no error, try and read the second time round
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * We read again if n = 2 (ie, there's another part of the buffer)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * and we read as much as we could in the first read
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * We don't test for <= 0 this time, because there legitimately
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * might not be any more data (since the socket is non-blocking),
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * a close will be detected on next iteration.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * A return of -1 wont (shouldn't) happen, since it didn't happen above
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ret = recv(so->s, iov[1].iov_base, iov[1].iov_len,0);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " ... read nn = %d bytes\n", nn));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Update fields */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Get urgent data
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * When the socket is created, we set it SO_OOBINLINE,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * so when OOB data arrives, we soread() it and everything
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * in the send buffer is sent as urgent data
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * We take a guess at how much urgent data has arrived.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * In most situations, when urgent data arrives, the next
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * read() should get all the urgent data. This guess will
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * be wrong however if more data arrives just after the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * urgent data, or the read() doesn't return all the
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * urgent data.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Send urgent data
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * There's a lot duplicated code here, but...
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync char buff[2048]; /* XXX Shouldn't be sending more oob data than this */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* We can send it directly */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync n = send(so->s, sb->sb_rptr, so->so_urgc, (MSG_OOB)); /* |MSG_DONTWAIT)); */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " --- sent %d bytes urgent data, %d urgent bytes left\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Since there's no sendv or sendtov like writev,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * we must copy all data to a linear buffer then
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * send it all
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync n = send(so->s, buff, len, (MSG_OOB)); /* |MSG_DONTWAIT)); */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_ERROR((dfd, "Didn't send all data urgently XXXXX\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " ---2 sent %d bytes urgent data, %d urgent bytes left\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Write data from so_rcv to so's socket,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * updating all sbuf field as necessary
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * No need to check if there's something to write,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * sowrite wouldn't have been called otherwise
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Should never succeed, but... */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync iov[0].iov_len = (sb->sb_data + sb->sb_datalen) - sb->sb_rptr;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Check if there's urgent data to send, and if so, send it */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync nn = send(so->s, iov[0].iov_base, iov[0].iov_len, 0);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* This should never happen, but people tell me it does *shrug* */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (nn < 0 && (errno == EAGAIN || errno == EINTR || errno == EWOULDBLOCK))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " --- sowrite disconnected, so->so_state = %x, errno = %d\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ret = send(so->s, iov[1].iov_base, iov[1].iov_len,0);
c10a6f0c7041e4d1ee50ad38425aab9d43c55522vboxsync DEBUG_MISC((dfd, " ... wrote nn = %d bytes\n", nn));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Update sbuf */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * If in DRAIN mode, and there's no more data, set
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * it CANTSENDMORE
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * recvfrom() a UDP socket
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* This is a "ping" reply */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if !defined(VBOX_WITH_SLIRP_ICMP) || (defined(VBOX_WITH_SLIRP_ICMP) && !defined(RT_OS_WINDOWS))
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#if defined(VBOX_WITH_SLIRP_ICMP) && defined(RT_OS_WINDOWS)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* A "normal" UDP packet */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * XXX Shouldn't FIONREAD packets destined for port 53,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * but I don't know the max packet size for DNS lookups
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* if (so->so_fport != htons(53)) */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " did recvfrom %d, errno = %d-%s\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd," rx error, tx icmp ICMP_UNREACH:%i\n", code));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync icmp_error(pData, so->so_m, ICMP_UNREACH,code, 0,strerror(errno));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Hack: domain name lookup will be used the most for UDP,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * and since they'll only be used once there's no need
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * for the 4 minute (or whatever) timeout... So we time them
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * out much quicker (10 seconds for now...)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * If this packet was destined for CTL_ADDR,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * make it look like that's where it came from, done by udp_output
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync } /* rx error */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync } /* if ping packet */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * sendto() a socket
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncsosendto(PNATState pData, struct socket *so, struct mbuf *m)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ((so->so_faddr.s_addr & htonl(pData->netmask)) == special_addr.s_addr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* It's an alias */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync uint32_t last_byte = ntohl(so->so_faddr.s_addr) & ~pData->netmask;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* handle this case at 'default:' */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Send the packet to host to fully emulate broadcast */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /** @todo r=klaus: on Linux host this causes the host to receive
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * the packet twice for some reason. And I cannot find any place
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * in the man pages which states that sending a broadcast does not
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * reach the host itself. */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync (struct sockaddr *)&host_addr, sizeof (struct sockaddr));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync DEBUG_MISC((dfd, " sendto()ing, addr.sin_port=%d, addr.sin_addr.s_addr=%.16s\n",
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Don't care what port we get */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync (struct sockaddr *)&addr, sizeof (struct sockaddr));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("UDP: sendto fails (%s)\n", strerror(errno)));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Kill the socket if there's no reply in 4 minutes,
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * but only if it's an expirable socket
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_state = SS_ISFCONNECTED; /* So that it gets select()ed */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * XXX This should really be tcp_listen
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncsolisten(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* free(so); Not sofree() ??? free(NULL) == NOP */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Don't tcp_attach... we don't need so_snd nor so_rcv */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if ((so->so_tcpcb = tcp_newtcpcb(pData, so)) == NULL)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * SS_FACCEPTONCE sockets must time out.
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_tcpcb->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT*2;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync || (bind(s,(struct sockaddr *)&addr, sizeof(addr)) < 0)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int tmperrno = WSAGetLastError(); /* Don't clobber the real reason we failed */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Restore the real errno */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync int tmperrno = errno; /* Don't clobber the real reason we failed */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Restore the real errno */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Data is available in so_rcv
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Just write() the data to the socket
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * XXX not yet...
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Data has been freed in so_snd
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * We have room for a read() if we want to
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * For now, don't read, it'll be done in the main loop
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Various session state calls
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * XXX Should be #define's
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * The socket state stuff needs work, these often get call 2 or 3
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * times each when only 1 was needed
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_state &= ~(SS_NOFDREF|SS_ISFCONNECTED|SS_FCANTRCVMORE|
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_state |= SS_ISFCONNECTING; /* Clobber other states */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_state &= ~(SS_ISFCONNECTING|SS_FWDRAIN|SS_NOFDREF);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_state |= SS_ISFCONNECTED; /* Clobber other states */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* XXX close() here as well? */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync so->so_state &= ~(SS_ISFCONNECTING|SS_ISFCONNECTED);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * XXX Do nothing ... ?
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Set write drain mode
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync * Set CANTSENDMORE once all data has been write()n
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncsend_icmp_to_guest(PNATState pData, char *buff, size_t len, struct socket *so, const struct sockaddr_in *addr)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("ICMP:received msg(t:%d, c:%d)\n", icp->icmp_type, icp->icmp_code));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync if (icp->icmp_type != ICMP_ECHOREPLY && icp->icmp_type != ICMP_TIMXCEED)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("NAT: Can't find the corresponding packet for the received ICMP\n"));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Now ip is pointing on header we've sent from guest */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* source address from original IP packet*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* overide ther tail of old packet */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ip = mtod(m, struct ip *); /* ip is from mbuf we've overrided */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* according RFC 793 error messages required copy of initial IP header + 64 bit */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ip->ip_tos = ((ip->ip_tos & 0x1E) | 0xC0); /* high priority for errors */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* the low level expects fields to be in host format so let's convert them*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* Don't call m_free here*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*XXX: so->so_m already freed so we shouldn't call sofree */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /*close tcp should be here */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* do nothing */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncsorecvfrom_icmp_win(PNATState pData, struct socket *so)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync struct ip *ip_broken; /* ICMP returns header + 64 bit of packet */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync len = pData->pfIcmpParseReplies(pData->pvIcmpBuffer, pData->szIcmpBuffer);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("NAT: Error (%d) occurred on ICMP receiving\n", GetLastError()));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync return; /* no error */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync for (i = 0; i < len; ++i)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync code = (code != ~0 ? code : ICMP_UNREACH_PROTOCOL);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* UNREACH error inject here */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync icmp_error(pData, so->so_m, ICMP_UNREACH, code, 0, "Error occurred!!!");
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ip->ip_dst.s_addr = so->so_laddr.s_addr; /*XXX: still the hack*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ip->ip_hl = sizeof(struct ip) >> 2; /* requiered for icmp_reflect, no IP options */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync memcpy(icp->icmp_data, icr[i].Data, icr[i].DataSize);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ip->ip_len = sizeof(struct ip) + ICMP_MINLEN + icr[i].DataSize;
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("ICMP: can't find original package (first double word %x)\n", *(uint32_t *)ip_broken));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync icp = (struct icmp *)((char *)ip + (ip->ip_hl << 2));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync ip_broken->ip_src.s_addr = src; /*it packet sent from host not from guest*/
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync memcpy(icp->icmp_data, ip_broken, (ip_broken->ip_hl << 2) + 64);
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync LogRel(("ICMP(default): message with Status: %x was received from %x\n", icr[i].Status, icr[i].Address));
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync# endif /* RT_OS_WINDOWS */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync#endif /* VBOX_WITH_SLIRP_ICMP */
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsyncstatic void sorecvfrom_icmp_unix(PNATState pData, struct socket *so)
553a2f0d8ef91a6dad8de4eef206ff093af53a5dvboxsync /* XXX Check if reply is "correct"? */