You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by steven liu <st...@gmail.com> on 2011/09/11 18:24:25 UTC

problem for plugin example: server-transform.c

Dear All,

I am tring to run a plugin example: server-transform.c under V3.0.0. But I
found that it does not work out of the box. Firstly, it cannot be compiled
properly due to TSNetConnect(contp, server_ip, server_port);

In V3.0.0, the parameter of this function has been changed to
TSNetConnect(TSCont contp, sockaddr const* addr);

I have tried to change to the new function. However, it does not work
properly. This transform plugin actually sends received buffer to a local
socket server (echo server), which will send the content back to the plugin.
I found that even TSNetConnect() returns SUCCESS, but it does not send
anything out to the socket server. I have tried to use TCPdump to capture
packets with port = 7 (echo port). BUt I did not captured any such packets.
It looks like TSNetConnect() has some problems. Many thanks for any help.

Rgds,
Steve

Re: problem for plugin example: server-transform.c

Posted by steven liu <st...@gmail.com>.
Tks. I actually tried to hard code the port number using:

ip4addr.sin_port = htons(5566);

And the following output from netstat indicates that I have a socket
listening at port 5566.

tcp        0      0 0.0.0.0:5566            0.0.0.0:*               LISTEN

It looks quite strange. TCPDump cannot capture any packet with port 5566.
And my local server listening at port 5566 also does not receive any
packets.

May I know how to run regression test for TSNetConnect()? Tks.


On Mon, Sep 12, 2011 at 10:57 PM, Alan M. Carroll <
amc@network-geographics.com> wrote:

> Actually, Chris, you should use htons since this is going from host to
> network order. However on all modern systems htons() and ntohs() are the
> same function. Some of us old timers remember systems where that wasn't the
> case but those have long since faded to memories.
>
> I think TSNetConnect gets tested during regression, so this seems a rather
> unexpected failure. From where do you get server_port? atoi and its ilk,
> hard wired constant, or some other network connection?
>
> Can you do a netstat -a -n --tcp and verify that the listening process is
> listening on the port you expect?
>
> Monday, September 12, 2011, 9:20:26 AM, you wrote:
>
> > On 3.1 I have to use the ntohs function for the port number when using
> > TsNetConnect. Have you tried this?
>
> > On 12 September 2011 02:33, steven liu <st...@gmail.com> wrote:
>
> >> Thanks. Yes. I am setting port using hons() using following codes.
>
> >> struct sockaddr_in ip4addr;
> >> ip4addr.sin_family = AF_INET;
> >> ip4addr.sin_port = htons(server_port);
> >> ip4addr.sin_addr.s_addr = inet_addr((const char *)("127.0.0.1"));
> >> action = TSNetConnect(contp,  (struct sockaddr const*)&ip4addr);
>
>

Re: problem for plugin example: server-transform.c

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
Monday, September 12, 2011, 10:28:17 AM, you wrote:

> The server port comes from a URL, e.g. http://10.44.10.1:80, and I just atoi
> the port. I have checked with a network trace that the correct port is being
> connected to. With previous versions of Traffic Server I never had to
> use ntohs and
> just passed in the atoied number.

Sorry Chris, the question about the port was for Stephen Liu. Before 3.0.0 the port value to TSNetConnect was in host order. With the change to use sockaddr instead of separate IPv4 address and port the ordering was changed to be consistent with the definition of a sockaddr.


Re: problem for plugin example: server-transform.c

Posted by Chris Reynolds <sh...@gmail.com>.
The server port comes from a URL, e.g. http://10.44.10.1:80, and I just atoi
the port. I have checked with a network trace that the correct port is being
connected to. With previous versions of Traffic Server I never had to
use ntohs and
just passed in the atoied number.

On 12 September 2011 15:57, Alan M. Carroll <am...@network-geographics.com>wrote:

> Actually, Chris, you should use htons since this is going from host to
> network order. However on all modern systems htons() and ntohs() are the
> same function. Some of us old timers remember systems where that wasn't the
> case but those have long since faded to memories.
>
> I think TSNetConnect gets tested during regression, so this seems a rather
> unexpected failure. From where do you get server_port? atoi and its ilk,
> hard wired constant, or some other network connection?
>
> Can you do a netstat -a -n --tcp and verify that the listening process is
> listening on the port you expect?
>
> Monday, September 12, 2011, 9:20:26 AM, you wrote:
>
> > On 3.1 I have to use the ntohs function for the port number when using
> > TsNetConnect. Have you tried this?
>
> > On 12 September 2011 02:33, steven liu <st...@gmail.com> wrote:
>
> >> Thanks. Yes. I am setting port using hons() using following codes.
>
> >> struct sockaddr_in ip4addr;
> >> ip4addr.sin_family = AF_INET;
> >> ip4addr.sin_port = htons(server_port);
> >> ip4addr.sin_addr.s_addr = inet_addr((const char *)("127.0.0.1"));
> >> action = TSNetConnect(contp,  (struct sockaddr const*)&ip4addr);
>
>

Re: problem for plugin example: server-transform.c

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
Actually, Chris, you should use htons since this is going from host to network order. However on all modern systems htons() and ntohs() are the same function. Some of us old timers remember systems where that wasn't the case but those have long since faded to memories.

I think TSNetConnect gets tested during regression, so this seems a rather unexpected failure. From where do you get server_port? atoi and its ilk, hard wired constant, or some other network connection?

Can you do a netstat -a -n --tcp and verify that the listening process is listening on the port you expect?

Monday, September 12, 2011, 9:20:26 AM, you wrote:

> On 3.1 I have to use the ntohs function for the port number when using
> TsNetConnect. Have you tried this?

> On 12 September 2011 02:33, steven liu <st...@gmail.com> wrote:

>> Thanks. Yes. I am setting port using hons() using following codes.

>> struct sockaddr_in ip4addr;
>> ip4addr.sin_family = AF_INET;
>> ip4addr.sin_port = htons(server_port);
>> ip4addr.sin_addr.s_addr = inet_addr((const char *)("127.0.0.1"));
>> action = TSNetConnect(contp,  (struct sockaddr const*)&ip4addr);


Re: problem for plugin example: server-transform.c

Posted by Chris Reynolds <sh...@gmail.com>.
On 3.1 I have to use the ntohs function for the port number when using
TsNetConnect. Have you tried this?

On 12 September 2011 02:33, steven liu <st...@gmail.com> wrote:

> Thanks. Yes. I am setting port using hons() using following codes.
>
> struct sockaddr_in ip4addr;
> ip4addr.sin_family = AF_INET;
> ip4addr.sin_port = htons(server_port);
> ip4addr.sin_addr.s_addr = inet_addr((const char *)("127.0.0.1"));
> action = TSNetConnect(contp,  (struct sockaddr const*)&ip4addr);
>
>
>
>
> On Mon, Sep 12, 2011 at 6:34 AM, Alan M. Carroll <
> amc@network-geographics.com> wrote:
>
> > Are you setting the port in the sockaddr? Note that in a sockaddr, all
> data
> > is in network order (including the port).
> >
> > Sunday, September 11, 2011, 11:24:25 AM, you wrote:
> >
> > > Dear All,
> >
> > > I am tring to run a plugin example: server-transform.c under V3.0.0.
> But
> > I
> > > found that it does not work out of the box. Firstly, it cannot be
> > compiled
> > > properly due to TSNetConnect(contp, server_ip, server_port);
> >
> > > In V3.0.0, the parameter of this function has been changed to
> > > TSNetConnect(TSCont contp, sockaddr const* addr);
> >
> > > I have tried to change to the new function. However, it does not work
> > > properly. This transform plugin actually sends received buffer to a
> local
> > > socket server (echo server), which will send the content back to the
> > plugin.
> > > I found that even TSNetConnect() returns SUCCESS, but it does not send
> > > anything out to the socket server. I have tried to use TCPdump to
> capture
> > > packets with port = 7 (echo port). BUt I did not captured any such
> > packets.
> > > It looks like TSNetConnect() has some problems. Many thanks for any
> help.
> >
> > > Rgds,
> > > Steve
> >
> >
>

Re: problem for plugin example: server-transform.c

Posted by steven liu <st...@gmail.com>.
Thanks. Yes. I am setting port using hons() using following codes.

struct sockaddr_in ip4addr;
ip4addr.sin_family = AF_INET;
ip4addr.sin_port = htons(server_port);
ip4addr.sin_addr.s_addr = inet_addr((const char *)("127.0.0.1"));
action = TSNetConnect(contp,  (struct sockaddr const*)&ip4addr);




On Mon, Sep 12, 2011 at 6:34 AM, Alan M. Carroll <
amc@network-geographics.com> wrote:

> Are you setting the port in the sockaddr? Note that in a sockaddr, all data
> is in network order (including the port).
>
> Sunday, September 11, 2011, 11:24:25 AM, you wrote:
>
> > Dear All,
>
> > I am tring to run a plugin example: server-transform.c under V3.0.0. But
> I
> > found that it does not work out of the box. Firstly, it cannot be
> compiled
> > properly due to TSNetConnect(contp, server_ip, server_port);
>
> > In V3.0.0, the parameter of this function has been changed to
> > TSNetConnect(TSCont contp, sockaddr const* addr);
>
> > I have tried to change to the new function. However, it does not work
> > properly. This transform plugin actually sends received buffer to a local
> > socket server (echo server), which will send the content back to the
> plugin.
> > I found that even TSNetConnect() returns SUCCESS, but it does not send
> > anything out to the socket server. I have tried to use TCPdump to capture
> > packets with port = 7 (echo port). BUt I did not captured any such
> packets.
> > It looks like TSNetConnect() has some problems. Many thanks for any help.
>
> > Rgds,
> > Steve
>
>

Re: problem for plugin example: server-transform.c

Posted by "Alan M. Carroll" <am...@network-geographics.com>.
Are you setting the port in the sockaddr? Note that in a sockaddr, all data is in network order (including the port).

Sunday, September 11, 2011, 11:24:25 AM, you wrote:

> Dear All,

> I am tring to run a plugin example: server-transform.c under V3.0.0. But I
> found that it does not work out of the box. Firstly, it cannot be compiled
> properly due to TSNetConnect(contp, server_ip, server_port);

> In V3.0.0, the parameter of this function has been changed to
> TSNetConnect(TSCont contp, sockaddr const* addr);

> I have tried to change to the new function. However, it does not work
> properly. This transform plugin actually sends received buffer to a local
> socket server (echo server), which will send the content back to the plugin.
> I found that even TSNetConnect() returns SUCCESS, but it does not send
> anything out to the socket server. I have tried to use TCPdump to capture
> packets with port = 7 (echo port). BUt I did not captured any such packets.
> It looks like TSNetConnect() has some problems. Many thanks for any help.

> Rgds,
> Steve