Listen on user-specified addresses
[mgsmtp.git] / Network.pas
index 5ef26164939b85795cf4abc85ef5cf93d20ba9f4..10a95f991d3898060489ecfdc31d252c242b81d7 100644 (file)
@@ -1,6 +1,6 @@
 {
    Basic object-oriented network functions
 {
    Basic object-oriented network functions
-   Copyright (C) 2010-2014 MegaBrutal
+   Copyright (C) 2010-2018 MegaBrutal
 
    This unit is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
 
    This unit is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
@@ -99,10 +99,11 @@ type
    end;
 
    TTCPListener = class(TThread)
    end;
 
    TTCPListener = class(TThread)
-      constructor Create(Port: word; FeatureRequest: word);
+      constructor Create(const Address: string; Port: word; FeatureRequest: word);
       {destructor Destroy; override;}
    private
       FFeatureRequest: word;
       {destructor Destroy; override;}
    private
       FFeatureRequest: word;
+      FListenAddress: string;
       FListenPort: word;
       FListenSocket: socket;
       sAddr: TSockAddr;
       FListenPort: word;
       FListenSocket: socket;
       sAddr: TSockAddr;
@@ -163,8 +164,9 @@ begin
 end;
 
 
 end;
 
 
-constructor TTCPListener.Create(Port: word; FeatureRequest: word);
+constructor TTCPListener.Create(const Address: string; Port: word; FeatureRequest: word);
 begin
 begin
+   FListenAddress:= Address;
    FListenPort:= Port;
    FFeatureRequest:= FeatureRequest;
    FreeOnTerminate:= false;
    FListenPort:= Port;
    FFeatureRequest:= FeatureRequest;
    FreeOnTerminate:= false;
@@ -292,12 +294,11 @@ begin
       with sAddr do begin
          sin_family:= af_inet;
          sin_port:= htons(FListenPort);
       with sAddr do begin
          sin_family:= af_inet;
          sin_port:= htons(FListenPort);
-         sin_addr.s_addr:= 0;
+         sin_addr:= ResolveHost(FListenAddress);
       end;
       if fpBind(FListenSocket, @sAddr, sizeof(sAddr)) <> -1 then begin
          { It seems the maximum connection value isn't enforced by the
            Free Pascal library, so this 512 is a constant, dummy value. }
       end;
       if fpBind(FListenSocket, @sAddr, sizeof(sAddr)) <> -1 then begin
          { It seems the maximum connection value isn't enforced by the
            Free Pascal library, so this 512 is a constant, dummy value. }
-           { TEMPORARY SETTING OF 1 FROM 512! }
          if fpListen(FListenSocket, 512) <> -1 then begin
             Result:= true;
             Start;
          if fpListen(FListenSocket, 512) <> -1 then begin
             Result:= true;
             Start;