All pastes #485336 Raw Edit

Someone

public c v1 · immutable
·published 2007-05-12 23:49 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <winsock2.h>#define PORT 6667 // the port client will be connecting to#define MAXDATASIZE 512 // max number of bytes we can get at onceint main(int argc, char *argv[]){     int local_socket = 0, remote_socket = 0, menu_switch = 0, message_length = 0;     unsigned short local_port = 0, remote_port = 0;     struct sockaddr_in local_address /*remote_address*/;     WSADATA wsa_data;     /* Load Winsock 2.0 DLL */     if (WSAStartup(MAKEWORD(2, 0), &wsa_data) != 0)     {          fprintf(stderr, "WSAStartup() failed\n");          return (1);     }     if ((local_socket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)     {          fprintf(stderr, "socket() failed\n");          return(1);     }    int sockfd, numbytes;      char buf[MAXDATASIZE];    struct hostent *he;    struct sockaddr_in their_addr; // connector's address information    if (argc != 2) {        fprintf(stderr,"usage: client hostname\n");        exit(1);    }    if ((he=gethostbyname(argv[1])) == NULL) {  // get the host info        perror("gethostbyname");        exit(1);    }    if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {        perror("socket");        exit(1);    }    their_addr.sin_family = AF_INET;    // host byte order    their_addr.sin_port = htons(PORT);  // short, network byte order    their_addr.sin_addr = *((struct in_addr *)he->h_addr);    memset(&(their_addr.sin_zero), '\0', 8);  // zero the rest of the struct    if (connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr)) == -1) {        perror("connect");        exit(1);    }    if ((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {        perror("recv");        exit(1);    }    buf[numbytes] = '\0';	do{    printf("Received: %s",buf);	char nick[20] = "NICK nanobot\n";	send(sockfd,nick,20,NULL);    //closesocket(sockfd);	}while(1);    return 0;}