[fpc-pascal]Socket problems

Martyn Ranyard ranyardm at lineone.net
Tue Jul 16 14:34:48 CEST 2002


Hi all, this is my first post to this list, lets see if there are any 
knowledgable eager beavers out there.

I have a program that used to run fine (Compiled with Freepascal on Linux 
ix86 Slackware), but doesn't anymore - admittedly I am now running on a 
rebuilt machine, as the hard disk failed.

here's a snippet :

-------- 8<---------
   lSock := Socket(af_inet, sock_stream, 0);
   if lSock = -1 then SockError('Socket: ');

   with sAddr do
   begin
     Family := af_inet;
     Port := htons(ListenPort);
     Addr := 0;
   end;

   Writeln('Listening on port ',ListenPort);
   if not Bind(lSock, sAddr, sizeof(sAddr)) then SockError('Bind: ');
-------- 8<---------

ListenPort is a word containing 7878

Which when compiled with -Sd gives an exception and with -S2 gives an error 
message :

(ppc386 -Sd program ; ./program)
An unhandled exception occurred at 0x08062E1D :
Access violation
   0x08062E1D
   0x0805E481
   0x08064ECF
   0x080480B0

(ppc386 -S2 program ; ./program)

Bind: Permission denied

Now, I am running as a normal user, but as root, the -S2 version runs 
without error, but does not answer on the port 7878, but on 198. (which 
explains why as a user I cannot bind to it, but why is it listening on 
198?)  The htons() is from inetaux.pas, the code for which is at the end of 
this email, but if I don't have it - and I think I should (the document 
that I have learned from provided the function) - the program doesn't error 
as a user, but even an nmap scan doesn't register any new ports open.

This is most confusing, as I'm sure you can appreciate, and any suggestions 
would be gratefully recieved.

htons() from inetaux.pas :

-------- 8<---------
function htons(i : Integer) : Integer;
begin
    htons := lo(i) shl 8 or hi(i);
end;
-------- 8<---------

Thanks all.

Martyn Ranyard
Free Software Advocate

jabber - joran at amessage.de
icq    - 122500800
irc    - Joran on oftc
msn    - ranyardm at hotmail.com
y!     - ranyardm
e      - ranyardm at lineone.net





More information about the fpc-pascal mailing list