Getting Local Port Number in Perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • darksteel21
    New Member
    • Jul 2008
    • 36

    Getting Local Port Number in Perl

    Hi to all,

    I am currently developing an application in perl that is capable of connecting to a server and sends information..
    the server has a deamon that listens to the socket connections. It requires a socket port number of the client used in making a socket connection for validation..

    is there a way in perl in which i can get the local port number (client side) used in making a socket connection to the server?(using Socket and IO:Socket libraries only)

    Regards,
    Mark Tan
  • Icecrack
    Recognized Expert New Member
    • Sep 2008
    • 174

    #2
    Let me clear up on this, you are trying to get the client to send its port to the server for auth?

    or are you trying just to find out what port the client is running on?

    Comment

    • darksteel21
      New Member
      • Jul 2008
      • 36

      #3
      I am trying to get the client to send its port to the server for authentication. ..
      my perl script resides on the client..

      Comment

      • Icecrack
        Recognized Expert New Member
        • Sep 2008
        • 174

        #4
        how are you calling your socket

        have you tried?

        socketpair(DOMA IN, TYPE, PROTOCOL)

        Comment

        • darksteel21
          New Member
          • Jul 2008
          • 36

          #5
          i am using these codes :
          Code:
          $r_socket = IO::Socket::INET->new(PeerAddr => $ServerIP,PeerPort => $ServerPort,Proto => 'tcp') or die("Socket Error Connection");
          I am using the IO:Socket module
          Last edited by eWish; Apr 27 '09, 10:05 PM. Reason: Please use the code tags

          Comment

          • RRick
            Recognized Expert Contributor
            • Feb 2007
            • 463

            #6
            You are almost there, the following methods will supply the info you need.

            The following methods can be used on socket filehandle objects created by IO::Socket::INE T:

            * sockaddr
            * sockport
            * sockhost
            * peeraddr
            * peerport
            * peerhost

            For more info try http://docstore.mik.ua/orelly/perl/perlnut/ch13_02.htm

            Comment

            • darksteel21
              New Member
              • Jul 2008
              • 36

              #7
              thanks for these information, i'll study these methods...

              Comment

              Working...