udp.c revision 15e9551616edacb30fe180f55fdb97c1a0f6aacb
/*
* Copyright (c) 1982, 1986, 1988, 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)udp_usrreq.c 8.4 (Berkeley) 1/21/94
* udp_usrreq.c,v 1.4 1994/10/02 17:48:45 phk Exp
*/
/*
* Changes and additions relating to SLiRP
* Copyright (c) 1995 Danny Gasparovski.
*
* Please read the file COPYRIGHT for the
* terms and conditions of the copyright.
*/
#include <slirp.h>
#include "ip_icmp.h"
#include "ctl.h"
/*
* UDP protocol implementation.
* Per RFC 768, August, 1980.
*/
#define udpcksum 1
void
{
udp_last_so = &udb;
}
/* m->m_data points at ip packet header
* m->m_len length ip packet
* ip->ip_len length data (IPDU)
*/
void
{
int len;
int ret;
int ttl;
DEBUG_CALL("udp_input");
DEBUG_ARG("m = %lx", (long)m);
/*
* Strip IP options, if any; should skip this,
* make available to user, and use on returned packets,
* but we don't yet have a way to check the checksum
* with options still present.
*/
{
ip_stripoptions(m, (struct mbuf *)0);
}
/*
* Get IP and UDP header together in first mbuf.
*/
/*
* Make mbuf data length reflect UDP length.
* If not enough data to reflect UDP length, drop.
*/
{
{
goto bad;
}
}
/*
* Save a copy of the IP header in case we want restore it
* for sending an ICMP error message in response.
*/
/*
* Checksum extended UDP header and data.
*/
{
#if 0
/* keep uh_sum for ICMP reply */
{
#endif
{
goto bad;
}
}
#if 0
}
#endif
/*
*/
{
bootp_input(pData, m);
goto bad;
}
/*
* handle TFTP
*/
{
tftp_input(pData, m);
goto bad;
}
/*
* Locate pcb for datagram.
*/
so = udp_last_so;
{
{
{
break;
}
}
else
{
udp_last_so = so;
}
}
{
/*
* If there's no socket for this packet,
* create one
*/
goto bad;
{
goto bad;
}
/*
* Setup fields
*/
/* udp_last_so = so; */
/*
* XXXXX Here, check if it's in udpexec_list,
* and if it is, do the fork_exec() etc.
*/
}
/*
* Now we sendto() the packet.
*/
if (ret < 0)
LogRel(("NAT: Error (%s) occurred while setting TTL(%d) attribute "
{
}
/* restore the orig mbuf packet */
return;
bad:
return;
}
int iptos)
{
int error = 0;
DEBUG_CALL("udp_output");
DEBUG_ARG("m = %lx", (long)m);
/*
* Adjust for header
*/
/*
* Fill in mbuf with extended UDP header
* and addresses and length put into network format.
*/
/* XXXXX Check for from-one-location sockets, or from-any-location sockets */
/*
* Stuff checksum and output datagram.
*/
if (udpcksum)
{
}
return error;
}
struct sockaddr_in *addr)
{
{
}
/* Any UDP packet to the loopback address must be translated to be from
* the forwarding address, i.e. 10.0.2.2. */
}
int
{
struct sockaddr_in addr;
int status;
{
/*
* Here, we bind() the socket. Although not really needed
* (sendto() on an unbound socket will bind it), it's done
* here so that emulation of ytalk etc. don't have to do it
*/
{
closesocket(so->s);
so->s = -1;
#ifdef RT_OS_WINDOWS
#else
#endif
}
else
{
int opt = 1;
/* success, insert in queue */
/* enable broadcast for later use */
}
}
return so->s;
}
void
{
{
closesocket(so->s);
}
}
{
{ 0, 0, 0, 0 }
};
{
int i = 0;
{
{
}
i++;
}
return 0;
}
#ifdef EMULATE_TALK
#include "talkd.h"
#endif
/*
*/
void
{
struct sockaddr_in addr;
#ifdef EMULATE_TALK
struct talk_request
{
struct talk_request *next;
} *req;
static struct talk_request *req_tbl = 0;
#endif
struct cu_header
{
} *cu_head;
{
#ifdef EMULATE_TALK
case EMU_TALK:
case EMU_NTALK:
/*
* Talk emulation. We always change the ctl_addr to get
* some answers from the daemon. When an ANNOUNCE comes,
* we send LEAVE_INVITE to the local daemons. Also when a
* DELETE comes, we send copies to the local daemons.
*/
return;
do { \
} while (0)
/* old_sockaddr to sockaddr_in */
if (IS_OLD)
{
/* old talk */
}
else
{
/* new talk */
}
return; /* for LOOK_UP this is enough */
if (IS_OLD)
{
/* make a copy of the message */
}
else
/*
* If if is an ANNOUNCE message, we go through the
* request table to see if a tcp port has already
* been redirected for this socket. If not, we solisten()
* a new socket and add this entry to the table.
* The port number of the tcp socket and our IP
* are put to the addr field of the message structures.
* Then a LEAVE_INVITE is sent to both local daemon
* ports, 517 and 518. This is why we have two copies
* of the message, one in old talk and one in new talk
* format.
*/
{
int s;
break; /* found it */
if (!req)
{
/* no entry for so, create new */
}
/* replace port number in addr field */
/* send LEAVE_INVITEs */
closesocket(s) ;
}
/*
* If it is a DELETE message, we send a copy to the
* local daemons. Then we delete the entry corresponding
* to our socket from the request table.
*/
{
int s;
closesocket(s);
/* delete table entry */
{
}
else
{
{
{
break;
}
else
}
}
}
return;
#endif
case EMU_CUSEEME:
/*
* Cu-SeeMe emulation.
* Hopefully the packet is more that 16 bytes long. We don't
* do any other tests, just replace the address and port
* fields.
*/
{
return;
}
return;
}
}
struct socket *
{
struct sockaddr_in addr;
int opt = 1;
return NULL;
{
return NULL;
}
/* setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int)); */
/* The original check was completely broken, as the commented out
* if statement was always true (INADDR_ANY=0). */
/* if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) */
if (1 == 0) /* always use the else part */
else
if (flags != SS_FACCEPTONCE)
return so;
}