Solved

Delphi Programming question

Posted on 1997-09-02
12
270 Views
Last Modified: 2010-04-04
I can't setup my socket to listen at my IP addres.
I don't know if this is Windows Configuration error or i made error in code.

What i'm doing :
I have single PC with NetworkCard. TCPIP and NetBUI, but Dialup adapter too with different TCPIP settings.
I need write and test InternetWWW server.
I create socket and place to Listen mode, i have message procedure for WM_ASYNCSELECTand I call WSAASyncSelect(..)

but when i run IE3.0 it can't connect to my IP or name.

When I setup socket with :
sin.sin_family := AF_INET;
sin.sin_addr.s_addr := INADDR_ANY;
i can connect only to 127.0.0.1

How can i setup socket to listen on My IP?
0
Comment
Question by:mirek071497
12 Comments
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
Adjusted points to 80
0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
Adjusted points to 100
0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
I run Server and IE3.0 on the same PC. Mayby the problem is here?
0
 

Expert Comment

by:kimfriis
Comment Utility
This defenatly looks like what you surgestied your self. That you have a dialup adapter with a different IP setting. I have experinced a similar problem, and also when I was just trying to connect to a network. If the dialup adapter had a different setting, then I would not work. Try and set the two things alike, and see if it works, then you will know if that is the problem.
0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
I remove Dialup adapter from My System and i have the same problem.
I think so i must made error with usage of socket functions.
Please try find what i'm doing wrong.

When I don't set My IP then i can listen on IP=127.0.0.1
but how can i listen on MyIP;

procedure TSockets.SListen;
var
  iStatus: integer;
  szTcp: PChar;
  szPort: array[0..31] of char;
  szData: array[0..256] of char;
  Phe: PHostEnt;
  szHostName: array[0..128] of char;

begin
  FPort = '80';
  { sin is TSockAddrIn }
  sin.sin_family := AF_INET;
  sin.sin_addr.s_addr := INADDR_ANY;

  { this is for set my IP }
  GetHostName(szHostName,128);
  Phe := GetHostByName(szHostName);
  if Phe <> nil then
    sin.sin_addr.s_addr := longint(plongint(Phe^.h_addr_list^)^);

  { show message for test if correct IP was assigned }
  ShowMessage ( inet_ntoa(sin.sin_addr) );

  szTcp := 'tcp';
  StrPCopy(szPort,FPort);
  Pse := getservbyname(szPort,szTcp);
  if Pse = nil then
    sin.sin_port := htons(StrToInt(StrPas(szPort)))
  else
    sin.sin_port := Pse^.s_port;
  Ppe := getprotobyname(szTcp);

  FMSocket := socket(PF_INET,SOCK_STREAM,Ppe^.p_proto);
  if FMSocket < 0 then
    SocketError(INVALID_SOCKET,'socket',WSAGetLastError);

  iStatus := bind(FMSocket, sin, sizeof(sin));
  if iStatus <> 0 then
    SocketError(FMSocket,'Bind',WSAGetLastError);
  iStatus := listen(FMSocket,5);
  if iStatus <> 0 then
    SocketError(FMSocket,'Listen',WSAGetLastError);
  if FMode = 1 then
  begin
    iStatus := WSAASyncSelect(FMSocket,Handle,WM_ASYNCSELECT,
      FD_READ or FD_WRITE or FD_ACCEPT or FD_CLOSE);
    if iStatus <> 0 then
      SocketError(FMSocket,'WSAASyncSelect',WSAGetLastError);
  end
  else ioctlsocket(FMSocket,FIONBIO,FMode);
end;

0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
Adjusted points to 120
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 3

Author Comment

by:mirek071497
Comment Utility
Adjusted points to 133
0
 
LVL 1

Expert Comment

by:AJFleming
Comment Utility
First thing that I can see is that your 'sin' is unsassigned at
the start of the function call... is it global? And if so, are you _Sure_ it's set to something sensible because your GetHostByName() call is going to fall over without a DNS set.

My best bet is that there's a problem with your win setup. Working TCP/IP programming withouth more than 1 mahcine is a real pain in the ass.
0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
Hi AjFleming !
thanx for comment. I newbie with server socket programming so if you have time i give you points with A for some talk here.

1.I found so i don't need set my IP and i can't set my IP when i need make connections from more than one networks. Is this correct ?
2.I think so i have error with socket number. Do you know sockets number which is for use with WWW and other ? (some i know i.e. echo=7, mail=25 .... )
3.Can you help me vith basic principies of setting up sockets for servers ?

Regards
Mirek
0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
Hi All. I found the solution !

IP is for the wire to host not for the host (example : when you have more than one wires to network you need more than one IP!) and in result I can't call my machine with their IP.
IP 127.any.any.any is for call to local host only and this is the answer.

I wait 3 days to give you time to read this and i delete this question.
0
 
LVL 7

Accepted Solution

by:
linda101698 earned 0 total points
Comment Utility
I'm posting the solution so the answer can be saved in the PAQ.

Hi All. I found the solution !

IP is for the wire to host not for the host (example : when you have more than one wires to network you need more than one IP!) and in result I can't call my machine with their IP.
                     
IP 127.any.any.any is for call to local host only and this is the answer.
0
 
LVL 3

Author Comment

by:mirek071497
Comment Utility
i see so this server have more bugs than Windows95 !
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now