2019-07-23 10:38:28 +03:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2019-07-24 10:17:29 +03:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2019-07-23 10:38:28 +03:00
|
|
|
|
2019-07-24 10:17:29 +03:00
|
|
|
#include "idris_net.h"
|
2019-07-23 10:38:28 +03:00
|
|
|
|
2019-07-24 10:17:29 +03:00
|
|
|
void test_eagain() {
|
2019-07-23 10:38:28 +03:00
|
|
|
int eagain = idrnet_geteagain();
|
|
|
|
assert(eagain == 35);
|
2019-07-24 10:17:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void test_bind_to_0_assigns_random_port() {
|
|
|
|
struct sockaddr_in address;
|
|
|
|
socklen_t addrlen = sizeof(struct sockaddr);
|
|
|
|
int sock = idrnet_socket(AF_INET, 1, 0);
|
|
|
|
assert(sock > 0);
|
|
|
|
|
|
|
|
int res = idrnet_bind(sock, AF_INET, 1, "127.0.0.1", 0);
|
|
|
|
assert(res == 0);
|
|
|
|
|
|
|
|
res = idrnet_sockaddr_port(sock);
|
|
|
|
assert(res > 0);
|
|
|
|
|
|
|
|
printf("socket bound to %d\n",res);
|
|
|
|
close(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char**argv) {
|
|
|
|
test_eagain();
|
|
|
|
test_bind_to_0_assigns_random_port();
|
2019-07-23 10:38:28 +03:00
|
|
|
|
|
|
|
printf("network library tests SUCCESS\n");
|
|
|
|
return 0;
|
|
|
|
}
|