[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [ns] How to run emulation programs in NS-2?
We will be integrating this patch into ns soon.
Thank you Ruud.
alefiya
On Mon, 17 Sep 2001, Schramp, R. wrote:
> The .bin file used to be a "patch" file.
>
> Typical use is to set your working directory to the place of the original
> code e.g.
>
> cd /home/mmrenyu/ns/ns-allinone/ns-2.1b8a
>
> here you type something like
>
> patch -p1 < ~mmrenyu/patch
>
>
> The -p1 tells patch to strip the first directory from the directory's in the
> patch file. ensuring that the paths in the patch file point to existing
> files.
>
> Although the patch file is against the latest version of ns, I expect no big
> problems patching it automatically to a litle older version. If you get
> errors you can also patch the source files by hand as it is only about 20
> lines of code.
>
> Best regards,
>
> Ruud Schramp
>
>
> ------CUT HERE: <Patch>------
> diff -Naur ns-2.1b8a/emulate/net-ip.cc ns-2.1b8a_patched/emulate/net-ip.cc
> --- ns-2.1b8a/emulate/net-ip.cc Mon Jun 25 20:01:08 2001
> +++ ns-2.1b8a_patched/emulate/net-ip.cc Fri Aug 31 13:05:29 2001
> @@ -573,10 +573,22 @@
> IPNetwork::send(u_char* buf, int len)
> {
> struct ip *ip = (struct ip*) buf;
> +#ifdef __linux__
> +// r.schramp@kpn.com: For raw sockets on linux the send does not work,
> +// all packets show up only on the loopback device and are not routed
> +// to the correct host. Using sendto on a closed socket solves this problem
> + ip->ip_len = (ip->ip_len);
> + ip->ip_off = (ip->ip_off);
> + sockaddr_in sin;
> + memset((char *)&sin, 0, sizeof(sin));
> + sin.sin_family = AF_INET;
> + sin.sin_addr = ip->ip_dst;
> + return (::sendto(ssock_, (char*)buf, len, 0,(sockaddr *)
> &sin,sizeof(sin)));
> +#else
> ip->ip_len = ntohs(ip->ip_len);
> ip->ip_off = ntohs(ip->ip_off);
> -
> return (::send(ssock_, (char*)buf, len, 0));
> +#endif
> }
>
> int IPNetwork::command(int argc, const char*const* argv)
> @@ -714,8 +726,13 @@
> return (-1);
> }
>
> +#ifndef __linux__
> // sort of curious, but do a connect() even though we have
> // HDRINCL on. Otherwise, we get ENOTCONN when doing a send()
> +
> + // r.schramp@kpn.com: the send does not work under linux, this has
> + // been replaced by a sendto, however this requires a closed socket
> +
> sockaddr_in sin;
> in_addr ia = { INADDR_ANY };
> if (connectsock(fd, ia, 0, sin) < 0) {
> @@ -723,6 +740,7 @@
> "IPNetwork(%s): open: unable to connect : %s\n",
> name(), strerror(errno));
> }
> +#endif
> rsock_ = ssock_ = fd;
> mode_ = mode;
> NIDEBUG5("IPNetwork(%s): opened with mode %d, rsock_:%d,
> ssock_:%d\n",
> diff -Naur ns-2.1b8a/emulate/tcptap.cc ns-2.1b8a_patched/emulate/tcptap.cc
> --- ns-2.1b8a/emulate/tcptap.cc Mon Jun 25 20:01:08 2001
> +++ ns-2.1b8a_patched/emulate/tcptap.cc Fri Aug 31 13:08:19 2001
> @@ -36,6 +36,13 @@
> "@(#) $Header: /nfs/jade/vint/CVSROOT/ns-2/emulate/tcptap.cc,v 1.1
> 2001/05/15 21:23:38 alefiyah Exp $ (ISI)";
> #endif
>
> +#ifdef __linux__
> +// r.schramp@kpn.com: The ip header structure under linux defaults to a
> different structure, this
> +// define makes the BSD ip header the default one. Actualy this solution
> does not win the beaty
> +// contest, anyone with knowledge of makefiles and configure may want to
> include it there
> +#define _BSD_SOURCE
> +#endif
> +
> #include "tcptap.h"
> --------CUT HERE <patch>-------
>