EzDevInfo.com

forwarding interview questions

Top forwarding frequently asked interview questions

GoDaddy DNS forward to IP adds frames to html [closed]

I have a domain name mydomain.biz from GoDaddy forwarding to a physical server at home. Godaddy while redirecting always adds frame to the html such as

<html>
<head>
<frameset border="0" rows="100%,*">
<frame frameborder="0" src="http://my_server_ip/wwwroot">
<html xmlns="http://www.w3.org/1999/xhtml">
</frame>
<frame noresize="" frameborder="0">
</frameset>
</html>

Is there a way to have it redirect without frame added to my html? My server is a WAMP (apache 2.2, php 5.3). What are the security concerns?


Source: (StackOverflow)

adb forward remote port to local machine

This is a query regarding the usage of adb on android.

Is there a way to forward the remote port i.e. port on the android device/emulator to the local machine to which the device is connected?

$ adb forward tcp:port1 tcp:port2 # forwards the local port port1 on the machine to port2 on the device.

Thanks in advance!


Source: (StackOverflow)

Advertisements

Perfect Forwarding in C++03

If you have this function

template<typename T> f(T&);

And then try to call it with, let's say an rvalue like

f(1);

Why isn't T just be deduced to be const int, making the argument a const int& and thus bindable to an rvalue?


Source: (StackOverflow)

Set up DNS based URL forwarding in Amazon Route53

I'm trying to setup forwarding in Amazon Route53. My last DNS service (Nettica) allowed me to route requests to "aws.example.com" to "https://myaccount.signin.aws.amazon.com/console/".

Is this functionality supported by Route53?

How does Nettica achieve this? Does it insert a special A, CNAME, PTR, or TXT record(s)?


Source: (StackOverflow)

When to use std::forward to forward arguments?

C++0x shows an example of using std::forward:

template<class T>
void foo(T&& arg) 
{
  bar(std::forward<T>(arg));
}

When is it advantageous to use std::forward, always?

Also, it requires to use && in the parameters declaration, is it valid in all cases? I thought you had to pass temporaries to a function if the function was declared with && in it, so can foo be called with any parameter?

Lastly, if I have a function call such as this:

template<int val, typename... Params>
void doSomething(Params... args) {
  doSomethingElse<val, Params...>(args...);
}

Should I use this instead:

template<int val, typename... Params>
void doSomething(Params&&... args) {
  doSomethingElse<val, Params...>(std::forward<Params>(args)...);
}

Also, if use the parameters twice in the function, i.e. forwarding to two functions at the same time, is it wise to use std::forward? Won't std::forward convert the same thing to a temporary twice, moving the memory and make it invalid for a second use? Would the following code be ok:

template<int val, typename... Params>
void doSomething(Params&&... args) {
  doSomethingElse<val, Params...>(std::forward<Params>(args)...);
  doSomethingWeird<val, Params...>(std::forward<Params>(args)...);
}

I'm a bit confused by std::forward, and I'd gladly use some clearing up.


Source: (StackOverflow)

Does PHP Have an Equivalent of Java's RequestDispatcher.forward?

In Java I can write a really basic JSP index.jsp like so:

<% request.getRequestDispatcher("/home.action").forward(request, response); %>

The effect of this is that a user requesting index.jsp (or just the containing directory assuming index.jsp is a default document for the directory) will see home.action without a browser redirect, i.e. the forward happens on the server side.

Can I do something similar with PHP? I suspect it's possible to configure Apache to handle this case, but since I might not have access to the relevant Apache configuration I'd be interested in a solution that relies on PHP alone.


Source: (StackOverflow)

How to forward http request to https in Amazon Route53?

I have a subdomain in Amazon Route53. Let's say secure.example.com

If requests come like https://secure.example.com it is ok but I would like to force http requests to come through https. When user types http://secure.example.com it needs to be forwarded to https://secure.example.com.

Is there a domain level redirecting/forwarding requests coming through http to https in Amazon Route53?


Source: (StackOverflow)

Can someone explain rvalue references with respect to exceptions?

Lets say I've this exception class:

struct MyException : public std::exception
{
    MyException(const std::exception &exc) : std::exception(exc)
    {
        cout << "lval\n";
    }
    MyException(std::exception &&exc) : std::exception(std::forward<std::exception>(exc))
    {
        cout << "rval\n";
    }
};

...
...

try
{
    throw std::exception("Oh no!");
    // above is rvalue since it's got no name, what if the throw is made as
    // std::exception lvalExc("Oh wierd!");
    // throw lvalExc;
    // if the throw is made thus, how can it be caught by catch(std::exception &&exc)?
}
catch(std::exception &&rValRef)
{
    cout << "rValRef!\n";
    throw MyException(std::forward<std::exception>(rValRef));
}

When I tried to catch by value or by (const) lvalue ref. the compiler says these cases are already handled by the rvalue ref catch clause, which is understandable, as an exception is an xvalue and perhaps the best way to catch an xvalue is an rvalue ref (correct me if I'm wrong). But can someone explain about the perfect forwarding in the above case of exception creation? Is it correct? Even though it compiles, is it meaningful or useful? Should the C++ library I use have a move constructor implemented for its std::exception for this kind of usage to be truly meaningful? I tried searching for articles and SO questions on rvalue references with respect to exceptions, couldn't find any.


Source: (StackOverflow)

iptables FORWARD and INPUT

I have a home network with Linux pc's, which all had iptables running. I think it is easier to put my LAN behind a Linux gateway/firewall, so I've put a pc (with fedora,no gui) between my router and LAN and configured iptables. No problem here, INPUT only allows dns an http (and some local stuff), forwarding works fine: LAN connects to internet.

But my question is: does FORWARD allows all from the outside, or only the ports I configured with INPUT? Do FORWARD and INPUT work together or are they separate?

This is my iptables:

*nat
:PREROUTING ACCEPT [16:1336]
:INPUT ACCEPT [14:840]
:OUTPUT ACCEPT [30:2116]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o p1p1 -j MASQUERADE
COMMIT
# Completed on Tue Oct 16 09:55:31 2012
# Generated by iptables-save v1.4.14 on Tue Oct 16 09:55:31 2012
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [91:9888]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p UDP --dport 53 -j ACCEPT
-A INPUT -p TCP --dport 53 -j ACCEPT
-A INPUT -s 192.168.1.0/24 -i p1p1 -p tcp -m multiport --dports 20,21 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.2.0/24 -i p3p1 -p tcp -m multiport --dports 20,21 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.1.0/24 -i p1p1 -p tcp -m tcp --dport 5000:5100 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.2.0/24 -i p3p1 -p tcp -m tcp --dport 5000:5100 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i p1p1 -p tcp -m tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.2.0/24 -i p3p1 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -s 192.168.1.0/24 -i p1p1 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i p1p1 -p tcp -m multiport --dports 20,21,443 -j DROP
-A INPUT -i p1p1 -p tcp --dport 5000:5100 -j DROP
-A INPUT -i p1p1 -p icmp -m icmp --icmp-type 8 -j DROP
-A FORWARD -s 192.168.2.0/24 -j ACCEPT
-A FORWARD -d 192.168.2.0/24 -j ACCEPT
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
-A OUTPUT -j LOG --log-prefix "denied out: "

COMMIT

p1p1 (.1.x) is my external nic, p3p1 (.2.x) is internal.


Source: (StackOverflow)

Getting "error: closed" twice on "adb reverse"

I am trying to reverse-forward port through ADB, but it just returns cryptic error of error: closed. Normal forwarding works. Session snippet:

$ adb forward tcp:59778 tcp:59778
$ adb forward --list
015d2109ce0c1a0f tcp:59778 tcp:59778
$ adb forward --remove-all
$ adb forward --list
$ adb reverse --list
error: closed
error: closed
$ adb reverse tcp:59778 tcp:59778
error: closed
error: closed

I am connecting via USB to non-rooted Nexus 7 2012 Android 4.4.4 from Windows 7 Pro x64 on Boot Camp.


Source: (StackOverflow)

Unexpected overload called when function is called from variadic template instantiation

Assume following code:

#include <iostream>

template<typename... T>
void foo(const T &...);

template<unsigned N>
void foo(const char (&)[N])
{
   std::cout << "char(&)[N]" << std::endl;
}

void foo(const char *)
{
   std::cout << "const char *" << std::endl;
}

template<typename T>
void foo(const T &)
{
   std::cout << "Single" << std::endl;
}

template<typename First, typename... T>
void foo(const First & first, const T &... rest)
{
   std::cout << "Generic + " << sizeof...(T) << std::endl;
   foo(first);
   foo(rest...);
}

int main()
{
    const char * c = "asdf";
    char a[] = {'a', 'b', 'c', 'd'};
    foo('f', c, a, 1);
    foo(a);
}

The output is:

Generic + 3
Single              // fine; 'f' is `char` -> generic
Generic + 2
const char *        // fine; c is `const char *`
Generic + 1
const char *        // (!) not fine
Single
char(&)[N]          // fine; a is char[4]

The last call - foo(a), where a is char[4] - calls the version I'm expecting - template<unsigned N> void foo(const char (&)[N]). But why doesn't instantiation of variadic template of foo call foo(const char (&)[N], but calls foo(const char *) instead? If there wasn't a char array overload, that should be expected - but why is it happening here? Shouldn't const First & capture array type properly?

Also, what would be the easiest way to make the generic variadic version work properly with arrays passed to it?


As Matthieu M. noticed in comments, the problem probably isn't caused by variadic templates, but by indirection:

#include <iostream>

template <unsigned N>
void foo(const char (&)[N])
{
   std::cout << "char(&)[N]" << std::endl;
}

void foo(const char *)
{
   std::cout << "const char *" << std::endl;
}

template <typename T>
void goo(T const& t) {
    foo(t);
}

int main()
{
    char a[] = {'a', 'b', 'c', 'd'};
    foo(a);
    goo(a);
}
    char(&)[N]
    const char *

He also said that it might be compiler bug - although the code yields exactly same results in both Clang 3.2 dev, G++ 4.6 and 4.7.

R. Martinho Fernandes noted that changing a's type in the last snippet to const char a[] makes code yield const char * twice.


Source: (StackOverflow)

Struts 1.3 action forward parameter

I'm working on a little project which uses Struts 1.3 and I encountered the following problem.

After some business logic takes place in an Action i want to forward the control to another Action which is mapped in struts-config.xml.

Usually this is the way I'm solving this:

struts-config.xml

<action path="/boardCreate" type="com.example.BoardCreateAction" name="BoardCreateForm" input="/board.jsp">
    <forward name="success" path="/board.do" redirect="true" />
</action>

Java action class

return mapping.findForward("success");

This will take make a redirect to the board.do action which is also mapped there.

My problem is that I want to redirect the control to something like:

<forward name="success" path="/board.do?id=1" redirect="true" />

Notice the id=1 parameter. Is this any other way except rebuilding my own action forward for this? I can't find any documentation debating this matter. Thanks!


Source: (StackOverflow)

VirtualBox port forwarding not working with NAT adapter

I'm trying simple port forwarding with VirtualBox and it appears VirtualBox.exe is listening on the host to the port, but not actually forwarding the connection to the guest. I've tried on multiple ports, and I've restarted VirtualBox several times. Guest to host connectivity, on the other hand, is fine. Here's the info:

Host: Win7 x64
Guest: Win7 x64
VirtualBox version: VirtualBox 4.2.10
Firewalls: All firewalls on host and guest disabled.

Virtual Box > Machine Settings > Network
 Adapter 1: 
  Attached to: NAT
  Cable Connected : True
  Port Forwarding:
   Rule 1: TCP, HostIP=127.0.0.1, HostPort=8081, GuestIP=127.0.0.1, GuestPort=8081

On Host:
[VirtualBox.exe]  TCP    127.0.0.1:8081         IBM-6KT5OPCF76P:0      LISTENING

On Guest:
I never get the connection request on port 8081 or any others I've tried.

Any ideas? I'd like to avoid using VirtualBox's bridged adapter for multiple reasons. I was under the impression that NAT port forwarding was relatively straightforward with VirtualBox.

Thanks!


Source: (StackOverflow)

In OOP, what is forwarding and how is it different from delegation?

Would someone please explain the difference between forwarding and delegation? They seem similar, but I haven't been able to find a good definition of forwarding, so I'm not sure I really understand.


Source: (StackOverflow)

Why is T&& instantiated as int&?

Can anyone please explain why this compiles and why does t end up with type int&?

#include <utility>

void f(int& r)
{
    ++r;
}

template <typename Fun, typename T>
void g(Fun fun, T&& t) 
{ 
    fun(std::forward<T>(t)); 
}

int main()
{
    int i = 0;

    g(f, i);
}

I see this on GCC 4.5.0 20100604 and GDB 7.2-60.2


Source: (StackOverflow)