src/net.c
int32_t UdpConnect(struct sockaddr_in *addr, char *ip, uint32_t port, uint32_t sockfd)
{
    int32_t res;
    struct sockaddr_in *remote = addr;

    remote->sin_family = AF_INET;
    res = inet_pton(AF_INET, (const char*)ip, (void *) (&(remote->sin_addr.s_addr)));
    if (res < 0) {
	    fprintf(stderr, "Error: Can't set remote->sin_addr.s_addr\n");
	    return -1;
    }
    else if (res == 0) {
	    fprintf(stderr, "Error: Invalid address '%s'\n", ip);
	    return -1;
    }

    remote->sin_port = htons(port);
#if 0
    if (connect(sockfd,
                (struct sockaddr *)remote, sizeof(struct sockaddr)) == -1) {
        close(sockfd);
        fprintf(stderr, "Error connecting to %s:%d\n", ip, port);
        return -1;
    }
#endif

    return True;
}
/* Connect to a UDP socket server and returns the file descriptor */
Connect to a UDP socket server and returns the file descriptor
Connect to a UDP socket server and returns the file descriptor
int32_t UdpConnect(struct sockaddr_in *addr, char *ip, uint32_t port, uint32_t sockfd)
{
    int32_t res;
    struct sockaddr_in *remote = addr;
    remote->sin_family = AF_INET;
    res = inet_pton(AF_INET, (const char*)ip, (void *) (&(remote->sin_addr.s_addr)));
    if (res < 0) {
	    fprintf(stderr, "Error: Can't set remote->sin_addr.s_addr\n");
	    return -1;
    }
    else if (res == 0) {
	    fprintf(stderr, "Error: Invalid address '%s'\n", ip);
	    return -1;
    }
    remote->sin_port = htons(port);
#if 0
    if (connect(sockfd,
                (struct sockaddr *)remote, sizeof(struct sockaddr)) == -1) {
        close(sockfd);
        fprintf(stderr, "Error connecting to %s:%d\n", ip, port);
        return -1;
    }
#endif
    return True;
}
int32_t UdpConnect ( struct sockaddr_in * addr , char * ip , uint32_t port , uint32_t sockfd ) { int32_t res ; struct sockaddr_in * remote = addr ; remote -> sin_family = AF_INET ; res = inet_pton ( AF_INET , ( const char * ) ip , ( void * ) ( & ( remote -> sin_addr . s_addr ) ) ) ; if ( res < 0 ) { fprintf ( stderr , " \n " ) ; return -1 ; } else if ( res == 0 ) { fprintf ( stderr , " \n " , ip ) ; return -1 ; } remote -> sin_port = htons ( port ) ; #if 0 if ( connect ( sockfd , ( struct sockaddr * ) remote , sizeof ( struct sockaddr ) ) == -1 ) { close ( sockfd ) ; fprintf ( stderr , " \n " , ip , port ) ; return -1 ; } #endif return True ; }
Connect to a UDP socket server and returns the file descriptor
Connect to a UDP socket server and returns the file descriptor