<commit_before>#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#if 0
/* 
 * Structs exported from netinet/in.h (for easy reference)
 */

/* Internet address */
struct in_addr {
  unsigned int s_addr; 
};

/* Internet style socket address */
struct sockaddr_in  {
  unsigned short int sin_family; /* Address family */
  unsigned short int sin_port;   /* Port number */
  struct in_addr sin_addr;	 /* IP address */
  unsigned char sin_zero[...];   /* Pad to size of 'struct sockaddr' */
};

/*
 * Struct exported from netdb.h
 */

/* Domain name service (DNS) host entry */
struct hostent {
  char    *h_name;        /* official name of host */
  char    **h_aliases;    /* alias list */
  int     h_addrtype;     /* host address type */
  int     h_length;       /* length of address */
  char    **h_addr_list;  /* list of addresses */
}
#endif

#define BUFSIZE 4096

#define USAGE                                                                 \
"usage:\n"                                                                    \
"  echoserver [options]\n"                                                    \
"options:\n"                                                                  \
"  -p                  Port (Default: 8888)\n"                                \
"  -h                  Show this help message\n"                              



int main(int argc, char **argv) {
  int option_char;   // passed options
  int portno = 8888; /* port to listen on */
  struct sockaddr_in address;
  char buffer[16];
  int sock = -1;
  
  // Parse and set command line arguments
  while ((option_char = getopt(argc, argv, "p:h")) != -1){
    switch (option_char) {
      case 'p': // listen-port
        portno = atoi(optarg); // global optarg; aoti -> int
        break;
      case 'h': // help
        fprintf(stdout, "%s", USAGE);
        exit(0);
        break;           
      default:
        fprintf(stderr, "%s", USAGE);
        exit(1);
    }
  }

  /* Socket Code Here */

  sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = INADDR_ANY;
  address.sin_port = portno;

  bind(sock, (struct sockaddr *)&address, sizeof(struct sockaddr_in));
  listen(sock, 5);
  printf("%s: ready and listening on port %d\n", argv[0], portno);
  return 0;

}<commit_msg>gtpr1: primitive but working version of echoserver.<commit_after>#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h> 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#if 0
/* 
 * Structs exported from netinet/in.h (for easy reference)
 */

/* Internet address */
struct in_addr {
  unsigned int s_addr; 
};

/* Internet style socket address */
struct sockaddr_in  {
  unsigned short int sin_family; /* Address family */
  unsigned short int sin_port;   /* Port number */
  struct in_addr sin_addr;	 /* IP address */
  unsigned char sin_zero[...];   /* Pad to size of 'struct sockaddr' */
};

/*
 * Struct exported from netdb.h
 */

/* Domain name service (DNS) host entry */
struct hostent {
  char    *h_name;        /* official name of host */
  char    **h_aliases;    /* alias list */
  int     h_addrtype;     /* host address type */
  int     h_length;       /* length of address */
  char    **h_addr_list;  /* list of addresses */
}
#endif

#define BUFSIZE 4096

#define USAGE                                                                 \
"usage:\n"                                                                    \
"  echoserver [options]\n"                                                    \
"options:\n"                                                                  \
"  -p                  Port (Default: 8888)\n"                                \
"  -h                  Show this help message\n"                              



int main(int argc, char **argv) {
    int option_char;   // passed options
    int portno = 8888; /* port to listen on */
    struct sockaddr_in address_server; // address info of the server
    struct sockaddr address_client; // address info of a connected client
    int addr_client_len; // length of the client field
    int read_size; // size of the message received
    char client_message[16];
    int sock_server;
    int sock_client;

    // Parse and set command line arguments
    while ((option_char = getopt(argc, argv, "p:h")) != -1){
        switch (option_char) {
            case 'p': // listen-port
                portno = atoi(optarg); // global optarg; aoti -> int
                break;
        case 'h': // help
            fprintf(stdout, "%s", USAGE);
            exit(0);
            break;           
        default:
            fprintf(stderr, "%s", USAGE);
            exit(1);
        }
    }

    /* Socket Code Here */

    sock_server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    address_server.sin_family = AF_INET;
    address_server.sin_addr.s_addr = INADDR_ANY;
    address_server.sin_port = portno;

    bind(sock_server, (struct sockaddr *)&address_server, sizeof(struct sockaddr_in));
    listen(sock_server, 5);
    printf("%s: ready and listening on port %d\n", argv[0], portno);

    while(1) {
        sock_client = accept(sock_server, (struct sockaddr *)&address_client, (socklen_t *) sizeof(struct sockaddr_in));
        
        while ((read_size = recv(sock_client, client_message, 15, 0)) > 0 ) // I think 0 will be added to the end
            write(sock_client, client_message, strlen(client_message));
    }
}
{'fraction_non_alphanumeric': 0.11835153222965833, 'fraction_numerical': 0.008629799225079253, 'mean_word_length': 1.7329162656400385, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3140468', 'n_tokens_mistral': 1730, 'n_tokens_neox': 1676, 'n_words': 491}