コード例 #1
0
ファイル: recvwall.c プロジェクト: jadm1/bs
int client(char* host_address, int host_port, FILE* fin, FILE* fout, int buf_size) {
	int ret = 0;
	int socket_c;

	ret = socktcp(&socket_c);
	if (ret < 0) {
		return -1;
	}

	printf("Connection to %s:%d\n", host_address, host_port);

	ret = sockconnect(socket_c, host_address, host_port);
	if (ret < 0) {
		printf("connect() failed !\n");
		sockclose(socket_c);
		return -1;
	}
	printf("Connection successful !\n");

	ret = sender(socket_c, fin, fout, buf_size);

	printf("Disconnecting...\n");

	sockclose(socket_c);

	return ret;
}
コード例 #2
0
int tcpconnect( unsigned long  iP, 
                unsigned short port, 
                unsigned short timeout ) {

  int                socky;
  struct sockaddr_in address;
  struct sigaction sv;
  struct hostent *athost;
  char thathost[0x100];
  char buffer[512];

  int tries, length;
  socky = -1;
  tries = 0;

  sigemptyset(&sv.sa_mask);
  sv.sa_handler=brokenpipe;
  sigaction(SIGPIPE,&sv,NULL);    

/*  if ((athost = gethostbyname (thathost)) == NULL) {
     return -1;     
  }*/

  fflush(stdout);
   if ((socky = sockconnect(timeout,iP,port)) == -1) {
	fprintf(stdout,"Connection refused.\n");
        socky = -1;
        return socky;
   }

  if (socky == -1) printf("Connection refused.\n");    
  alarm( 0x0 );

  return socky;
}
コード例 #3
0
ファイル: ntqc.c プロジェクト: jadm1/ieor4739-final
int ntq_connect(ntq_server** pserver, char* server_address, int server_port) {
	int ret = 0;
	ntq_server* server = NULL;

	server = (ntq_server*)malloc(sizeof(ntq_server));
	if (server == NULL) {
		fprintf(stderr, "ntq_connect() error not enough memory\n");
		return -1;
	}

	server->server_address = server_address;
	server->server_port = server_port;

	ret = socktcp(&server->socket);
	if (ret != 0) {
		fprintf(stderr, "ntq_connect() error socket creation failed\n");
		return -1;
	}
	ret = sockconnect(server->socket, server->server_address, server->server_port);
	if (ret != 0) {
		fprintf(stderr, "ntq_connect() error socket connect failed\n");
		sockclose(server->socket);
		return -1;
	}

	*pserver = server;
	return 0;
}
コード例 #4
0
void sigalrm_handler() {
  printf("\n -- send() timeout\n");
  close(sockfd);

  printf(" -- reconnecting to %s:%d ..\n", host, orig_port);

  if(sockconnect(host, orig_port) == -1)
    die("unable to connect, DoS successful?");

  printf(" -- attacking!\n");
  sockattack();

  return;
}
コード例 #5
0
ファイル: hey.c プロジェクト: pete0877/wpi
int main(int argc, char *argv[]) {

  char name[MAX_NAME],
       host[MAX_HOST_NAME],
       my_host[MAX_HOST_NAME],
       msgout[MAX_LINE],
      *server;
  int  bytes;

  my_ppid = getppid();

  server = argv[1];

  pthread_mutex_init(&mutex, NULL);

  printf("\nTrying to connect to server %s at port %d...", server, PORT);

  sock = sockconnect(server, PORT);
  if (sock == -1) {
    printf("\nCouldn't connect to the server!");
    exit(1); }

  /* set up clean up function */
  signal(SIGINT, Clean_Up);

  /* send LOGIN */
  gethostname(my_host,MAX_HOST_NAME);
  my_id = (int) (getpid());
  sprintf(msgout,"LOGIN,%s,%s,%d;",getlogin(),my_host,my_id);
pthread_mutex_lock(&mutex);
  bytes = send(sock, msgout, strlen(msgout)+1, 0);
pthread_mutex_unlock(&mutex); 
  if (bytes == -1) {
	printf("\nCouldn't send command!");
	Clean_Up(); 
  } else {
	printf("\nSent Login Info.");
  }

  pthread_create(&tid_send_hey, NULL, (void*) &Send_Hey, (void*) sock);
  pthread_create(&tid_get_hey,  NULL, (void*) &Get_Hey,  (void*) sock);

  while (1) { 
	sleep (2);
	if (my_ppid != getppid()) Clean_Up(); 
  } 

}
コード例 #6
0
ファイル: pd9p.c プロジェクト: JuEeHa/pd9p
int
main(int argc, char **argv) {
	int s, inlen, outlen, f;
	pd9p_session *session;
	uint32_t file;
	char buf[1024];
	
	if(argc<6) {
		fputs("Usage: pd9p addr port cmd remote local\n", stderr);
		return 1;
	}
	
	if((s=sockconnect(argv[1], atoi(argv[2]))) == -1) {
		fputs("pd9p: error: sockconnect\n", stderr);
	}
	
	if((session=pd9p_connect(s)) == 0) {
		close(s);
		fputs("pd9p: error: pd9p_connec\n", stderr);
		return 1;
	}
	
	if(!strcmp(argv[3], "get")) {
		if((file=pd9p_open(session, argv[4], pd9p_rdonly)) == errfid) {
			fputs("pd9p: error: pd9p_open\n", stderr);
			return 1;
		}
		if((f=open(argv[4], O_WRONLY|O_CREAT, 0666)) == -1) {
			fputs("pd9p: error: open\n", stderr);
			return 1;
		}
		
		inlen=0;
		while((inlen=pd9p_read(session, file, buf+inlen, 1024)) > 0) {
			for(outlen=0; outlen<inlen;)
				outlen+=write(f, buf+outlen, inlen-outlen);
		}
		pd9p_close(session, file);
		close(f);
	}
	
	pd9p_closesession(session);
	close(s);
	return 0;
}
コード例 #7
0
int main(int argc,char **argv){
    struct addrinfo *res;
    struct addrinfo *caddr;
    char hname[STRSIZE + 1];
    char *ipv;
    int ai_family;
    char *host;
    char *port;
    in_port_t uport;
    int rc;
    int cs;
    int buffsize;
    int64_t data_size;

    if(argc<4){
        usage(argv[0]);
        return 0;
    }
    host = argv[1];
    port = argv[2];
    ipv = argv[3];
    uport = atoi(port);
    data_size = (int64_t)atoll(argv[4]);
    buffsize = atoi(argv[5]);
    ai_family = get_ai_family(ipv);
    rc = lookup(host,port,ai_family,&res);
        if(rc != 0) {
        fprintf(stderr,"Error getting addrinfo for %s:",host);
        fprintf(stderr,"%s\n",gai_strerror(rc));
        exit(1);
        }
    cs = sockconnect(res,host,&uport,stdout);
    freeaddrinfo(res);
    swallow_client(cs,data_size,buffsize);
    close(cs);
    return 0;
}