Hi James,

i've just converted tuo network byte order with the function:

server_port = htons(server_port);

and the code worked as expected

thanks again,
Heitor Ganzeli


On 03/19/2013 03:30 PM, James Peach wrote:
> On Mar 19, 2013, at 11:20 AM, Heitor Ganzeli <[email protected]> wrote:
>
>> hello,
>>
>> i've been trying to tackle this connection problem and came up with this 
>> minimal code to start a connection
>>     in_addr_t server_ip;
>>     int server_port;
>>     server_ip = (192 << 24) | (168 << 16) | (0 << 8) | (2);
>>     server_ip = htonl(server_ip);
>>     server_port = 80;
>>
>>     memset(&ip_addr, 0, sizeof(ip_addr));
>>     ip_addr.sin_family = AF_INET;
>>     ip_addr.sin_addr.s_addr = server_ip; /* Should be in network byte order 
>> */
>>     ip_addr.sin_port = server_port;
> sin_port should be in network byte order too.
>
>>
>>     txn_sm->q_pending_action = TSNetConnect(contp,
>>             (struct sockaddr const*) &ip_addr);
>>
>> but, despite trafficserver is already starting a connection, the port it 
>> connects is 20480 instead of 80 as specified in the code.
>> Does anyone know how to solve this problem? i've already tried to follow 
>> some example plugin codes but it seams I keep missing something in order for 
>> the request to work... 
>>
>>
>> thanks,
>> Heitor Ganzeli
>>
>>
>> On 03/14/2013 04:02 PM, Heitor Ganzeli wrote:
>>> Hi all,
>>>
>>> For a couple of weeks, I've been trying to develop a plugin capable of 
>>> doing some specific requests to other server. And, I'm still stuck. So I'd 
>>> like if anyone could help me with this plugin or give some guidance on 
>>> where to look for the answer.
>>>
>>> the problem is as follow:
>>>
>>> I'm on a Ubuntu 12.04 machine using traffic server 3.2.x from the git 
>>> repository and I'm trying to do something similar to the protocol plugin 
>>> which is included in the examples folder.
>>> By now, could rightly start a connection via TSNetConnet and receive its 
>>> call back event, TS_EVENT_NET_CONNECT. However, when i try to write 
>>> something to the TSVConn objetc, via TSVConnWrite, it crashes.
>>>
>>> the code is as follows:
>>>     TxnSM *txn_sm = (TxnSM *) TSContDataGet(contp);
>>>     struct sockaddr const* q_server_addr;
>>>     struct sockaddr_in ip_addr;
>>>
>>>     /* Get the server IP from data structure TSHostLookupResult. */
>>>     q_server_addr = TSHostLookupResultAddrGet(host_info);
>>>
>>>     memcpy(&ip_addr, q_server_addr, sizeof(ip_addr));
>>>     ip_addr.sin_port = 80;
>>>     
>>>     txn_sm->q_pending_action = TSNetConnect(contp,
>>>             (struct sockaddr const*) &ip_addr);
>>> and, although port is set to 80, the request is made to the port 20480.
>>> then, when it receives the TS_EVENT_NET_CONNECT event, the code is as 
>>> follows:
>>>
>>>     TxnSM *txn_sm = (TxnSM *) TSContDataGet(contp);
>>>     txn_sm->q_pending_action = NULL;
>>>     txn_sm->q_server_vc = vc;
>>>
>>>     TSIOBuffer bufp = TSIOBufferCreate();
>>>     TSIOBufferReader bufp_reader = TSIOBufferReaderAlloc(bufp);
>>>
>>>     TSIOBufferWrite(bufp, "test", strlen("test"));
>>>
>>>     txn_sm->q_server_write_vio = TSVConnWrite(txn_sm->q_server_vc, contp,
>>>             bufp_reader, strlen("teste"));
>>>
>>> After this execution, the Continuation contp do not receive events call 
>>> back anymore.
>>> The stack trace is below, but I con't think it is much of help:
>>> /usr/local/bin/traffic_server(_ZN6HttpSM16do_hostdb_lookupEv+0xaa)[0x5271ea]
>>> /usr/local/bin/traffic_server(_ZN6HttpSM14set_next_stateEv+0x10b7)[0x538677]
>>> /home/heitor/workspace/trafficserver/plugins/ptt-cache/ptt-cache.so(prepare_to_die+0x39)[0x2afb00206a99]
>>> /usr/local/bin/traffic_server(_Z15write_to_net_ioP10NetHandlerP18UnixNetVConnectionP7EThread+0x12bc)[0x686f6c]
>>> /usr/local/bin/traffic_server(_ZN10NetHandler12mainNetEventEiP5Event+0x293)[0x67d663]
>>> /lib/x86_64-linux-gnu/libpthread.so.0(+0xfcb0)[0x2afae325fcb0]
>>> /usr/local/bin/traffic_server(_ZN7EThread13process_eventEP5Eventi+0x90)[0x6ab570]
>>> /usr/local/bin/traffic_server(_ZN15HostDBProcessor13getbyname_immEP12ContinuationMS0_FvP10HostDBInfoEPKciiii+0x8d)[0x5e217d]
>>> /usr/local/bin/traffic_server(_ZN7EThread7executeEv+0x52c)[0x6ac06c]
>>> /usr/local/bin/traffic_server(_ZN6HttpSM16do_hostdb_lookupEv+0xaa)[0x5271ea]
>>> /usr/local/bin/traffic_server[0x6aa352]
>>> /usr/local/bin/traffic_server(_ZN6HttpSM14set_next_stateEv+0x10b7)[0x538677]
>>> /home/heitor/workspace/trafficserver/plugins/ptt-cache/ptt-cache.so(prepare_to_die+0x39)[0x2afb00206a99]
>>> /usr/local/bin/traffic_server(_Z15write_to_net_ioP10NetHandlerP18UnixNetVConnectionP7EThread+0x12bc)[0x686f6c]
>>> /usr/local/bin/traffic_server(_ZN10NetHandler12mainNetEventEiP5Event+0x293)[0x67d663]
>>> /usr/local/bin/traffic_server(_ZN7EThread13process_eventEP5Eventi+0x90)[0x6ab570]
>>> /usr/local/bin/traffic_server(_ZN7EThread7executeEv+0x52c)[0x6ac06c]
>>> /usr/local/bin/traffic_server[0x6aa352]
>>>
>>> Furthermore, I've already tried some alternatives like the TSHttpConnect 
>>> but the result was simmilar 
>>>
>>> thanks in advance,
>>>
>>> Regards,
>>> Heitor Ganzeli
>>>
>>>
>>>
>>>
>> <heitor.vcf>

<<attachment: heitor.vcf>>

Reply via email to