Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Frederico Valente <a25285@alunos.det.ua.pt>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Udp connection problem
Date: Sat, 06 Jan 2007 16:52:53 +0000	[thread overview]
Message-ID: <459FD3E5.4080409@alunos.det.ua.pt> (raw)
In-Reply-To: <459F78AA.4020603@crans.org>

Stéphane Glondu wrote:
> Frederico Valente a écrit :
>>     I am trying to communicate with an udp server currently in my computer.
>> The problem is that although I can send messages, and they are correctly
>> received, I dont get any message back (I should). Running a sniffer I
>> get an ICMP Unreacheable (Port Unreacheable) after the server response.
> 
> It sounds like a firewall is filtering your traffic.
> 

Indeed it sounds, but I don't think it is, as I can set up the 
connection using C++.

bool Connection::connect(const char *host, int port )
{
   struct hostent *host_ent;
   struct in_addr *addr_ptr;
   struct sockaddr_in  cli_addr ;
   int    sockfd ;

   m_sock.socketfd = -1 ;

   if( (host_ent = (struct hostent*)gethostbyname(host)) == NULL)
   {
     // if not a string, get information from IP adress.
     if( inet_addr(host) == INADDR_NONE )
     {
       cerr << "(Connection::connect) Cannot find host " << host << endl;
       return false ;
     }
   }
   else   // get the necessary information from the hostname (string)
   {
     addr_ptr = (struct in_addr *) *host_ent->h_addr_list;
     host = inet_ntoa(*addr_ptr);
   }

   //  Open UDP socket.
   if( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
   {
     cerr << "(Connection::connect) Cannot create socket " << host << endl;
     return false ;
   }

   // insert the information of the client
   cli_addr.sin_family      = AF_INET ;
   cli_addr.sin_addr.s_addr = htonl(INADDR_ANY) ;
   cli_addr.sin_port        = htons(0) ;

   // bind the client to the server socket
   if(::bind(sockfd, (struct sockaddr *) &cli_addr, sizeof(cli_addr)) < 0)
   {
     cerr << "(Connection::connect) Cannot bind local address " << host 
<< endl;
     return false ;
   }

   //  Fill in the structure with the address of the server.
   m_sock.socketfd = sockfd ;

   m_sock.serv_addr.sin_family       = AF_INET ;
   m_sock.serv_addr.sin_addr.s_addr  = inet_addr(host);
   m_sock.serv_addr.sin_port         = htons(port) ;

   return true;
}


  reply	other threads:[~2007-01-06 16:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-05 19:23 Frederico Valente
2007-01-06 10:23 ` [Caml-list] " Stéphane Glondu
2007-01-06 16:52   ` Frederico Valente [this message]
2007-01-08 14:27 ` Serge Aleynikov
2007-01-08 23:58   ` Frederico Valente
2007-01-09 21:24     ` Serge Aleynikov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=459FD3E5.4080409@alunos.det.ua.pt \
    --to=a25285@alunos.det.ua.pt \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox