[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

How can i set a port number

Dear Experts,

In my programm I have put 2 edit-boxes, where the user must specify the IP-address/Hostname
and the Port number to make a connection to a server. The IP-address/Hostname editbox is finished. Only I have a hard time to find where in the procedure MakeConnect the port number
is specified!

I have put a partial code of the procedure MakeConnect, because it's a long procedure.

procedure MakeConnect;
var
 usPort: u_short;         <=============
...
 usPort := pServAddr^.s_port;          <===============
 RemoteAddr.sin_family := AF_INET;
 RemoteAddr.sin_addr.s_addr := ina.s_addr;
 RemoteAddr.sin_port := usPort;         <==============
 psaddr := Pointer(@RemoteAddr);

The port 23 is specified in this code, because when i look at my logging i see this:

TCP Started.
Socket opened OK.
Foreign host name: 145.70.16.5
    Address type: 2
    Address length: 4
    Foreign host address: 145.70.16.5
Local host name: cp557259-a
    Address type: 2
    Address length: 4
    Local host address: 192.168.1.2
Bind successful
Remote Service Info.:
    Name: telnet
    Port: 23              <===========
Connect error: 10060
TCP Ended.

How can i when the user enter a port number in the edit-box pass it on to the
MakeConnect-procedure?

Greetings,

Peter Kiers
0
peterkiers
Asked:
peterkiers
  • 4
  • 2
1 Solution
 
MerijnBSr. Software EngineerCommented:
usPort := pServAddr^.s_port;          <===============
 

what is pServAddr and where is it filled in?
0
 
peterkiersAuthor Commented:
Procedure MakeConnect;
I have put here al the lines with pServAddr:

var
  pServAddr: PServEnt;   <== is also declared
        .....
          pServAddr := getservbyname('telnet', 'tcp');
          if pServAddr <> nil then
        .....
            usPort := pServAddr^.s_port;
            RemoteAddr.sin_family := AF_INET;
            RemoteAddr.sin_addr.s_addr := ina.s_addr;
            RemoteAddr.sin_port := usPort;
        .....

Peter          
0
 
peterkiersAuthor Commented:
I have put the complete procedure on my site

http://members.home.nl/peterkiers/
(click on the floppy-disk underneath the Under Construction bar)

I hope this makes it easer...

P.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
MerijnBSr. Software EngineerCommented:
         pServAddr := getservbyname('telnet', 'tcp');

is the line what makes you use port 23. Telnet is default on port 23 (see for example http://www.iana.org/assignments/port-numbers);

So if you want to change it you'll need something like:

procedure MakeConnect(PortNr: integer);
var
 usPort: u_short;         <=============
...
 usPort := PortNr;          <===============
 RemoteAddr.sin_family := AF_INET;
 RemoteAddr.sin_addr.s_addr := ina.s_addr;
 RemoteAddr.sin_port := usPort;         <==============
 psaddr := Pointer(@RemoteAddr);
end;

//...

MakeConnect(StrToInt(EditPortNr.Text));
0
 
peterkiersAuthor Commented:
The portnumber that the user enters in a edit-box
is stored in a variable called ConnectPortName.

var
 usPort: u_short;        
...
 usPort := //what do i have to put here???
 RemoteAddr.sin_family := AF_INET;
 RemoteAddr.sin_addr.s_addr := ina.s_addr;
 RemoteAddr.sin_port := usPort;        
 psaddr := Pointer(@RemoteAddr);
end;
0
 
peterkiersAuthor Commented:
Thanks i have got it.

Peter Kiers
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now