# Thread: Can someone help me out with these 2 problems?

1. Hi,

I am trying to make an FTP server. I am having some problems
with this, however. Actually I have 2 problems at this time.

My first problem is (really a math problem I guess):

When a client connects it sends the PORT command to establish a data socket connection. Now, the client
sends it's IP and the port it's listening on in a format
that I don't understand: it sends a string like:

PORT 102,32,69,120,15,208

where the first 4 numbers (102,32,69 and 120) form the
IP address, and the last 2 (15,208) from the port.

Now, how do I find out what the port number is?

perhaps these hints will help:
------------------------------------------------------
DATA PORT (PORT)

The argument is a HOST-PORT specification for the data port
to be used in data connection. There are defaults for both
the user and server data ports, and under normal
circumstances this command and its reply are not needed. If
this command is used, the argument is the concatenation of a
This address information is broken into 8-bit fields and the
value of each field is transmitted as a decimal number (in
character string representation). The fields are separated
by commas. A port command would be:
PORT h1,h2,h3,h4,p1,p2

where h1 is the high order 8 bits of the internet host address.
---------------------------------------------------------

My 2nd question should be easier:

If I'm listening on a port and someone connects, then how do I find out the IP of the person connecting?

I hope someone can help me out here,

vbDan

2. my binary math skills are not very good, but if p1 is the "high region" (above 8-bit), then take (in your example)

Code:
```Dim lowpart As Byte, highpart As Byte, fullpart As Long
lowpart = 208 'p2
highpart = 15 'p1
fullpart = (highpart * 256) + lowpart```
This may be completly wrong, but i'm not sure. I've done this before, once (adding a 4-bit binary number to a 8-bit binary number

You were right; someone else told me (as well) that:

Port = (p1 * 256) + p2

--
p1 = port/256
p2 = port And 255

4. You must be connected to the person to get their ip address. It is stored in the RemoteIP property of the Winsock control that is connected. If you're doing this through code, I have no idea.

5. Well, I *think* I got it;

What I am using now gives my an IP, unfortunatly
when I connect it tells me the IP = "127.0.0.1"
which is my local IP, not my real IP.
I just hope that it will work when other people connect
to the server.

What I use is:

mRemoteIP = lngIPtoStrIP(ToDo)

Public Function lngIPtoStrIP(ByVal longip As Long) As String

Dim dotted As String
Dim i As Long
Dim tval As Long

If longip < 0 Then
tval = 255
longip = longip + 1
End If

For i = 1 To 3
dotted = dotted + CStr((longip Mod 256) + tval) + "."
longip = Fix(longip \ 256)
Next

dotted = dotted + CStr(longip + tval)
lngIPtoStrIP = dotted

End Function

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•