Exemplo n.º 1
0
/* TODO: fix me */
int release_socket(int s)
{ struct SocketSettings *lss;
  /* TODO: Finish me */
  /* dup the socket first, since for AmiTCP, we can only release once */
  int s2 = dup(s);
  /*StdFileDes *fp = _lx_fhfromfd(s);*/
  int rc = -1;

  if (s2 >= 0) {
    switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
      case LX_AS225:
        rc = (int)SOCK_release(s2);
        SOCK_close(s2);
      break;

      case LX_AMITCP:
        rc = TCP_ReleaseSocket(s2, -1);
        TCP_CloseSocket(s2);
      break;

      default:
        /* silence compiler */
      break;
    }
  }

  return rc;
}
Exemplo n.º 2
0
void sethostent(int stayopen)
{ struct SocketSettings *lss = _lx_get_socket_settings();

  if (lss->lx_network_type == LX_AS225) {
    SOCK_sethostent(stayopen);
  }
  else if (stayopen && lss->lx_res) {
    lss->lx_res->options |= RES_STAYOPEN | RES_USEVC;
  }
}
Exemplo n.º 3
0
void endhostent(void)
{ struct SocketSettings *lss = _lx_get_socket_settings();

  if (lss->lx_network_type == LX_AS225) {
    SOCK_endhostent();
  }
  else if (lss->lx_res) {
    lss->lx_res->options &= ~(RES_STAYOPEN | RES_USEVC);
    if (*lss->lx_res_socket >= 0) {
      close(*lss->lx_res_socket); *lss->lx_res_socket = -1;
    }
  }
}
Exemplo n.º 4
0
struct netent *getnetbyname(const char *name)
{ struct SocketSettings *lss;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      return SOCK_getnetbyname(name);

    case LX_AMITCP:
      return TCP_GetNetByName(name);

    default:
      return NULL;
  }
}
Exemplo n.º 5
0
struct servent *getservbyport(int port, const char *proto)
{ struct SocketSettings *lss = _lx_get_socket_settings();

  switch (lss->lx_network_type) {
    case LX_AS225:
      return SOCK_getservbyport(port,proto);

    case LX_AMITCP:
      return TCP_GetServByPort(port,proto);

    default:
      return NULL;
  }
}
Exemplo n.º 6
0
struct hostent *gethostbyaddr(const char *addr, int len, int type)
{ struct SocketSettings *lss;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      return SOCK_gethostbyaddr(addr,len,type);

    case LX_AMITCP:
      return TCP_GetHostByAddr(addr,len,type);

    default:
      return NULL;
  }    
}
Exemplo n.º 7
0
static int _sock_select(StdFileDes *fp,int select_cmd,int io_mode,fd_set *set,u_long *nfds)
{ struct SocketSettings *lss = _lx_get_socket_settings();
  
  if (select_cmd == SELCMD_PREPARE) {
    FD_SET(fp->lx_sock, set);
    if (fp->lx_sock > *nfds)
      *nfds = fp->lx_sock;
    return (1L << lss->lx_sigurg | 1L << lss->lx_sigio);
  }

  if (select_cmd == SELCMD_CHECK)
    return FD_ISSET(fp->lx_sock, set);

  if (select_cmd == SELCMD_POLL)
    return _sock_poll(fp, io_mode, lss);

  return 0;
}
Exemplo n.º 8
0
int recvmsg(int s, struct msghdr *msg, int flags)
{ struct SocketSettings *lss;
  StdFileDes *fp = _lx_fhfromfd(s);
  int rc;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      rc = SOCK_recvmsg(fp->lx_sock,msg,flags);
    break;

    case LX_AMITCP:
      rc = TCP_RecvMsg(fp->lx_sock,msg,flags);
    break;

    default:
      rc = -1;
    break;
  }

  return rc;
}
Exemplo n.º 9
0
int getsockopt(int s, int level, int name, void *val, int *valsize)
{ struct SocketSettings *lss;
  StdFileDes *fp = _lx_fhfromfd(s);
  int rc;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      rc = SOCK_getsockopt(fp->lx_sock,level,name,val, valsize);
    break;

    case LX_AMITCP:
      rc = TCP_GetSockOpt(fp->lx_sock,level,name,val, valsize);
    break;

    default:
      rc = 0;
    break;
  }

  return rc;
}
Exemplo n.º 10
0
static int _sock_close(StdFileDes *fp)
{ struct SocketSettings *lss;
  int rc;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {

    case LX_AS225:
      rc = SOCK_close(fp->lx_sock);
    break;

    case LX_AMITCP:
      rc = TCP_CloseSocket(fp->lx_sock);
    break;

    default:
      rc = 0;
    break;
  }

  return rc;
}
Exemplo n.º 11
0
int getpeername(int s, struct sockaddr *asa, int *alen)
{ struct SocketSettings *lss;
  StdFileDes *fp = _lx_fhfromfd(s);
  int rc;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      rc = SOCK_getpeername(fp->lx_sock,asa,alen);
    break;

    case LX_AMITCP:
      rc = TCP_GetPeerName(fp->lx_sock,asa,alen);
    break;

    default:
      rc = -1;
    break;
  }

  return rc;
}
Exemplo n.º 12
0
int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, int *fromlen)
{ struct SocketSettings *lss;
  StdFileDes *fp = _lx_fhfromfd(s);
  int rc;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      rc = SOCK_recvfrom(fp->lx_sock,buf,len,flags, from, fromlen);
    break;

    case LX_AMITCP:
      rc = TCP_RecvFrom(fp->lx_sock,buf,len,flags, from, fromlen);
    break;

    default:
      rc = -1;
    break;
  }

  return rc;
}
Exemplo n.º 13
0
void setnetent(int stayopen)
{ struct SocketSettings *lss;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      SOCK_setnetent(stayopen);
    break;

    case LX_AMITCP:
      if (!lss->lx_net_fp)
        lss->lx_net_fp = fopen(TCP_PATH_NETWORKS, "r");
      else
        rewind(lss->lx_net_fp);
      lss->lx_net_stayopen = stayopen;
    break;

    default:
      /* silence compiler */
    break;
  }
}
Exemplo n.º 14
0
int shutdown(int s, int how)
{ struct SocketSettings *lss;
  StdFileDes *fp = _lx_fhfromfd(s);
  int rc;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      rc = SOCK_shutdown(fp->lx_sock,how);
    break;

    case LX_AMITCP:
      rc = TCP_ShutDown(fp->lx_sock,how);
    break;

    default:
      rc = 0;
    break;
  }

  return rc;
}
Exemplo n.º 15
0
int listen(int s, int backlog)
{ struct SocketSettings *lss;
  register StdFileDes *fp;
  int rc;

  if ((fp=_lx_fhfromfd(s))) {
    switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
      case LX_AS225:
        rc = SOCK_listen(fp->lx_sock, backlog);
      break;

      case LX_AMITCP:
        rc = TCP_Listen(fp->lx_sock, backlog);
      break;

      default:
        rc = -1;
      break;
    }
  }
  else rc = -1;

  return rc;
}
Exemplo n.º 16
0
void endnetent(void)
{ struct SocketSettings *lss;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      SOCK_endnetent();
    break;

    default:
      lss->lx_net_stayopen = 0;
      if (lss->lx_net_fp) {
        fclose(lss->lx_net_fp); lss->lx_net_fp = NULL;
      }
#if 0
      if (lss->lx_net_aliases) {
        free(lss->lx_net_aliases); lss->lx_net_aliases = NULL;
      }
      if (lss->lx_net_line) {
        free(lss->lx_net_line); lss->lx_net_line = NULL;
      }
#endif
    break;
  }
}
Exemplo n.º 17
0
static int _sock_dup(StdFileDes *fp)
{ struct SocketSettings *lss;
  StdFileDes *fp2;
  int rc;

  if ((fp2=_create_socket(fp->lx_family, fp->lx_domain, fp->lx_protocol)) == NULL)
    return -1;

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {

    case LX_AS225:
      /* only INET-225 has dup */
      if (lss->lx_SocketBase->lib_Version >= 8)
        rc = SOCK_dup(fp->lx_sock);
      else
        rc = fp->lx_sock;
    break;

    case LX_AMITCP:
      rc = TCP_Dup2Socket(fp->lx_sock, -1);
    break;

    default:
      rc = -1;
    break;
  }

  if (rc >= 0) {
    fp2->lx_sock = rc; rc = fp2->lx_pos;
  }
  else {
    fp2->lx_inuse = 0;
  }

  return rc;
}
Exemplo n.º 18
0
int ioctl(int s, unsigned long cmd, ...)
{ struct SocketSettings *lss;
  StdFileDes *fp = _lx_fhfromfd(s);
  int arglen,inout,rc;
  caddr_t data;
  va_list va;

  if (fp->lx_type == LX_FILE) {
    errno = EBADF; return -1;
  }
  
  va_start(va, cmd);
  inout = va_arg(va, int);
  arglen = va_arg(va, int);
  data = va_arg(va, caddr_t);
  va_end(va);

  switch (lss=_lx_get_socket_settings(),lss->lx_network_type) {

    case LX_AS225:

      /* _SIGH_... they left almost everything neatly as it was in the BSD kernel
       *  code they used, but for whatever reason they decided they needed their
       *  own kind of ioctl encoding :-((
       *
       *  Well then, here we go, and map `normal' cmds into CBM cmds:
       */

      switch (cmd) {
        case SIOCADDRT      : cmd = ('r'<<8)|1; break;
        case SIOCDELRT      : cmd = ('r'<<8)|2; break;
        case SIOCSIFADDR    : cmd = ('i'<<8)|3; break;
        case SIOCGIFADDR    : cmd = ('i'<<8)|4; break;
        case SIOCSIFDSTADDR : cmd = ('i'<<8)|5; break;
        case SIOCGIFDSTADDR : cmd = ('i'<<8)|6; break;
        case SIOCSIFFLAGS   : cmd = ('i'<<8)|7; break;
        case SIOCGIFFLAGS   : cmd = ('i'<<8)|8; break;
        case SIOCGIFCONF    : cmd = ('i'<<8)|9; break;
        case SIOCSIFMTU     : cmd = ('i'<<8)|10; break;
        case SIOCGIFMTU     : cmd = ('i'<<8)|11; break;
        case SIOCGIFBRDADDR : cmd = ('i'<<8)|12; break;
        case SIOCSIFBRDADDR : cmd = ('i'<<8)|13; break;
        case SIOCGIFNETMASK : cmd = ('i'<<8)|14; break;
        case SIOCSIFNETMASK : cmd = ('i'<<8)|15; break;
        case SIOCGIFMETRIC  : cmd = ('i'<<8)|16; break;
        case SIOCSIFMETRIC  : cmd = ('i'<<8)|17; break;
        case SIOCSARP       : cmd = ('i'<<8)|18; break;
        case SIOCGARP       : cmd = ('i'<<8)|19; break;
        case SIOCDARP       : cmd = ('i'<<8)|20; break;
        case SIOCATMARK     : cmd = ('i'<<8)|21; break;
        case FIONBIO        : cmd = ('m'<<8)|22; break;
        case FIONREAD       : cmd = ('m'<<8)|23; break;
        case FIOASYNC       : cmd = ('m'<<8)|24; break;
        case SIOCSPGRP      : cmd = ('m'<<8)|25; break;
        case SIOCGPGRP      : cmd = ('m'<<8)|26; break;

        default:
        /* we really don't have to bother the library with cmds we can't even
         * map over...
         */
	break;
      }
      rc = SOCK_ioctl(fp->lx_sock,cmd,data);
    break;

    case LX_AMITCP:
      rc = TCP_IoctlSocket(fp->lx_sock,cmd,data);
    break;

    default:
      rc = 0;
    break;
  }

  return rc;
}
Exemplo n.º 19
0
struct netent *getnetent(void)
{ struct SocketSettings *lss;

  switch(lss=_lx_get_socket_settings(),lss->lx_network_type) {
    case LX_AS225:
      return SOCK_getnetent();
    break;
	
    case LX_AMITCP:

      if (!lss->lx_net_line)
        lss->lx_net_line = malloc(BUFSIZ + 1);

      if (!lss->lx_net_aliases)
        lss->lx_net_aliases = malloc(MAXALIASES * sizeof(char *));

      if (!lss->lx_net_line || !lss->lx_net_aliases) {
        errno = ENOMEM; return NULL;
      }

      if (lss->lx_net_fp || (lss->lx_net_fp=fopen(TCP_PATH_NETWORKS, "r"))) {
        for(;;) {
          char *s, *cp, **q;

          if ((s=fgets(lss->lx_net_line, BUFSIZ, lss->lx_net_fp)) == NULL)
            break;

          if ((*s == '#') || ((cp=strpbrk(s, "#\n")) == NULL))
            continue;
          *cp = '\0';
          lss->lx_net.n_name = s;

          if ((cp=strpbrk(s, " \t")) == NULL)
            continue;
          *cp++ = '\0';
          while (*cp == ' ' || *cp == '\t')
            cp++;
          if ((s=strpbrk(cp, " \t")))
            *s++ = '\0';
          lss->lx_net.n_net = inet_network(cp);
          lss->lx_net.n_addrtype = AF_INET;

          q = lss->lx_net.n_aliases = lss->lx_net_aliases;
          if ((cp=s)) {
            while (cp && *cp) {
              if (*cp == ' ' || *cp == '\t') {
                cp++; continue;
              }
              if (q < &lss->lx_net_aliases[MAXALIASES - 1])
                *q++ = cp;
              if ((cp=strpbrk(cp, " \t")))
                *cp++ = '\0';
            }
          }
          *q = NULL; return &lss->lx_net;
        }
      }

      /* fall through */

    default:
      return NULL;
    break;
  }
}