mirror of
https://github.com/vishapoberon/compiler.git
synced 2026-04-05 23:22:25 +00:00
now test server can listen on any ipv4 address.
This commit is contained in:
parent
e36e862c8c
commit
2178fa7b18
2 changed files with 68 additions and 62 deletions
|
|
@ -39,6 +39,7 @@ VAR
|
|||
pid: LONGINT;
|
||||
res: Platform.ErrorCode;
|
||||
sockaddrlen: LONGINT;
|
||||
ipAddr: LONGINT; ip: ARRAY 16 OF CHAR;
|
||||
BEGIN
|
||||
sockfd := sockets.Socket(sockets.AfInet, sockets.SockStream, 0);
|
||||
IF sockfd < 0 THEN
|
||||
|
|
@ -47,8 +48,10 @@ BEGIN
|
|||
Out.String("socket created.")
|
||||
END;
|
||||
Out.Ln;
|
||||
COPY("127.0.0.1", ip);
|
||||
ipAddr := sockets.inetaddr(ip);
|
||||
|
||||
sockets.SetSockAddrIn(sockets.AfInet, Port, 0, ServAddr);
|
||||
sockets.SetSockAddrIn(sockets.AfInet, Port, ipAddr, ServAddr);
|
||||
IF sockets.Bind(sockfd, SYSTEM.VAL(sockets.SockAddr, ServAddr), SIZE(sockets.SockAddr)) < 0 THEN
|
||||
Out.String("error on binding")
|
||||
ELSE
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ TYPE
|
|||
END;
|
||||
|
||||
PROCEDURE -includesocket "#include <sys/socket.h>";
|
||||
PROCEDURE -includeInet "#include <arpa/inet.h>";
|
||||
|
||||
PROCEDURE -inetaddr*(s: ARRAY OF CHAR): LONGINT "(LONGINT)inet_addr((char*)s)";
|
||||
|
||||
PROCEDURE -SetCShort(i: INTEGER; VAR si: oocC.shortint)
|
||||
"*(short*)si = i";
|
||||
|
|
@ -84,7 +87,7 @@ TYPE
|
|||
PROCEDURE -SetCShortSwapped(i: INTEGER; VAR si: oocC.shortint)
|
||||
"*(short*)si = ((i >> 8) & 0x00ff) | ((i << 8) & 0xff00)";
|
||||
|
||||
PROCEDURE SetSockAddrIn*(family, port, inaddr: INTEGER; VAR sai: SockAddrIn);
|
||||
PROCEDURE SetSockAddrIn*(family, port: INTEGER; inaddr: LONGINT; VAR sai: SockAddrIn);
|
||||
VAR i: INTEGER;
|
||||
BEGIN
|
||||
SetCShort(family, sai.SinFamily);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue