×
The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.
//*********************************************************************
// Program Description/Documentation
//
// DATE: 1/25/10
// DESCRIPTION: Check for internet availability.
//*********************************************************************
D ZNETISUP_Val S 1
// Check for internet availability
D ZNETISUP PR 1
D P#Site 255 VALUE
D P#Port 5 0 VALUE
D P#Timeout 5 0
VALUE
H/Copy Qrpglesrc,OITHSPEC
Note: This is the content of OITHSPEC
ctl-opt option(*nodebugio:*srcstmt);
ctl-opt nomain;
ctl-opt debug(*input);
//---------------------------------------------------------------------
// Management Information Systems
//*********************************************************************
// Program Description/Documentation
//
// AUTHOR: Gerald Kern
// DATE: 1/25/10
// DESCRIPTION: Check for internet availability by attempting to
// create a socket connection to google.com on port 80. Other sites
// using other ports may be passed as parameters. A timeout value
// in seconds allows you to specify how long to wait to connect.
//
// Programs using this function must include the following
// statement in that program's H spec:
// H BNDDIR('SOCKTUT/SOCKUTIL')
//
//Compile instructions:
// 1st-Compile this program as a module.
//*********************************************************************
// L O G O F P R O G R A M M O D I F I C A T I O N S
//*********************************************************************
// Date Programmer Description of Modifications
// -------- ----------
----------------------------------------------
//XX/XX/XX XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Copybook for ZNETISUP PR specs
D/Copy Qrpglesrc,ZNETISUPPR
// Begin prototype procedure
P ZNETISUP B EXPORT
D ZNETISUP PI 1
D P#Site 255 VALUE
D P#Port 5 0 VALUE
D P#Timeout 5 0 VALUE
//********************************************************
// end of IFS API call definitions
//********************************************************
D sock S 10I 0
D port S 5U 0
D flags S 10I 0
D host s 32A
D addr s 10U 0
D connto S like(sockaddr_in)
D err S 10I 0
D connfds S like(fdset)
D timeout S like(timeval)
D Yes C 'Y'
D No C 'N'
//+++++++++++++++++ M A I N L I N E C A L C S +++++++++++++++++
/FREE
If P#Port = *Zero;
P#Port = 80;
Endif;
Port = P#Port;
If P#Timeout = *Zero;
P#Timeout = 60;
Endif;
// Attempt to connect to server...
Exsr Conn_To_Svr;
Return ZNETISUP_Val;
*InLr = *On;
//++++++++++++++++++++ S U B R O U T I N E S ++++++++++++++++++++
//*********************************************************************
// Conn_To_Svr - Attempt to establish connection with the server.
// Assume connection is up and must prove otherwise...
ZNETISUP_Val = Yes;
//************************************************
// Get the 32-bit network IP address for the host
// that was supplied by the user:
//************************************************
addr = inet_addr(%trim(host));
if addr = INADDR_NONE;
p_hostent = gethostbyname(%trim(host));
if p_hostent = *NULL;
ZNETISUP_Val = No;
LeaveSr;
endif;
addr = h_addr;
endif;
//************************************************
// Create a socket
//************************************************
sock = socket(AF_INET: SOCK_STREAM:
IPPROTO_IP);
if sock < 0;
ZNETISUP_Val = No;
LeaveSr;
endif;
//************************************************
// Put the socket in non-blocking mode:
//************************************************
flags = fcntl(sock: F_GETFL);
flags = flags + O_NONBLOCK;
if fcntl(sock: F_SETFL: flags) < 0;
ZNETISUP_Val = No;
LeaveSr;
endif;
//************************************************
// Create a socket address structure that
// describes the host & port we wanted to
// connect to
//************************************************
p_sockaddr = %addr(connto);
//************************************************
// Start the connection process.
//************************************************
if connect(sock: %addr(connto):
%size(connto) ) < 0;
err = errno;
if err <> EINPROGRESS;
callp close(sock);
ZNETISUP_Val = No;
LeaveSr;
endif;
endif;
//************************************************
// wait up to P#Timeout (seconds) for connection to be made
//************************************************
FD_ZERO(connfds);
FD_SET(sock: connfds);
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact
[javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.