Connecting Tech Pros Worldwide Help | Site Map

Getting Local Port Number in Perl

darksteel21's Avatar
Newbie
 
Join Date: Jul 2008
Posts: 15
#1: Apr 27 '09
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's Avatar
Expert
 
Join Date: Sep 2008
Location: Sydney, Australia
Posts: 173
#2: Apr 27 '09

re: Getting Local Port Number in Perl


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?
darksteel21's Avatar
Newbie
 
Join Date: Jul 2008
Posts: 15
#3: Apr 27 '09

re: Getting Local Port Number in Perl


I am trying to get the client to send its port to the server for authentication...
my perl script resides on the client..
Icecrack's Avatar
Expert
 
Join Date: Sep 2008
Location: Sydney, Australia
Posts: 173
#4: Apr 27 '09

re: Getting Local Port Number in Perl


how are you calling your socket

have you tried?

socketpair(DOMAIN, TYPE, PROTOCOL)
darksteel21's Avatar
Newbie
 
Join Date: Jul 2008
Posts: 15
#5: Apr 27 '09

re: Getting Local Port Number in Perl


i am using these codes :
Expand|Select|Wrap|Line Numbers
  1. $r_socket = IO::Socket::INET->new(PeerAddr => $ServerIP,PeerPort => $ServerPort,Proto => 'tcp') or die("Socket Error Connection");
I am using the IO:Socket module
RRick's Avatar
Expert
 
Join Date: Feb 2007
Posts: 428
#6: May 5 '09

re: Getting Local Port Number in Perl


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::INET:

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

For more info try http://docstore.mik.ua/orelly/perl/perlnut/ch13_02.htm
darksteel21's Avatar
Newbie
 
Join Date: Jul 2008
Posts: 15
#7: May 6 '09

re: Getting Local Port Number in Perl


thanks for these information, i'll study these methods...
Reply