BOOL amiga_init()
{
  if(!SocketBase)
    SocketBase = OpenLibrary("bsdsocket.library", 4);
  
  if(!SocketBase) {
    __request("No TCP/IP Stack running!");
    return FALSE;
  }
  
  if(SocketBaseTags(
    SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (ULONG) &errno,
//    SBTM_SETVAL(SBTC_HERRNOLONGPTR),     (ULONG) &h_errno,
    SBTM_SETVAL(SBTC_LOGTAGPTR),       (ULONG) "cURL",
  TAG_DONE)) {
    
    __request("SocketBaseTags ERROR");
    return FALSE;
  }
  
#ifndef __libnix__
  atexit(amiga_cleanup);
#endif
  
  return TRUE;
}
Example #2
0
int checksocketlib(void)
{
	if(!SocketBase)
	{
		if(SocketBase=OpenLibrary("bsdsocket.library",4))
		{
			/*
			 * Succesfull. Now tell bsdsocket.library:
			 * - the address of our errno
			 * - the address of our h_errno
			 * - our program name
			 */
			SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), &errno,
						   SBTM_SETVAL(SBTC_HERRNOLONGPTR), &h_errno,
						   SBTM_SETVAL(SBTC_LOGTAGPTR), "Python",
						   TAG_END);
		}
		else
		{
			PyErr_SetString(PyExc_SystemError, "Couldn't open bsdsocket.library (start AmiTCP)");
			return 0;
		}
	}
	return 1;
}
Example #3
0
/*
* Actually this doesn't work with Python 1.5.
* You must call it after the interpreter has been initialised.
*/
long _install_AmiTCP_callback(void)
{
  /* needs bsdsocket.library -- I.J. */
  if(checksocketlib())
  {
	if (SocketBaseTags(SBTM_SETVAL(SBTC_FDCALLBACK), &fdCallback, TAG_END)) {
	syslog(LOG_ERR, "Cannot install fdCallback!");

	return 1;
/****
#if __VERSION__ > 6 || __REVISION__ > 3
	return 1;
#else
	exit(20);
#endif
****/
	}
  }
  else
	{
		PyErr_Clear();             /* don't report error if socketlib not found */
	}

  /*
   * Set up __closefunc (which is used at stdio cleanup)
   */
  __closefunc = __close;

  /*
   * Set default file mask to UNIX style
   */
  __fmask = 0644; 

  return 0;
}
Example #4
0
/****** net.lib/syslog *********************************************
*
*   NAME
*       openlog(), closelog(), setlogmask() -- syslog utility functions
*
*   SYNOPSIS
*       #include <syslog.h>
*
*       openlog(ident, logopt, facility);
*
*       void openlog(const char *, int, int);
*
*       closelog();
*
*       void closelog(void);
*
*       oldmask = setlogmask(maskpri);
*
*       int setlogmask(int);
*
*   FUNCTION
*       openlog() can be called to initialize the log file, if special
*       processing is needed.  ident is a string that precedes every
*       message.  logopt is a mask of bits, logically OR'ed together,
*       indicating logging options.  The values for logopt are:
*
*            LOG_PID             Log the process ID with each message;
*                                useful for identifying instantiations
*                                of daemons.
*
*            LOG_CONS            Force writing messages to the console
*                                if unable to send it to syslogd.
*                                This option is safe to use in daemon
*                                processes that have no controlling
*                                terminal because syslog() forks
*                                before opening the console.
*
*            LOG_NDELAY          Open the connection to syslogd
*                                immediately.  Normally, the open is
*                                delayed until the first message is
*                                logged.  This is useful for programs
*                                that need to manage the order in
*                                which file descriptors are allocated.
*
*            LOG_NOWAIT          Do not wait for children forked to
*                                log messages on the console. Obsolete
*                                in AmiTCP/IP, since AmiTCP/IP does
*                                not fork.
*
*       facility encodes a default facility to be assigned to all
*       messages written subsequently by syslog() with no explicit
*       facility encoded. The facility codes are:
*
*            LOG_KERN            Messages generated by the kernel.
*                                These cannot be generated by any user
*                                processes.
*
*            LOG_USER            Messages generated by random user
*                                processes.  This is the default
*                                facility identifier if none is
*                                specified.
*
*            LOG_MAIL            The mail system.
*
*            LOG_DAEMON          System daemons, such as inetd, ftpd,
*                                etc.
*
*            LOG_AUTH            The authorization system: login, su,
*                                getty, etc.
*
*            LOG_LPR             The line printer spooling system: lp,
*                                lpsched, etc.
*
*            LOG_LOCAL0          Reserved for local use. Similarly for
*                                LOG_LOCAL1 through LOG_LOCAL7.
*
*
*       closelog() closes the log file.
*
*       setlogmask() sets the log priority mask to maskpri and returns
*       the previous mask.  Calls to syslog() with a priority not set
*       in maskpri are rejected.  The mask for an individual priority
*       pri is calculated by the macro LOG_MASK(pri); the mask for all
*       priorities up to and including toppri is given by the macro
*       LOG_UPTO(toppri).  By default, all priorities are logged.
*
*   EXAMPLES
*       who logs a message regarding some sort of unexpected and
*       serious error:
*
*           syslog(LOG_ALERT, "who: internal error 23");
*
*       ftpd uses openlog() to arrange to log its process ID, to log
*       to the console if necessary, and to log in the name of the
*       daemon facility:
*
*           openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
*
*       Arrange to log messages only at levels LOG_ERR and lower:
*
*           setlogmask(LOG_UPTO(LOG_ERR));
*
*       Typical usage of syslog() to log a connection:
*
*           syslog(LOG_INFO, "Connection from host %d", CallingHost);
*
*       If the facility has not been set with openlog(), it defaults
*       to LOG_USER.
*
*       Explicitly set the facility for this message:
*
*           syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
*
*   NOTES
*       openlog() does not copy and store the ident string internally;
*       it stores only the character pointer.  Therefore it is the
*       responsibility of the programmer to make sure that the ident
*       argument points to the correct string while syslog() is being
*       called.
*
*   BUGS
*       Most of the logopt and facility codes are currently being
*       ignored by AmiTCP/IP, but they should be used for future
*       compatibility.
*
*       The autoinit module of the net.lib tells the program name
*       to the AmiTCP/IP at program startup, so use of the openlog()
*       for that purpose only is not necessary.
*
*   AUTHOR
*       syslog() was developed by the University of California,
*       Berkeley.
*
*   SEE ALSO
*       bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
*****************************************************************************
*
*/
void
openlog(const char *ident, int logstat, int logfac)
{
    /*
     * Note: SocketBaseTags() does value checking for the arguments
     */
    SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR), ident,
                   SBTM_SETVAL(SBTC_LOGSTAT), logstat,
                   SBTM_SETVAL(SBTC_LOGFACILITY), logfac,
                   TAG_END);
}
Example #5
0
void aros_init_socket(void)
{
  if (!(SocketBase = OpenLibrary("bsdsocket.library", 4))) {
    printf("NoTCP/IP Stack available");
    exit(10);
  }
  if (SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))),
                     (IPTR)&errno,
                     SBTM_SETVAL(SBTC_HERRNOLONGPTR),
                     (IPTR)&h_errno, TAG_DONE)) {
    printf("Failed to set ERRNO");
    exit(10);
  }
}
Example #6
0
static BOOL get_counters(SBQUAD_T *in, SBQUAD_T *out)
{
	BOOL result = TRUE;

	if (SocketBaseTags(
		SBTM_GETREF(SBTC_GET_BYTES_RECEIVED), in,
		SBTM_GETREF(SBTC_GET_BYTES_SENT), out,
		TAG_END)) {

		printf("Could not query data throughput statistics.\n");
		result = FALSE;
	}

	return result;
}
Example #7
0
long tcp_herrno(void)
{
	long id;

#if defined(_DCC) || defined(__MORPHOS__)
	struct TagItem tags[2]={{0, 0}, {TAG_DONE, 0}};
	tags[0].ti_Tag=(ULONG)SBTM_GETREF(SBTC_HERRNO);
	tags[0].ti_Data=(ULONG)&id;

	if(SocketBaseTagList(tags) != 0)
#else
	if(SocketBaseTags(
		SBTM_GETREF(SBTC_HERRNO), (ULONG)&id,
	TAG_DONE) != 0)
#endif
	{
		id = -1;
	}

	return id;
}
Example #8
0
/*
====================
NET_Init
====================
*/
void NET_Init(void)
{
#ifdef _WIN32
	int r;

	r = WSAStartup(MAKEWORD(1, 1), &winsockdata);
	if (r)
	{
		Com_Printf("WARNING: NET_Init: Winsock initialization failed, returned %d\n", r);
		return;
	}

	winsockInitialized = qtrue;
	Com_Printf("Winsock initialized.\n");
#endif
#if defined(__AROS__) || defined(__MORPHOS__)
	SocketBase = OpenLibrary("bsdsocket.library", 0);
	if (!SocketBase)
	{
		Com_Printf("WARNING: NET_Init - Unable to open bsdsocket.library\n");
		return;
	}

	if (SocketBaseTags(SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(errno))), (IPTR)&errno, TAG_DONE))
	{
		CloseLibrary(SocketBase);
		SocketBase = NULL;
		Com_Printf("WARNING: NET_Init - SocketBaseTags failed\n");
		return;
	}
#endif

	NET_Config(qtrue);

	Cmd_AddCommand("net_restart", NET_Restart_f);

	Com_Printf("Network initialized.\n");
}
Example #9
0
void
closelog(void)
{
    SocketBaseTags(SBTM_SETVAL(SBTC_LOGTAGPTR), NULL,
                   TAG_END);
}