By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,661 Members | 1,330 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,661 IT Pros & Developers. It's quick & easy.

Getting Local Port Number in Perl

darksteel21
P: 36
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
Apr 27 '09 #1
Share this Question
Share on Google+
6 Replies


Icecrack
Expert 100+
P: 174
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?
Apr 27 '09 #2

darksteel21
P: 36
I am trying to get the client to send its port to the server for authentication...
my perl script resides on the client..
Apr 27 '09 #3

Icecrack
Expert 100+
P: 174
how are you calling your socket

have you tried?

socketpair(DOMAIN, TYPE, PROTOCOL)
Apr 27 '09 #4

darksteel21
P: 36
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
Apr 27 '09 #5

RRick
Expert 100+
P: 463
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
May 5 '09 #6

darksteel21
P: 36
thanks for these information, i'll study these methods...
May 6 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.