示例#1
0
文件: socket.c 项目: Ugnis/Far-NetBox
static int addr_peer(void)
{
    ne_socket *sock = ne_sock_create();
    ne_inet_addr *ia, *ia2;
    unsigned int port = 9999, realport;
    int ret;

    ia = ne_iaddr_make(ne_iaddr_ipv4, raw_127);
    ONN("ne_iaddr_make returned NULL", ia == NULL);
    
    CALL(new_spawn_server(1, serve_close, NULL, &realport));
    ONN("could not connect", ne_sock_connect(sock, ia, realport));

    ia2 = ne_sock_peer(sock, &port);
    ret = ne_iaddr_cmp(ia, ia2);
    ONV(ret != 0,
        ("comparison of peer with server address was %d", ret));

    ONV(port != realport, ("got peer port %u, expected %u", port, realport));
 
    ne_sock_close(sock);
    CALL(await_server());

    ne_iaddr_free(ia);
    ne_iaddr_free(ia2);
    return OK;
}
示例#2
0
文件: utils.c 项目: Distrotech/neon
int session_server(ne_session **sess, server_fn fn, void *userdata)
{
    unsigned int port;
    
    CALL(new_spawn_server(1, fn, userdata, &port));
    
    *sess = ne_session_create("http", "localhost", port);

    return OK;
}
示例#3
0
文件: socket.c 项目: Ugnis/Far-NetBox
static int begin_socks(ne_socket **sock, struct socks_server *srv,
                       server_fn server, void *userdata)
{
    unsigned int port;
    srv->server = server;
    srv->userdata = userdata;
    srv->say_hello = 1;
    CALL(new_spawn_server(1, socks_server, srv, &port));
    return do_connect(sock, localhost, port);
}
示例#4
0
文件: socket.c 项目: Ugnis/Far-NetBox
static int begin(ne_socket **sock, server_fn fn, void *ud)
{
    struct serve_pair pair;
    unsigned int port;
    pair.fn = fn;
    pair.userdata = ud;
    CALL(new_spawn_server(1, wrap_serve, &pair, &port));
    CALL(do_connect(sock, localhost, port));
    ONV(ne_sock_connect_ssl(*sock, client_ctx, NULL),
	("SSL negotation failed: %s", ne_sock_error(*sock)));
    return OK;
}
示例#5
0
文件: utils.c 项目: Distrotech/neon
int proxied_session_server(ne_session **sess, const char *scheme,
                           const char *host, unsigned int fakeport,
                           server_fn fn, void *userdata)
{
    unsigned int port;
    
    CALL(new_spawn_server(1, fn, userdata, &port));
    
    *sess = ne_session_create(scheme, host, fakeport);

    ne_session_proxy(*sess, "localhost", port);

    return OK;
}
示例#6
0
文件: socket.c 项目: Ugnis/Far-NetBox
/* Connect to an address crafted using ne_iaddr_make rather than from
 * the resolver. */
static int addr_connect(void)
{
    ne_socket *sock = ne_sock_create();
    ne_inet_addr *ia;
    unsigned int port;

    ia = ne_iaddr_make(ne_iaddr_ipv4, raw_127);
    ONN("ne_iaddr_make returned NULL", ia == NULL);
    
    CALL(new_spawn_server(1, serve_close, NULL, &port));
    ONN("could not connect", ne_sock_connect(sock, ia, port));
    ne_sock_close(sock);
    CALL(await_server());

    ne_iaddr_free(ia);
    return OK;
}
示例#7
0
文件: socket.c 项目: Ugnis/Far-NetBox
static int try_prebind(int addr, int port)
{
    ne_socket *sock = ne_sock_create();
    ne_inet_addr *ia;
    char buf[128], line[256];
    unsigned int srvport;

    ia = ne_iaddr_make(ne_iaddr_ipv4, raw_127);
    ONN("ne_iaddr_make returned NULL", ia == NULL);
    
    CALL(new_spawn_server(1, serve_ppeer, NULL, &srvport));

    ne_sock_prebind(sock, addr ? ia : NULL, port ? 7778 : 0);

    ONN("could not connect", ne_sock_connect(sock, ia, srvport));

    ne_snprintf(line, sizeof line,
                "%s@%d\n", ne_iaddr_print(ia, buf, sizeof buf),
                7778);
    
    if (!port) {
        /* Don't know what port will be chosen, so... */
        ssize_t ret = ne_sock_readline(sock, buffer, BUFSIZ);
        
        ONV(ret < 0, ("socket error `%s'", ne_sock_error(sock)));

        ONV(strncmp(line, buffer, strchr(line, '@') - line) != 0,
            ("bad address: '%s', expecting '%s'",
             buffer, line));
    }
    else {
        LINE(line);
    }

    ne_sock_close(sock);
    CALL(await_server());

    ne_iaddr_free(ia);
    return OK;
}
示例#8
0
文件: socket.c 项目: Ugnis/Far-NetBox
/* non-SSL begin() function. */
static int begin(ne_socket **sock, server_fn fn, void *ud)
{
    unsigned int port;
    CALL(new_spawn_server(1, fn, ud, &port));
    return do_connect(sock, localhost, port);
}