<commit_before>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL> at g<EMAIL> dot <EMAIL>>
 * See LICENSE file for license details.
 */

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/un.h>
#include <unistd.h>

#include "cext.h"
#include "ixp.h"

static int
connect_unix_sock(char *address)
{
    int fd = 0;
    struct sockaddr_un addr = { 0 };
    socklen_t su_len;

    /* init */
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, address, sizeof(addr.sun_path));
    su_len = sizeof(struct sockaddr) + strlen(addr.sun_path);

    if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
        return -1;
    if(connect(fd, (struct sockaddr *) &addr, su_len)) {
        close(fd);
        return -1;
    }
    return fd;
}

static int
connect_tcp_sock(char *host)
{
    int fd = 0;
    struct sockaddr_in addr = { 0 };
	struct hostent *hp;
	char *port = strrchr(host, '!');
	const char *errstr = nil;

	*port = 0;
	port++;
	addr.sin_port = cext_strtonum(port, 1024, 65535, &errstr);
	if(errstr)
		return -1;

    /* init */
    if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        return -1;
	hp = gethostbyname(host);
    addr.sin_family = AF_INET;
	bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);

    if(connect(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
        close(fd);
        return -1;
    }
    return fd;
}

int
ixp_connect_sock(char *address)
{
	char *p = strchr(address, '!');
	char *addr, *type;

	if(!p)
		return -1;
	*p = 0;
	
	addr = &p[1];
	type = address; /* unix, tcp */

	if(strncmp(type, "unix", 5))
		return connect_unix_sock(addr);
	else if(!strncmp(type, "tcp", 4))<commit_msg>Added a missing exclamation sign for strncmp<commit_after>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/un.h>
#include <unistd.h>

#include "cext.h"
#include "ixp.h"

static int
connect_unix_sock(char *address)
{
    int fd = 0;
    struct sockaddr_un addr = { 0 };
    socklen_t su_len;

    /* init */
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, address, sizeof(addr.sun_path));
    su_len = sizeof(struct sockaddr) + strlen(addr.sun_path);

    if((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
        return -1;
    if(connect(fd, (struct sockaddr *) &addr, su_len)) {
        close(fd);
        return -1;
    }
    return fd;
}

static int
connect_tcp_sock(char *host)
{
    int fd = 0;
    struct sockaddr_in addr = { 0 };
	struct hostent *hp;
	char *port = strrchr(host, '!');
	const char *errstr = nil;

	*port = 0;
	port++;
	addr.sin_port = cext_strtonum(port, 1024, 65535, &errstr);
	if(errstr)
		return -1;

    /* init */
    if((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
        return -1;
	hp = gethostbyname(host);
    addr.sin_family = AF_INET;
	bcopy(hp->h_addr, &addr.sin_addr, hp->h_length);

    if(connect(fd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))) {
        close(fd);
        return -1;
    }
    return fd;
}

int
ixp_connect_sock(char *address)
{
	char *p = strchr(address, '!');
	char *addr, *type;

	if(!p)
		return -1;
	*p = 0;
	
	addr = &p[1];
	type = address; /* unix, tcp */

	if(!strncmp(type, "unix", 5))
		return connect_unix_sock(addr);
	else if(!strncmp(type, "tcp", 4))
{'fraction_non_alphanumeric': 0.16797532249018507, 'fraction_numerical': 0.015703869882220976, 'mean_word_length': 3.221301775147929, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '867496', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1450, 'n_words': 337}