EIBNetIPTunnel::EIBNetIPTunnel (const char *dest, int port, int sport,
				const char *srcip, int Dataport, int flags,
				Trace * tr)
{
  t = tr;
  TRACEPRINTF (t, 2, this, "Open");
  pth_sem_init (&insignal);
  pth_sem_init (&outsignal);
  getwait = pth_event (PTH_EVENT_SEM, &outsignal);
  noqueue = flags & FLAG_B_TUNNEL_NOQUEUE;
  sock = 0;
  if (!GetHostIP (&caddr, dest))
    return;
  caddr.sin_port = htons (port);
  if (!GetSourceAddress (&caddr, &raddr))
    return;
  raddr.sin_port = htons (sport);
  NAT = false;
  dataport = Dataport;
  sock = new EIBNetIPSocket (raddr, 0, t);
  if (!sock->init ())
    {
      delete sock;
      sock = 0;
      return;
    }
  if (srcip)
    {
      if (!GetHostIP (&saddr, srcip))
	{
	  delete sock;
	  sock = 0;
	  return;
	}
      saddr.sin_port = htons (sport);
      NAT = true;
    }
  else
    saddr = raddr;
  sock->sendaddr = caddr;
  sock->recvaddr = caddr;
  sock->recvall = 0;
  mode = 0;
  vmode = 0;
  support_busmonitor = 1;
  connect_busmonitor = 0;
  Start ();
  TRACEPRINTF (t, 2, this, "Opened");
}
static int32_t Lab16(void){uint32_t i;
  char *pt = NULL;

  memcpy(appData.HostName,SERVER,strlen(SERVER));
  if(GetHostIP() == 0){
    if( (appData.SockID = CreateConnection()) < 0 ) return -1;

/* HTTP GET string. */
    strcpy(appData.SendBuff,REQUEST); 
// 1) change Austin Texas to your city
// 2) you can change metric to imperial if you want temperature in F
    /* Send the HTTP GET string to the open TCP/IP socket. */
    sl_Send(appData.SockID, appData.SendBuff, strlen(appData.SendBuff), 0);

/* Receive response */
    sl_Recv(appData.SockID, &appData.Recvbuff[0], MAX_RECV_BUFF_SIZE, 0);
    appData.Recvbuff[strlen(appData.Recvbuff)] = '\0';

/* find ticker name in response*/
    pt = strstr(appData.Recvbuff, "id");
    i = 0; 
    if( NULL != pt ){
      pt = pt + 5; // skip over id":"
      while((i<MAXLEN)&&(*pt)&&(*pt!='\"')){
        Id[i] = *pt; // copy into Id string
        pt++; i++;    
      }
    }
    Id[i] = 0;

/* find score Value in response */
    pt = strstr(appData.Recvbuff, "\"score\"");
    i = 0; 
    if( NULL != pt ){
      pt = pt + 8; // skip over "score":
      while((i<MAXLEN)&&(*pt)&&(*pt!=',')){
        Score[i] = *pt; // copy into Score string
        pt++; i++;    
      }
    }
    Score[i] = 0;

/* find edxpost in response */
    pt = strstr(appData.Recvbuff, "edxpost");
    i = 0; 
    if( NULL != pt ){
      pt = pt + 9; // skip over edxpost":
      for(i=0; i<8; i++){
        Edxpost[i] = *pt; // copy into Edxpost string
        pt++;     
      }
    }
    Edxpost[i] = 0;
    
    sl_Close(appData.SockID);
  }

  return 0;
}
Beispiel #3
0
BOOL SocksParser::TCPResponse( SERVICE_INFO& svc )
{
		/*
		  +----+-----+-------+------+----------+----------+
		|VER | REP |  RSV  | ATYP | BND.ADDR | BND.gListenSocket |
		+----+-----+-------+------+----------+----------+
		| 1  |  1  | X'00' |  1   | Variable |    2     |
		+----+-----+-------+------+----------+----------+
		*/
		char buffer[1024];
		int nAddrSize = sizeof(sockaddr);

		buffer[0] = 0x05;
		buffer[1] = 0x00;
		buffer[2] = 0x00;
		buffer[3] = 0x01;
		GetHostIP(buffer+4);
		m_socket++;
		svc.sq = m_socket;
		buffer[8] = svc.sq/256;
		buffer[9] = svc.sq%256;

		SendBuf(svc.socket,buffer,10);

		BOOL ret = FALSE;

		do 
		{
			if (svc.type == SOCKS_CONNECT)
			{
				if(!Socket::Connect(svc.sremote,svc.saddr))
				{
					Socket::Close(svc.sremote);
					break;
				}
			}
			if (svc.type == SOCKS_BIND)
			{
				svc.sremote = Socket::Accept(svc.slocal,(sockaddr*)&svc.caddr);
				if (svc.sremote == SOCKET_ERROR)
				{
					Socket::Close(svc.slocal);
					break;
				}
				break;
			}

			ret = TRUE;

		} while (FALSE);

		return ret;
}
Beispiel #4
0
void
EIBNetIPRouter::start()
{
  struct sockaddr_in baddr;
  struct ip_mreq mcfg;
  TRACEPRINTF (t, 2, "Open");
  memset (&baddr, 0, sizeof (baddr));
#ifdef HAVE_SOCKADDR_IN_LEN
  baddr.sin_len = sizeof (baddr);
#endif
  baddr.sin_family = AF_INET;
  baddr.sin_port = htons (port);
  baddr.sin_addr.s_addr = htonl (INADDR_ANY);
  sock = new EIBNetIPSocket (baddr, 1, t);
  if (!sock->init ())
    goto err_out;
  sock->on_recv.set<EIBNetIPRouter,&EIBNetIPRouter::read_cb>(this);

  if (! sock->SetInterface(interface))
    {
      ERRORPRINTF (t, E_ERROR | 58, "interface %s not recognized", interface);
      goto err_out;
    }

  sock->recvall = 2;
  if (GetHostIP (t, &sock->sendaddr, multicastaddr) == 0)
    goto err_out;
  sock->sendaddr.sin_port = htons (port);
  if (!GetSourceAddress (t, &sock->sendaddr, &sock->localaddr))
    goto err_out;
  sock->localaddr.sin_port = sock->sendaddr.sin_port;

  mcfg.imr_multiaddr = sock->sendaddr.sin_addr;
  mcfg.imr_interface.s_addr = htonl (INADDR_ANY);
  if (!sock->SetMulticast (mcfg))
    goto err_out;
  TRACEPRINTF (t, 2, "Opened");
  BusDriver::start();
  return;

err_out:
  delete sock;
  sock = 0;
  stopped();
}
Beispiel #5
0
EIBNetIPRouter::EIBNetIPRouter (const char *multicastaddr, int port,
				eibaddr_t a UNUSED, Layer3 * l3, L2options *opt) : Layer2 (l3, opt)
{
  struct sockaddr_in baddr;
  struct ip_mreq mcfg;
  TRACEPRINTF (t, 2, this, "Open");
  memset (&baddr, 0, sizeof (baddr));
#ifdef HAVE_SOCKADDR_IN_LEN
  baddr.sin_len = sizeof (baddr);
#endif
  baddr.sin_family = AF_INET;
  baddr.sin_port = htons (port);
  baddr.sin_addr.s_addr = htonl (INADDR_ANY);
  sock = new EIBNetIPSocket (baddr, 1, t);
  if (!sock->init ())
    {
      delete sock;
      sock = 0;
      return;
    }
  sock->recvall = 2;
  if (GetHostIP (&sock->sendaddr, multicastaddr) == 0)
    {
      delete sock;
      sock = 0;
      return;
    }
  sock->sendaddr.sin_port = htons (port);
  if (!GetSourceAddress (&sock->sendaddr, &sock->localaddr))
    return;
  sock->localaddr.sin_port = sock->sendaddr.sin_port;

  mcfg.imr_multiaddr = sock->sendaddr.sin_addr;
  mcfg.imr_interface.s_addr = htonl (INADDR_ANY);
  if (!sock->SetMulticast (mcfg))
    {
      delete sock;
      sock = 0;
      return;
    }
  Start ();
  TRACEPRINTF (t, 2, this, "Opened");
}
Beispiel #6
0
void
LLtcp::start()
{
  int reuse = 1;
  int nodelay = 1;
  struct sockaddr_in addr;

  if (!GetHostIP (t, &addr, dest.c_str()))
    {
      ERRORPRINTF (t, E_ERROR | 52, "Lookup of %s failed: %s", dest, strerror(errno));
      goto ex1;
    }
  addr.sin_port = htons (port);

  fd = socket (AF_INET, SOCK_STREAM, 0);
  if (fd == -1)
    {
      ERRORPRINTF (t, E_ERROR | 52, "Opening %s:%d failed: %s", dest,port, strerror(errno));
      goto ex1;
    }

  if (connect (fd, (struct sockaddr *) &addr, sizeof (addr)) == -1)
    {
      ERRORPRINTF (t, E_ERROR | 53, "Connect %s:%d: connect: %s", dest,port, strerror(errno));
      goto ex2;
    }
  setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (reuse));
  setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof (nodelay));

  TRACEPRINTF (t, 2, "Opened");
  FDdriver::start();
  return;

ex2:
  close (fd);
  fd = -1;
ex1:
  stopped();
}
Beispiel #7
0
EIBnetDriver::EIBnetDriver (LinkConnectClientPtr c,
                            std::string& multicastaddr, int port, std::string& intf)
  : SubDriver(c)
{
  struct sockaddr_in baddr;
  struct ip_mreq mcfg;
  sock = 0;
  t->setAuxName("driver");

  TRACEPRINTF (t, 8, "OpenD");

  if (GetHostIP (t, &maddr, multicastaddr) == 0)
    {
      ERRORPRINTF (t, E_ERROR | 11, "Addr '%s' not resolvable", multicastaddr);
      goto err_out;
    }

  if (port)
    {
      maddr.sin_port = htons (port);
      memset (&baddr, 0, sizeof (baddr));
#ifdef HAVE_SOCKADDR_IN_LEN
      baddr.sin_len = sizeof (baddr);
#endif
      baddr.sin_family = AF_INET;
      baddr.sin_addr.s_addr = htonl (INADDR_ANY);
      baddr.sin_port = htons (port);

      sock = new EIBNetIPSocket (baddr, 1, t);
      if (!sock->SetInterface(intf))
        goto err_out;
      if (!sock->init ())
        goto err_out;
      sock->on_recv.set<EIBnetDriver,&EIBnetDriver::recv_cb>(this);
      sock->on_error.set<EIBnetDriver,&EIBnetDriver::error_cb>(this);
    }
  else
    {
      EIBnetServer &parent = *std::static_pointer_cast<EIBnetServer>(server);
      maddr.sin_port = parent.Port;
      sock = parent.sock;
    }

  mcfg.imr_multiaddr = maddr.sin_addr;
  mcfg.imr_interface.s_addr = htonl (INADDR_ANY);
  if (!sock->SetMulticast (mcfg))
    goto err_out;

  /** This causes us to ignore multicast packets sent by ourselves */
  if (!GetSourceAddress (t, &maddr, &sock->localaddr))
    goto err_out;
  sock->localaddr.sin_port = std::static_pointer_cast<EIBnetServer>(server)->Port;
  sock->recvall = 2;

  TRACEPRINTF (t, 8, "OpenedD");
  return;

err_out:
  if (sock && port)
    delete (sock);
  sock = 0;
  return;
}
Beispiel #8
0
void
EIBNetIPTunnel::start()
{
  TRACEPRINTF (t, 2, "Open");

  timeout.set <EIBNetIPTunnel,&EIBNetIPTunnel::timeout_cb> (this);
  conntimeout.set <EIBNetIPTunnel,&EIBNetIPTunnel::conntimeout_cb> (this);
  trigger.set <EIBNetIPTunnel,&EIBNetIPTunnel::trigger_cb> (this);

  trigger.start();

  sock = nullptr;
  if (!GetHostIP (t, &caddr, dest))
    goto ex;
  caddr.sin_port = htons (port);
  if (!GetSourceAddress (t, &caddr, &raddr))
    goto ex;
  raddr.sin_port = htons (sport);
  NAT = false;
  sock = new EIBNetIPSocket (raddr, (sport != 0), t);
  if (!sock->init ())
    goto ex;
  raddr.sin_port = sock->port();
  sock->on_recv.set<EIBNetIPTunnel,&EIBNetIPTunnel::read_cb>(this);
  sock->on_error.set<EIBNetIPTunnel,&EIBNetIPTunnel::error_cb>(this);

  if (srcip.size())
    {
      if (!GetHostIP (t, &saddr, srcip))
                goto ex;
      saddr.sin_port = htons (sport);
      NAT = true;
    }
  else
    saddr = raddr;
  sock->sendaddr = caddr;
  sock->recvaddr = caddr;
  sock->recvall = 0;
  support_busmonitor = true;
  connect_busmonitor = false;

  {
    EIBnet_ConnectRequest creq = get_creq();
    EIBNetIPPacket p = creq.ToPacket ();
    sock->sendaddr = caddr;
    sock->Send (p);
  }
  conntimeout.start(CONNECT_REQUEST_TIMEOUT,0);

  TRACEPRINTF (t, 2, "Opened");
  out.clear();
  return;
ex:
  if (sock) 
    {
      delete sock;
      sock = nullptr;
    }
  is_stopped();
  stopped();
}
Beispiel #9
0
int
main (int ac, char *ag[])
{
  int tracelevel;
  int sport;
  int dport;
  char *a, *b, *c;
  if (ac != 2 && ac != 3)
    die ("Usage: %s ip[:dst-port[:src-port]] [tracelevel]", ag[0]);
  struct sockaddr_in saddr;
  struct sockaddr_in caddr;
  EIBNetIPSocket *sock;
  ev_timer timeout;
  ev_timer_init(&timeout, &end_me, 10.,0.);
  ev_timer_start(EV_DEFAULT_ &timeout);

  tracelevel = 0;
  if (ac == 3)
    tracelevel = atoi (ag[2]);
  a = strdup (ag[1]);
  if (!a)
    die ("out of memory");
  for (b = a; *b; b++)
    if (*b == ':')
      break;
  sport = 3672;
  if (*b == ':')
    {
      *b = 0;
      for (c = b + 1; *c; c++)
	if (*c == ':')
	  break;
      if (*c == ':')
	{
	  *c = 0;
	  sport = atoi (c + 1);
	}
      dport = atoi (b + 1);
    }
  else
    dport = 3671;

  std::string edesc = "eibnetdescribe";
  Trace t = Trace(edesc, "main");
  t.SetTraceLevel (tracelevel);

  printf ("Asking %s at port %d from port %d\n", a, dport, sport);

  if (!GetHostIP (NULL, &caddr, a))
    die ("Host not found");
  caddr.sin_port = htons (dport);
  if (!GetSourceAddress (TracePtr(new Trace(t,a)), &caddr, &saddr))
    die ("No route found");
  saddr.sin_port = htons (sport);
  sock = new EIBNetIPSocket (saddr, 0, TracePtr(new Trace(t,a)));
  sock->sendaddr = caddr;
  sock->recvaddr = caddr;

  if (!sock->init ())
    die ("IP initialisation failed");

  EIBnet_DescriptionRequest req;
  EIBNetIPPacket *p1;
  req.caddr = saddr;
  sock->on_read.set<recv_me>();

  sock->Send (req.ToPacket ());
  ev_run (EV_DEFAULT_ 0);

  return 0;
}
BOOL CCardSwipeServiceApp::InitInstance()
{
	HANDLE hMutex = OpenMutex(
		MUTEX_ALL_ACCESS, 0, "CARDVIDEOCARDSWIPESERVICE.INITINSTANCE.0.1.0.0");

	if (!hMutex)
		// Mutex doesn’t exist. This is
		// the first instance so create
		// the mutex.
		hMutex = 
			CreateMutex(0, 0, "CARDVIDEOCARDSWIPESERVICE.INITINSTANCE.0.1.0.0");
	else
	{
		DebugTell(_T("CCardSwipeServiceApp::InitInstance: Attempt to start duplicate instance of application."));
		// The mutex exists so this is the
		// the second instance so return.
		return FALSE;
	}

	if (!AfxSocketInit())
	{
		DebugTell("Could not initialize Winsock.");
//		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}
	DebugTell(_T("CCardSwipeServiceApp::InitInstance: System starting..."));

	HKEY hk;
	m_addrCardSwipeServiceLocalAddr.s_addr = 0;
	if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,OYSTER_REGISTRY_LOCATION"\\Data",&hk))
	{
		char buf[BUFSIZ];
		DWORD dw = REG_SZ, dwCount;
		dwCount = BUFSIZ;
		DWORD dwValue = 0;

		if (ERROR_SUCCESS ==
			RegQueryValueEx(hk,"DebugMode",0,&dw,(LPBYTE)buf,&dwCount))
		{
			if (strcmp(buf,"1") == 0)
				g_bDebugMode = true;
		}
		dwCount = BUFSIZ;
		if (ERROR_SUCCESS ==
			RegQueryValueEx(hk,"CardSwipeServiceLocalAddr",0,&dw,(LPBYTE)buf,&dwCount))
		{
			m_sCardSwipeServiceLocalAddr = buf;
			if (IsIpAddress((LPCTSTR)m_sCardSwipeServiceLocalAddr))
			{
				m_addrCardSwipeServiceLocalAddr.s_addr = inet_addr((char*)((LPCTSTR)m_sCardSwipeServiceLocalAddr));
			}
			else
			{
				m_addrCardSwipeServiceLocalAddr.s_addr = inet_addr(GetHostIP((LPCTSTR)m_sCardSwipeServiceLocalAddr));
				m_sCardSwipeServiceLocalAddr = GetHostIP();
			}
		}
		dw = REG_DWORD;
		dwCount = 4;
		if (ERROR_SUCCESS ==
			RegQueryValueEx(hk,"CardSwipeServiceClientConnectionPort",0,&dw,(LPBYTE)dwValue,&dwCount))
		{
			if (dwValue > 0)
				m_nPort = dwValue;
			else
				m_nPort = CSS_DEFAULT_PORT;
		}
		else
			m_nPort = CSS_DEFAULT_PORT;
		RegCloseKey(hk);
		DebugTell(_T("CCardSwipeServiceApp::InitInstance: Finished reading registry."));
	}

	CString spv, sfv;
	CExecImageVersion* pVer = new CExecImageVersion();
	spv = pVer->GetProductVersion();
	sfv = pVer->GetFileVersion();
	spv.Replace(_T(", "),_T("."));
	sfv.Replace(_T(", "),_T("."));
	DebugTell(_T("Product Info: %s, Version: %s   File Version: %s"),
		pVer->GetProductName(),spv,sfv);
	delete pVer;

	m_pMainWnd = new CHiddenWnd();
	m_pMainWnd->CreateEx(0,AfxRegisterWndClass(NULL),_T("CardSwipeServiceHiddenWindow"),
		WS_OVERLAPPED,0,0,0,0,HWND_MESSAGE,0);
	m_pServiceThread = AfxBeginThread(ThreadProcRunService,this);
	m_pMainWnd->UpdateWindow();
	m_pMainWnd->EnableWindow();
	DebugTell(_T("CCardSwipeServiceApp::InitInstance: Complete."));
	
	return TRUE;
}