Exemplo n.º 1
0
int           TUNTAP_SetMACAddr( char*   pszNetDevName,
                                 char*   pszMACAddr )
{
    struct hifr         hifr;
    struct sockaddr*    addr;
    MAC                 mac;

    memset( &hifr, 0, sizeof( struct hifr ) );

    addr = (struct sockaddr*)&hifr.hifr_hwaddr;

    addr->sa_family = AF_UNIX;

    if( !pszNetDevName || !*pszNetDevName )
    {
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    strcpy( hifr.hifr_name, pszNetDevName );

    if( !pszMACAddr || ParseMAC( pszMACAddr, mac ) != 0 )
    {
        WRMSG( HHC00145, "E", pszNetDevName, pszMACAddr ? pszMACAddr : "NULL" );
            return -1;
    }

    memcpy( addr->sa_data, mac, IFHWADDRLEN );

    return TUNTAP_IOCtl( 0, SIOCSIFHWADDR, (char*)&hifr );
}   // End of function  TUNTAP_SetMACAddr()
Exemplo n.º 2
0
/*-------------------------------------------------------------------*/
static int cardrdr_close_device ( DEVBLK *dev )
{
    /* Close the device file */

    if (0
        || (  dev->bs && dev->fd >=  0   && close_socket( dev->fd ) <  0 )
        || ( !dev->bs && dev->fh != NULL &&    fclose(    dev->fh ) != 0 )
    )
    {
        int errnum = dev->bs ? get_HSO_errno() : errno;
        WRMSG (HHC01200, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "close_socket() or fclose()", strerror(errnum));
        dev->fd = -1;
        dev->fh = NULL;
        return -1;
    }

    if (dev->bs && (dev->bs->clientip || dev->bs->clientname))
    {
        WRMSG (HHC01206, "I", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->bs->clientname, dev->bs->clientip, dev->bs->spec);
    }

    dev->fd = -1;
    dev->fh = NULL;

    return 0;
} /* end function cardrdr_close_device */
Exemplo n.º 3
0
int history_absolute_line(int x) {
  HISTORY *tmp = history_lines_end;
  int lowlimit;
  char buf[80];

  if (history_count == 0) {
    WRMSG(HHC02293, "I", "History empty");
    return -1;
  }

  lowlimit = history_count - HISTORY_MAX;

  if (x > history_count || x <= lowlimit) {
    MSGBUF(buf, "Only commands %d-%d are in history", lowlimit<0? 1 : lowlimit + 1, history_count);
    WRMSG(HHC02293, "I", buf);
    return (-1);
  }

  while (tmp->number != x)
    tmp = tmp->prev;

  copy_to_historyCmdLine(tmp->cmdline);
  history_ptr = NULL;
  return(0);
}
Exemplo n.º 4
0
//
// TUNTAP_SetMTU
//
int             TUNTAP_SetMTU( char*  pszNetDevName,
                               char*  pszMTU )
{
    struct hifr         hifr;
    int                 iMTU;

    if( !pszNetDevName || !*pszNetDevName )
    {
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    if( !pszMTU  || !*pszMTU )
    {
        WRMSG( HHC00144, "E", pszNetDevName, pszMTU ? pszMTU : "NULL" );
        return -1;
    }

    iMTU = atoi( pszMTU );
    if( iMTU < 46 || iMTU > 65536 )
    {
        WRMSG( HHC00144, "E", pszNetDevName, pszMTU );
        return -1;
    }

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));
    hifr.hifr_mtu = iMTU;

    return TUNTAP_IOCtl( 0, SIOCSIFMTU, (char*)&hifr );
}   // End of function  TUNTAP_SetMTU()
Exemplo n.º 5
0
/*-------------------------------------------------------------------*/
static void loglock( ILOCK* ilk, const int rc, const char* calltype,
                                               const char* err_loc )
{
    const char* err_desc;

    switch (rc)
    {
        case EAGAIN:          err_desc = "max recursion";    break;
        case EPERM:           err_desc = "not owned";        break;
        case EINVAL:          err_desc = "invalid argument"; break;
        case EDEADLK:         err_desc = "deadlock";         break;
        case ENOTRECOVERABLE: err_desc = "not recoverable";  break;
        case EOWNERDEAD:      err_desc = "owner dead";       break;
        case EBUSY:           err_desc = "busy";             break; /* (should not occur) */
        case ETIMEDOUT:       err_desc = "timeout";          break; /* (should not occur) */
        default:              err_desc = "(unknown)";        break;
    }

    // "'%s(%s)' failed: rc=%d: %s; tid="TIDPAT", loc=%s"
    WRMSG( HHC90013, "E", calltype, ilk->name, rc, err_desc,
        hthread_self(), TRIMLOC( err_loc ));

    if (ilk->tid)
    {
        // "lock %s was obtained by thread "TIDPAT" at %s"
        WRMSG( HHC90014, "I", ilk->name, ilk->tid, TRIMLOC( ilk->location ));
    }
}
Exemplo n.º 6
0
/* hdl_dchk - dependency check
 */
static int hdl_dchk (char *name, char *version, int size)
{
HDLDEP *depent;

    for(depent = hdl_depend;
      depent && strcmp(name,depent->name);
      depent = depent->next);

    if(depent)
    {
        if(strcmp(version,depent->version))
        {
            WRMSG( HHC01509, "I",name, version, depent->version );
            return -1;
        }

        if(size != depent->size)
        {
            WRMSG( HHC01510, "I", name, size, depent->size );
            return -1;
        }
    }
    else
    {
        hdl_dadd(name,version,size);
    }

    return 0;
}
Exemplo n.º 7
0
DEVTHREADPARMS*  CreateDeviceThread(unsigned short wDevNum)
{
    DEVTHREADPARMS*  pThreadParms;      // ptr to returned device_thread parameters
    DWORD            dwThreadID;        // (work)

    pThreadParms = malloc(sizeof(DEVTHREADPARMS));      // (allocate structure)

    if (!pThreadParms)
    {
        WRMSG ( HHC04111, "E", 0, wDevNum, "malloc(DEVTHREADPARMS)", errno, strerror(errno) );
        return NULL;    // (error)
    }

    pThreadParms->hShutdownEvent = MyCreateEvent(NULL,TRUE,FALSE,NULL);

    if (!pThreadParms->hShutdownEvent)
    {
        WRMSG ( HHC04111, "E", 0, wDevNum, "CreateEvent(hShutdownEvent)", errno, strerror(errno) );
        free(pThreadParms);
        return NULL;    // (error)
    }

    pThreadParms->hRequestQueuedEvent = MyCreateEvent(NULL,TRUE,FALSE,NULL);

    if (!pThreadParms->hRequestQueuedEvent)
    {
        WRMSG ( HHC04111, "E", 0, wDevNum, "CreateEvent(hRequestQueuedEvent)", errno, strerror(errno) );
        MyCloseHandle(pThreadParms->hShutdownEvent);
        free(pThreadParms);
        return NULL;    // (error)
    }

    MyInitializeCriticalSection(&pThreadParms->IORequestListLock);

    InitializeListLink(&pThreadParms->ThreadListLinkingListEntry);
    InitializeListHead(&pThreadParms->IORequestListHeadListEntry);

    pThreadParms->bThreadIsDead = FALSE;
    pThreadParms->dwThreadID = 0;

    if (fthread_create(&dwThreadID,NULL,DeviceThread,pThreadParms,"DeviceThread") != 0)
    {
        WRMSG ( HHC04111, "E", 0, wDevNum, "fthread_create(DeviceThread)", errno, strerror(errno) );
        MyCloseHandle(pThreadParms->hShutdownEvent);
        MyCloseHandle(pThreadParms->hRequestQueuedEvent);
        MyDeleteCriticalSection(&pThreadParms->IORequestListLock);
        free(pThreadParms);
        return NULL;    // (error)
    }

    // Add the newly created device_thread to the end of our list of managed threads.

    InsertListTail(&ThreadListHeadListEntry,&pThreadParms->ThreadListLinkingListEntry);

    if (++ios_devtnbr > ios_devthwm) ios_devthwm = ios_devtnbr;

    LockThreadParms(pThreadParms);  // (lock thread parms before using)

    return pThreadParms;            // (success)
}
Exemplo n.º 8
0
/*
|| Retrieve and validate a standard label
*/
int
get_sl( SLLABEL *lab )
{
    int rc;
    
    /*
    || Read a block
    */
    if ( opts.faketape )
        rc = fet_read( opts.fetb, blkptr );
    else
        rc = het_read( opts.hetb, blkptr );
    if( rc >= 0 )
    {
        /*
        || Does is look like a standard label?
        */
        if( sl_islabel( lab, blkptr, rc ) == TRUE )
        {
            return( 0 );
        }
    }
    else
    {
        if ( opts.faketape )
            WRMSG( HHC00075, "E", "fet_read()", fet_error( rc ) );
        else
            WRMSG( HHC00075, "E", "het_read()", het_error( rc ) );
    }

    return( -1 );
}
Exemplo n.º 9
0
/* hdl_shut - call all shutdown call entries in LIFO order
 */
DLL_EXPORT void hdl_shut (void)
{
HDLSHD *shdent;

    if(MLVL(DEBUG))
        WRMSG( HHC01500, "I" );

    hdl_sdip = TRUE;

    for(shdent = hdl_shdlist; shdent; shdent = hdl_shdlist)
    {
        /* Remove shutdown call entry to ensure it is called once */
        hdl_shdlist = shdent->next;

        {
            if(MLVL(DEBUG))
                WRMSG( HHC01501, "I", shdent->shdname );

            (shdent->shdcall) (shdent->shdarg);

            if(MLVL(DEBUG))
                WRMSG( HHC01502, "I", shdent->shdname );
        }
        free(shdent);
    }

        if(MLVL(DEBUG))
            WRMSG( HHC01504, "I" );
}
Exemplo n.º 10
0
/*-------------------------------------------------------------------*/
int HelpMessage(char *msg)
{
    char *help[][4] = {
        {   HMSG(HHC01415),
            "This message displays the build data and time of the Hercules executables.",
            "Information.",
            "None."
        },

        { NULL, NULL, NULL, NULL }
    };

    int i;
    char id[9];

    strlcpy(id, "HHC",sizeof(id));
    strncpy(&id[3], &msg[3], 5);
    id[8] = 0;

    for(i = 0; help[i][0] && strncmp(help[i][0], id, 8); i++);
    if(help[i][0])
        WRMSG(HHC00017, "I", help[i][0], help[i][1], help[i][2], help[i][3]);
    else
        WRMSG(HHC01607, "I", id);
    return(-1);
}
Exemplo n.º 11
0
/*-------------------------------------------------------------------*/
static void hthread_list_abandoned_locks( TID tid, const char* exit_loc )
{
    ILOCK*       ilk;
    LIST_ENTRY*  ple;

    if (sysblk.shutdown)
        return;

    LockLocksList();
    for (ple = locklist.Flink; ple != &locklist; ple = ple->Flink)
    {
        ilk = CONTAINING_RECORD( ple, ILOCK, locklink );
        if (hthread_equal(ilk->tid,tid))
        {
            char tod[27];           /* "YYYY-MM-DD HH:MM:SS.uuuuuu"  */

            FormatTIMEVAL( &ilk->time, tod, sizeof( tod ));

            if (exit_loc)
            {
                // "Thread "TIDPAT" has abandoned at %s lock %s obtained on %s at %s"
                WRMSG( HHC90016, "E", tid, TRIMLOC( exit_loc ),
                    ilk->name, &tod[11], TRIMLOC( ilk->location ));
            }
            else
            {
                // "Thread "TIDPAT" has abandoned lock %s obtained on %s at %s"
                WRMSG( HHC90015, "E", tid,
                    ilk->name, &tod[11], TRIMLOC( ilk->location ));
            }
        }
    }
    UnlockLocksList();
}
Exemplo n.º 12
0
int           TUNTAP_SetMACAddr( char*  pszNetDevName,
                                 char*  pszMACAddr )
{
    struct hifr         hifr;
    struct sockaddr*    addr;
    MAC                 mac;

    if( !pszNetDevName || !*pszNetDevName )
    {
        // "Invalid net device name %s"
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    if( !pszMACAddr || ParseMAC( pszMACAddr, mac ) != 0 )
    {
        // "Net device %s: Invalid MAC address %s"
        WRMSG( HHC00145, "E", pszNetDevName, pszMACAddr ? pszMACAddr : "NULL" );
        return -1;
    }

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));
    addr = (struct sockaddr*)&hifr.hifr_hwaddr;
    memcpy( addr->sa_data, mac, IFHWADDRLEN );
    addr->sa_family = 1;    // ARPHRD_ETHER

    return TUNTAP_IOCtl( 0, SIOCSIFHWADDR, (char*)&hifr );

}   // End of function  TUNTAP_SetMACAddr()
Exemplo n.º 13
0
int           TUNTAP_SetBCastAddr( char*  pszNetDevName,
                                   char*  pszBCastAddr )
{
    struct hifr         hifr;
    struct sockaddr_in* sin;

    if( !pszNetDevName || !*pszNetDevName )
    {
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));
    sin = (struct sockaddr_in*)&hifr.hifr_broadaddr;
    sin->sin_family = AF_INET;
    set_sockaddr_in_sin_len( sin );

    if( !pszBCastAddr  ||
        !inet_aton( pszBCastAddr, &sin->sin_addr ) )
    {
        WRMSG( HHC00155, "E", pszNetDevName, !pszBCastAddr ? "NULL" : pszBCastAddr );
            return -1;
    }

    return TUNTAP_IOCtl( 0, SIOCSIFBRDADDR, (char*)&hifr );
}   // End of function  TUNTAP_SetBCastAddr()
Exemplo n.º 14
0
static int bufgetc(DEVBLK *dev, int blocking)
{
BYTE *bufp = dev->buf + dev->ctcpos, *bufend = bufp + dev->ctcrem;
int n;

    if (bufp >= bufend) {
        if (blocking == 0) return -1;
        do {
            n = read(dev->fd, dev->buf, dev->bufsize);
            if (n <= 0) {
                if (n == 0) {
                    /* VMnet died on us. */
                    WRMSG (HHC00976, "E", SSID_TO_LCSS(dev->ssid), dev->devnum);
                    /* -2 will cause an error status to be set */
                    return -2;
                }
                if( n == EINTR )
                    return -3;
                WRMSG (HHC00900, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "read()", strerror(errno));
                SLEEP(2);
            }
        } while (n <= 0);
        dev->ctcrem = n;
        bufend = &dev->buf[n];
        dev->ctclastpos = dev->ctclastrem = dev->ctcpos = 0;
        bufp = dev->buf;
    }

    dev->ctcpos++;
    dev->ctcrem--;

    return *bufp;
}
Exemplo n.º 15
0
int           TUNTAP_SetNetMask( char*  pszNetDevName,
                                 char*  pszNetMask )
{
    struct hifr         hifr;
    struct sockaddr_in* sin;

    if( !pszNetDevName || !*pszNetDevName )
    {
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));
    sin = (struct sockaddr_in*)&hifr.hifr_netmask;
    sin->sin_family = AF_INET;
    set_sockaddr_in_sin_len( sin );

    if( !pszNetMask  ||
        !inet_aton( pszNetMask, &sin->sin_addr ) )
    {
        WRMSG( HHC00143, "E", pszNetDevName, !pszNetMask ? "NULL" : pszNetMask );
            return -1;
    }

    return TUNTAP_IOCtl( 0, SIOCSIFNETMASK, (char*)&hifr );
}   // End of function  TUNTAP_SetNetMask()
Exemplo n.º 16
0
/*-------------------------------------------------------------------*/
static void* ptt_timeout( void* arg )
{
    struct timeval  now;
    struct timespec tm;

    UNREFERENCED( arg );

    // "Thread id "TIDPAT", prio %2d, name %s started"
    WRMSG( HHC00100, "I", thread_id(), get_thread_priority(0),"PTT timeout timer");

    hthread_mutex_lock( &ptttolock );

    /* Wait for timeout period to expire */
    gettimeofday( &now, NULL );
    tm.tv_sec = now.tv_sec + pttto;
    tm.tv_nsec = now.tv_usec * 1000;
    hthread_cond_timedwait( &ptttocond, &ptttolock, &tm );

    /* Print the trace table automatically */
    if (hthread_equal( thread_id(), ptttotid ))
    {
        ptt_pthread_print();
        pttto = 0;
        ptttotid = 0;
    }

    hthread_mutex_unlock( &ptttolock );

    // "Thread id "TIDPAT", prio %2d, name %s ended"
    WRMSG( HHC00101, "I", thread_id(), get_thread_priority(0), "PTT timeout timer");

    return NULL;
}
Exemplo n.º 17
0
int           TUNTAP_DelRoute( char*  pszNetDevName,
                               char*  pszDestAddr,
                               char*  pszNetMask,
                               char*  pszGWAddr,
                               int    iFlags )
{
    struct rtentry      rtentry;
    struct sockaddr_in* sin;

    memset( &rtentry, 0, sizeof( struct rtentry ) );

    if( !pszNetDevName || !*pszNetDevName )
    {
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    rtentry.rt_dev = pszNetDevName;

    sin = (struct sockaddr_in*)&rtentry.rt_dst;
    sin->sin_family = AF_INET;
    set_sockaddr_in_sin_len( sin );

    if( !pszDestAddr  ||
        !inet_aton( pszDestAddr, &sin->sin_addr ) )
    {
        WRMSG(HHC00142, "E", pszNetDevName, pszDestAddr ? pszDestAddr : "NULL" );
        return -1;
    }

    sin = (struct sockaddr_in*)&rtentry.rt_genmask;
    sin->sin_family = AF_INET;
    set_sockaddr_in_sin_len( sin );

    if( !pszNetMask  ||
        !inet_aton( pszNetMask, &sin->sin_addr ) )
    {
        WRMSG( HHC00143, "E", pszNetDevName, pszNetMask ? pszNetMask : "NULL" );
        return -1;
    }

    sin = (struct sockaddr_in*)&rtentry.rt_gateway;
    sin->sin_family = AF_INET;
    set_sockaddr_in_sin_len( sin );

    if( pszGWAddr )
    {
        if( !inet_aton( pszGWAddr, &sin->sin_addr ) )
        {
            WRMSG( HHC00146, "E", pszNetDevName, pszGWAddr );
            return -1;
        }
    }

    rtentry.rt_flags = iFlags;

    return TUNTAP_IOCtl( 0, SIOCDELRT, (char*)&rtentry );
}   // End of function  TUNTAP_DelRoute()
Exemplo n.º 18
0
/*-------------------------------------------------------------------*/
int read_omaheaders (DEVBLK *dev, OMATAPE_DESC *omadesc,
                        BYTE *buf, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */
long            blkpos;                 /* Offset to block header    */
S32             curblkl;                /* Length of current block   */
S32             prvhdro;                /* Offset of previous header */
S32             nxthdro;                /* Offset of next header     */

    /* Read the 16-byte block header */
    blkpos = dev->nxtblkpos;
    rc = readhdr_omaheaders (dev, omadesc, blkpos, &curblkl,
                            &prvhdro, &nxthdro, unitstat,code);
    if (rc < 0) return -1;

    /* Update the offsets of the next and previous blocks */
    dev->nxtblkpos = nxthdro;
    dev->prvblkpos = blkpos;

    /* Increment file number and return zero if tapemark */
    if (curblkl == -1)
    {
        close (dev->fd);
        dev->fd = -1;
        dev->curfilen++;
        dev->nxtblkpos = 0;
        dev->prvblkpos = -1;
        return 0;
    }

    /* Read data block from tape file */
    rc = read (dev->fd, buf, curblkl);

    /* Handle read error condition */
    if (rc < 0)
    {
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, omadesc->filename, "oma", "read()", (off_t)blkpos,
                strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }

    /* Handle end of file within data block */
    if (rc < curblkl)
    {
        WRMSG(HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, omadesc->filename, "oma", "read_omaheaders()", (off_t)blkpos, "unexpected end of file");

        /* Set unit check with data check and partial record */
        build_senseX(TAPE_BSENSE_BLOCKSHORT,dev,unitstat,code);
        return -1;
    }

    /* Return block length */
    return curblkl;

} /* end function read_omaheaders */
Exemplo n.º 19
0
/*-------------------------------------------------------------------*/
static void EchoHercCmdLine( const char* cmd )
{
#if defined( OPTION_CMDTGT )
    if (CMDTGT_HERC != sysblk.cmdtgt)
        WRMSG( HHC00013, "I", cmd );    // "Herc command: '%s'"
    else
#endif /* defined( OPTION_CMDTGT ) */
        WRMSG( HHC01603, "I", cmd );    // "%s"
}
Exemplo n.º 20
0
/*-------------------------------------------------------------------*/
int http_startup(int isconfigcalling)
{
    int rc = 0;
    static int first_call = TRUE;

    if ( first_call )
    {
        if ( !http_struct_init )
        {
            memset(&http_serv,0,sizeof(HTTP_SERV));
            initialize_condition( &http_serv.http_wait_shutdown );
            initialize_lock( &http_serv.http_lock_shutdown );
            initialize_lock( &http_lock_root );
            http_struct_init = TRUE;
        }
        first_call = FALSE;
    }

    if ( http_serv.httpport == 0 )
    {
        rc = -1;
    }
    else if ( isconfigcalling )
    {
        if ( !http_serv.httpstmtold )
        {
            rc = 1;
        }
    }

    if ( rc == 0 )
    {
        if ( sysblk.httptid == 0 )
        {
            int rc_ct;

            rc_ct = create_thread (&sysblk.httptid, DETACHED, http_server, NULL, "http_server");
            if ( rc_ct )
            {
                WRMSG(HHC00102, "E", strerror(rc));
                rc = -1;
            }
            else
            {
                WRMSG( HHC01807, "I" );
                rc = 0;
            }
        }
        else
        {
            WRMSG( HHC01806, "W", "already started" );
            rc = 0;
        }
    }

    return rc;
}
Exemplo n.º 21
0
/*---------------------------------------------------------------------------*/
DLL_EXPORT void hao_command(char *cmd)
{
  char work[HAO_WKLEN];
  char work2[HAO_WKLEN];

  /* initialise hao */
  if(!haotid && !hao_initialize())
      WRMSG(HHC01404, "S");

  /* copy and strip spaces */
  hao_cpstrp(work, cmd);

  /* again without starting hao */
  hao_cpstrp(work2, &work[3]);

  if(!strncasecmp(work2, "tgt", 3))
  {
    /* again without starting tgt */
    hao_cpstrp(work, &work2[3]);
    hao_tgt(work);
    return;
  }

  if(!strncasecmp(work2, "cmd", 3))
  {
    /* again without starting cmd */
    hao_cpstrp(work, &work2[3]);
    hao_cmd(work);
    return;
  }

  if(!strncasecmp(work2, "del", 3))
  {
    /* again without starting del */
    hao_cpstrp(work, &work2[3]);
    hao_del(work);
    return;
  }

  if(!strncasecmp(work2, "list", 4))
  {
    /* again without starting list */
    hao_cpstrp(work, &work2[4]);
    hao_list(work);
    return;
  }

  if(!strncasecmp(work2, "clear", 4))
  {
    hao_clear();
    return;
  }

  WRMSG(HHC00070, "E");
}
Exemplo n.º 22
0
/*-------------------------------------------------------------------*/
int cpu_cmd(int argc, char *argv[], char *cmdline)
{
    BYTE    c;
    int     rc      =  0;
    int     cpu     = -1;
    int     currcpu = sysblk.pcpu;
    char    cmd[32768];

    memset(cmd,0,sizeof(cmd));

    if (argc < 2)
    {
        WRMSG(HHC02202, "E", argv[0] );
        return -1;
    }

    if (sscanf(argv[1], "%x%c", &cpu, &c) != 1
     || cpu < 0 || cpu >= sysblk.maxcpu)
    {
        WRMSG(HHC02205, "E", argv[1], ": target processor is invalid" );
        return -1;
    }

    sysblk.dummyregs.cpuad = cpu;
    sysblk.pcpu = cpu;

    strlcpy(cmd,cmdline,sizeof(cmd));

    if ( argc > 2 )
    {
         u_int i = 0;
         u_int j = 0;
         u_int n = (u_int)strlen(cmd);

         /* Skip leading blanks, if any */
         for ( ; i < n && cmd[i] == ' '; i++ );

         /* Skip two words */
         for ( ; j < 2; j++ )
         {
           for ( ; i < n && cmd[i] != ' '; i++ );
           for ( ; i < n && cmd[i] == ' '; i++ );
         }

         /* Issue command to temporary target cpu */
         if (i < n)
         {
             rc = HercCmdLine(cmd+i);
             sysblk.pcpu = currcpu;
             sysblk.dummyregs.cpuad = currcpu;
         }
    }

    return rc;
}
Exemplo n.º 23
0
/*-------------------------------------------------------------------*/
int readhdr_awstape (DEVBLK *dev, off_t blkpos,
                     AWSTAPE_BLKHDR *buf, BYTE *unitstat,BYTE code)
{
int             rc;                     /* Return code               */
off_t           rcoff;                  /* Return code from lseek()  */

    /* Reposition file to the requested block header */
    rcoff = lseek (dev->fd, blkpos, SEEK_SET);
    if (rcoff < 0)
    {
        /* Handle seek error condition */
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "aws", "lseek()", blkpos, strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_LOCATEERR,dev,unitstat,code);
        return -1;
    }

    /* Read the 6-byte block header */
    rc = read (dev->fd, buf, sizeof(AWSTAPE_BLKHDR));

    /* Handle read error condition */
    if (rc < 0)
    {
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "aws", "read()", blkpos, strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }

    /* Handle end of file (uninitialized tape) condition */
    if (rc == 0)
    {
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "aws", "readhdr_awstape()", blkpos, "end of file (uninitialized tape)");

        /* Set unit exception with tape indicate (end of tape) */
        build_senseX(TAPE_BSENSE_EMPTYTAPE,dev,unitstat,code);
        return -1;
    }

    /* Handle end of file within block header */
    if (rc < (int)sizeof(AWSTAPE_BLKHDR))
    {
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, dev->filename, "aws", "readhdr_awstape()", blkpos, "unexpected end of file");

        build_senseX(TAPE_BSENSE_BLOCKSHORT,dev,unitstat,code);
        return -1;
    }

    /* Successful return */
    return 0;

} /* end function readhdr_awstape */
Exemplo n.º 24
0
/*-------------------------------------------------------------------*/
int read_omafixed (DEVBLK *dev, OMATAPE_DESC *omadesc,
                        BYTE *buf, BYTE *unitstat,BYTE code)
{
off_t           rcoff;                  /* Return code from lseek()  */
int             blklen;                 /* Block length              */
long            blkpos;                 /* Offset of block in file   */

    /* Initialize current block position */
    blkpos = dev->nxtblkpos;

    /* Seek to new current block position */
    rcoff = lseek (dev->fd, blkpos, SEEK_SET);
    if (rcoff < 0)
    {
        /* Handle seek error condition */
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, omadesc->filename, "oma", "lseek()", (off_t)blkpos, strerror(errno));

        /* Set unit check with equipment check */
        build_senseX(TAPE_BSENSE_LOCATEERR,dev,unitstat,code);
        return -1;
    }

    /* Read fixed length block or short final block */
    blklen = read (dev->fd, buf, omadesc->blklen);

    /* Handle read error condition */
    if (blklen < 0)
    {
        WRMSG (HHC00204, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, omadesc->filename, "oma", "read()", (off_t)blkpos,
                strerror(errno));

        build_senseX(TAPE_BSENSE_READFAIL,dev,unitstat,code);
        return -1;
    }

    /* At end of file return zero to indicate tapemark */
    if (blklen == 0)
    {
        close (dev->fd);
        dev->fd = -1;
        dev->curfilen++;
        dev->nxtblkpos = 0;
        dev->prvblkpos = -1;
        return 0;
    }

    /* Calculate the offsets of the next and previous blocks */
    dev->nxtblkpos = blkpos + blklen;
    dev->prvblkpos = blkpos;

    /* Return block length, or zero to indicate tapemark */
    return blklen;

} /* end function read_omafixed */
Exemplo n.º 25
0
/*-------------------------------------------------------------------*/
static int start_vmnet(DEVBLK *dev, DEVBLK *xdev, int argc, char *argv[])
{
int sockfd[2];
int r, i;
char *ipaddress;

    if (argc < 2) {
        WRMSG (HHC00915, "E", SSID_TO_LCSS(dev->ssid), dev->devnum);
        return -1;
    }

    ipaddress = argv[0];
    argc--;
    argv++;

    if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockfd) < 0) {
        WRMSG (HHC00900, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "socketpair()", strerror(errno));
        return -1;
    }

    r = fork ();

    if (r < 0) {
        WRMSG (HHC00900, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "fork()", strerror(errno));
        return -1;
    } else if (r == 0) {
        /* child */
        close (0);
        close (1);
        dup (sockfd[1]);
        dup (sockfd[1]);
        r = (sockfd[0] > sockfd[1]) ? sockfd[0] : sockfd[1];
        for (i = 3; i <= r; i++) {
            close (i);
        }

        /* the ugly cast is to silence a compiler warning due to const */
        execv (argv[0], (EXECV_ARG2_ARGV_T)argv);

        exit (1);
    }

    close (sockfd[1]);
    dev->fd = sockfd[0];
    xdev->fd = sockfd[0];

    /* We just blindly copy these out in the hope vmnet will pick them
     * up correctly.  I don't feel like implementing a complete login
     * scripting facility here...
     */
    write(dev->fd, ipaddress, (u_int)strlen(ipaddress));
    write(dev->fd, "\n", 1);
    return 0;
}
Exemplo n.º 26
0
static int VMNET_Write(DEVBLK *dev, BYTE *iobuf, U32 count, BYTE *unitstat)
{
U32 blklen = (iobuf[0]<<8) | iobuf[1];
U32 pktlen;
BYTE *p = iobuf + 2;
BYTE *buffer = dev->buf;
U32 len = 0, rem;

    if (count < blklen) {
        WRMSG (HHC00975, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "block", count, blklen);
        blklen = count;
    }
    while (p < iobuf + blklen) {
        pktlen = (p[0]<<8) | p[1];

        rem = iobuf + blklen - p;

        if (rem < pktlen) {
            WRMSG (HHC00975, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "packet", rem, pktlen);
            pktlen = rem;
        }
        if (pktlen < 6) {
        WRMSG (HHC00975, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "packet", pktlen, 6);
            pktlen = 6;
        }

        pktlen -= 6;
        p += 6;

        while (pktlen--) {
            switch (*p) {
            case SLIP_END:
                buffer[len++] = SLIP_ESC;
                buffer[len++] = SLIP_ESC_END;
                break;
            case SLIP_ESC:
                buffer[len++] = SLIP_ESC;
                buffer[len++] = SLIP_ESC_ESC;
                break;
            default:
                buffer[len++] = *p;
                break;
            }
            p++;
        }
        buffer[len++] = SLIP_END;
        write(dev->fd, buffer, len);   /* should check error conditions? */
        len = 0;
    }

    *unitstat = CSW_CE | CSW_DE;

    return count;
}
Exemplo n.º 27
0
//
// TUNTAP_GetMACAddr
//
int           TUNTAP_GetMACAddr( char*   pszNetDevName,
                                 char**  ppszMACAddr )
{
#if defined(OPTION_TUNTAP_GETMACADDR)
    struct hifr         hifr;
    struct sockaddr*    addr;
    int                 rc;

    if( !pszNetDevName || !*pszNetDevName )
    {
        // "Invalid net device name %s"
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    if( !ppszMACAddr )
    {
        // HHC00136 "Error in function %s: %s"
        WRMSG(HHC00136, "E", "TUNTAP_GetMACAddr", "Invalid parameters" );
        return -1;
    }

    *ppszMACAddr = NULL;

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));
    addr = (struct sockaddr*)&hifr.hifr_hwaddr;
    addr->sa_family = 1;    // ARPHRD_ETHER

#if defined( OPTION_W32_CTCI )
    rc = TUNTAP_IOCtl( 0, SIOCGIFHWADDR, (char*)&hifr );
#else // (non-Win32 platforms)
    {
        int sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
        rc = ioctl( sockfd, SIOCGIFHWADDR, &hifr );
        close( sockfd );
    }
#endif
    if( rc < 0 )
    {
        // HHC00136 "Error in function %s: %s"
        WRMSG( HHC00136, "E", "TUNTAP_GetMACAddr", strerror( errno ));
        return -1;
    }

    return FormatMAC( ppszMACAddr, (BYTE*) addr->sa_data );
#else // defined(OPTION_TUNTAP_GETMACADDR)
    UNREFERENCED(pszNetDevName);
    UNREFERENCED(ppszMACAddr);
    WRMSG(HHC00136, "E", "TUNTAP_GetMACAddr", "Unsupported" );
    return -1; // (unsupported)
#endif // defined(OPTION_TUNTAP_GETMACADDR)
}   // End of function  TUNTAP_GetMACAddr()
Exemplo n.º 28
0
static int VMNET_Init(DEVBLK *dev, int argc, char *argv[])
{
U16             xdevnum;                /* Pair device devnum        */
DEVBLK          *xdev;                  /* Pair device               */
int rc;
U16 lcss;

    dev->devtype = 0x3088;

    dev->excps = 0;

    /* parameters for network CTC are:
     *    devnum of the other CTC device of the pair
     *    ipaddress
     *    vmnet command line
     *
     * CTC adapters are used in pairs, one for READ, one for WRITE.
     * The vmnet is only initialised when both are initialised.
     */
    if (argc < 3) {
        WRMSG(HHC00915, "E", SSID_TO_LCSS(dev->ssid), dev->devnum);
        return -1;
    }
    rc=parse_single_devnum(argv[0],&lcss,&xdevnum);
    if (rc<0)
    {
        WRMSG(HHC00916, "E", SSID_TO_LCSS(dev->ssid), dev->devnum, "device number", argv[0]);
        return -1;
    }
    xdev = find_device_by_devnum(lcss,xdevnum);
    if (xdev != NULL) {
        if (start_vmnet(dev, xdev, argc - 1, &argv[1]))
            return -1;
    }
    strlcpy(dev->filename, "vmnet", sizeof(dev->filename) );

    /* Set the control unit type */
    /* Linux/390 currently only supports 3088 model 2 CTCA and ESCON */
    dev->ctctype = CTC_VMNET;

    SetSIDInfo( dev, 0x3088, 0x08, 0x3088, 0x01 );

    /* Initialize the device dependent fields */
    dev->ctcpos = 0;
    dev->ctcrem = 0;

    /* Set length of buffer */
    /* This size guarantees we can write a full iobuf of 65536
     * as a SLIP packet in a single write.  Probably overkill... */
    dev->bufsize = 65536 * 2 + 1;
    return 0;
}
Exemplo n.º 29
0
//
// TUNTAP_GetMTU
//
int             TUNTAP_GetMTU( char*   pszNetDevName,
                               char**  ppszMTU )
{
    struct hifr         hifr;
    int                 rc;
    char                szMTU[8] = {0};

    if( !pszNetDevName || !*pszNetDevName )
    {
        // "Invalid net device name %s"
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    if( !ppszMTU )
    {
        // HHC00136 "Error in function %s: %s"
        WRMSG(HHC00136, "E", "TUNTAP_GetMTU", "Invalid parameters" );
        return -1;
    }

    *ppszMTU = NULL;

    memset( &hifr, 0, sizeof( struct hifr ) );
    strlcpy( hifr.hifr_name, pszNetDevName, sizeof(hifr.hifr_name));

#if defined( OPTION_W32_CTCI )
    rc = TUNTAP_IOCtl( 0, SIOCGIFMTU, (char*)&hifr );
#else // (non-Win32 platforms)
    {
        int sockfd = socket( AF_INET, SOCK_DGRAM, 0 );
        rc = ioctl( sockfd, SIOCGIFMTU, &hifr );
        close( sockfd );
    }
#endif
    if( rc < 0 )
    {
        // HHC00136 "Error in function %s: %s"
        WRMSG( HHC00136, "E", "TUNTAP_GetMTU", strerror( errno ));
        return -1;
    }

    MSGBUF( szMTU, "%u", hifr.hifr_mtu );
    if (!(*ppszMTU = strdup( szMTU )))
    {
        errno = ENOMEM;
        return -1;
    }

    return 0;
}   // End of function  TUNTAP_GetMTU()
Exemplo n.º 30
0
int             TUNTAP_SetIPAddr6( char*   pszNetDevName,
                                   char*   pszIPAddr6,
                                   char*   pszPrefixSize6 )
{
    struct hifr         hifr;
    int                 iPfxSiz;

    memset( &hifr, 0, sizeof( struct hifr ) );

    if( !pszNetDevName || !*pszNetDevName )
    {
        WRMSG( HHC00140, "E", pszNetDevName ? pszNetDevName : "NULL" );
        return -1;
    }

    strcpy( hifr.hifr_name, pszNetDevName );

    if( !pszIPAddr6 )
    {
        WRMSG( HHC00141, "E", pszNetDevName, "NULL" );
        return -1;
    }

    if( hinet_pton( AF_INET6, pszIPAddr6, &hifr.hifr6_addr ) != 1 )
    {
        WRMSG( HHC00141, "E", pszNetDevName, pszIPAddr6 );
        return -1;
    }

    if( !pszPrefixSize6 )
    {
        WRMSG(HHC00153, "E", pszNetDevName, "NULL" );
        return -1;
    }

    iPfxSiz = atoi( pszPrefixSize6 );

    if( iPfxSiz < 0 || iPfxSiz > 128 )
    {
        WRMSG(HHC00153, "E", pszNetDevName, pszPrefixSize6 );
        return -1;
    }

    hifr.hifr6_prefixlen = iPfxSiz;

    hifr.hifr6_ifindex = hif_nametoindex( pszNetDevName );

    hifr.hifr_afamily = AF_INET6;

    return TUNTAP_IOCtl( 0, SIOCSIFADDR, (char*)&hifr );
}   // End of function  TUNTAP_SetIPAddr6()