Skip to content
Snippets Groups Projects
Commit 326167e2 authored by Wesley W. Terpstra's avatar Wesley W. Terpstra
Browse files

Make it possible to force a specific IP version.

parent 567107d2
No related merge requests found
...@@ -43,7 +43,7 @@ void eb_posix_ip_close(eb_posix_sock_t sock) { ...@@ -43,7 +43,7 @@ void eb_posix_ip_close(eb_posix_sock_t sock) {
#endif #endif
} }
eb_posix_sock_t eb_posix_ip_open(int type, const char* port) { eb_posix_sock_t eb_posix_ip_open(int family, int type, const char* port) {
struct addrinfo hints, *match, *i; struct addrinfo hints, *match, *i;
eb_posix_sock_t sock; eb_posix_sock_t sock;
int protocol; int protocol;
...@@ -57,7 +57,7 @@ eb_posix_sock_t eb_posix_ip_open(int type, const char* port) { ...@@ -57,7 +57,7 @@ eb_posix_sock_t eb_posix_ip_open(int type, const char* port) {
/* Find a matching address for this port */ /* Find a matching address for this port */
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = PF_INET6; /* Not restricted to a given IP version */ hints.ai_family = family;
hints.ai_socktype = type; /* STREAM/DGRAM as requested */ hints.ai_socktype = type; /* STREAM/DGRAM as requested */
hints.ai_protocol = protocol; /* TCP/UDP over IP to exclude non IPv* protocols */ hints.ai_protocol = protocol; /* TCP/UDP over IP to exclude non IPv* protocols */
hints.ai_flags = AI_PASSIVE; /* Suitable for binding a socket */ hints.ai_flags = AI_PASSIVE; /* Suitable for binding a socket */
...@@ -78,7 +78,7 @@ eb_posix_sock_t eb_posix_ip_open(int type, const char* port) { ...@@ -78,7 +78,7 @@ eb_posix_sock_t eb_posix_ip_open(int type, const char* port) {
return sock; return sock;
} }
socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int type, struct sockaddr_storage* out) { socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int family, int type, struct sockaddr_storage* out) {
struct addrinfo hints, *match; struct addrinfo hints, *match;
int len, protocol; int len, protocol;
char host[250]; char host[250];
...@@ -113,7 +113,7 @@ socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int type, ...@@ -113,7 +113,7 @@ socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int type,
} }
memset(&hints, 0, sizeof(struct addrinfo)); memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = PF_UNSPEC; /* Not restricted to a given IP version */ hints.ai_family = family;
hints.ai_socktype = type; /* STREAM/DGRAM as requested */ hints.ai_socktype = type; /* STREAM/DGRAM as requested */
hints.ai_protocol = protocol; /* TCP/UDP over IP to exclude non IPv* protocols */ hints.ai_protocol = protocol; /* TCP/UDP over IP to exclude non IPv* protocols */
hints.ai_flags = 0; hints.ai_flags = 0;
......
...@@ -57,8 +57,8 @@ typedef eb_descriptor_t eb_posix_sock_t; ...@@ -57,8 +57,8 @@ typedef eb_descriptor_t eb_posix_sock_t;
#endif #endif
EB_PRIVATE void eb_posix_ip_close(eb_posix_sock_t sock); EB_PRIVATE void eb_posix_ip_close(eb_posix_sock_t sock);
EB_PRIVATE eb_posix_sock_t eb_posix_ip_open(int type, const char* port); EB_PRIVATE eb_posix_sock_t eb_posix_ip_open(int family, int type, const char* port);
EB_PRIVATE socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int type, struct sockaddr_storage* out); EB_PRIVATE socklen_t eb_posix_ip_resolve(const char* prefix, const char* address, int family, int type, struct sockaddr_storage* out);
EB_PRIVATE void eb_posix_ip_non_blocking(eb_posix_sock_t sock, unsigned long on); EB_PRIVATE void eb_posix_ip_non_blocking(eb_posix_sock_t sock, unsigned long on);
EB_PRIVATE void eb_posix_ip_force_non_blocking(eb_posix_sock_t sock, unsigned long on); EB_PRIVATE void eb_posix_ip_force_non_blocking(eb_posix_sock_t sock, unsigned long on);
......
...@@ -38,7 +38,7 @@ eb_status_t eb_posix_tcp_open(struct eb_transport* transportp, const char* port) ...@@ -38,7 +38,7 @@ eb_status_t eb_posix_tcp_open(struct eb_transport* transportp, const char* port)
struct eb_posix_tcp_transport* transport; struct eb_posix_tcp_transport* transport;
eb_posix_sock_t sock; eb_posix_sock_t sock;
sock = eb_posix_ip_open(SOCK_STREAM, port); sock = eb_posix_ip_open(PF_INET6, SOCK_STREAM, port);
if (sock == -1) return EB_BUSY; if (sock == -1) return EB_BUSY;
if (listen(sock, 5) != 0) { if (listen(sock, 5) != 0) {
...@@ -69,7 +69,11 @@ eb_status_t eb_posix_tcp_connect(struct eb_transport* transportp, struct eb_link ...@@ -69,7 +69,11 @@ eb_status_t eb_posix_tcp_connect(struct eb_transport* transportp, struct eb_link
link = (struct eb_posix_tcp_link*)linkp; link = (struct eb_posix_tcp_link*)linkp;
len = eb_posix_ip_resolve("tcp/", address, SOCK_STREAM, &sa); len = -1;
if (len == -1) len = eb_posix_ip_resolve("tcp6/", address, PF_INET6, SOCK_STREAM, &sa);
if (len == -1) len = eb_posix_ip_resolve("tcp4/", address, PF_INET, SOCK_STREAM, &sa);
if (len == -1) len = eb_posix_ip_resolve("tcp/", address, PF_INET6, SOCK_STREAM, &sa);
if (len == -1) len = eb_posix_ip_resolve("tcp/", address, PF_INET, SOCK_STREAM, &sa);
if (len == -1) return EB_ADDRESS; if (len == -1) return EB_ADDRESS;
sock = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP); sock = socket(sa.ss_family, SOCK_STREAM, IPPROTO_TCP);
......
...@@ -48,7 +48,7 @@ eb_status_t eb_posix_udp_open(struct eb_transport* transportp, const char* port) ...@@ -48,7 +48,7 @@ eb_status_t eb_posix_udp_open(struct eb_transport* transportp, const char* port)
eb_posix_sock_t sock; eb_posix_sock_t sock;
int optval; int optval;
sock = eb_posix_ip_open(SOCK_DGRAM, port); sock = eb_posix_ip_open(PF_INET6, SOCK_DGRAM, port);
if (sock == -1) return EB_BUSY; if (sock == -1) return EB_BUSY;
/* Etherbone can broadcast */ /* Etherbone can broadcast */
...@@ -76,7 +76,11 @@ eb_status_t eb_posix_udp_connect(struct eb_transport* transportp, struct eb_link ...@@ -76,7 +76,11 @@ eb_status_t eb_posix_udp_connect(struct eb_transport* transportp, struct eb_link
struct sockaddr_storage sa; struct sockaddr_storage sa;
socklen_t len; socklen_t len;
len = eb_posix_ip_resolve("udp/", address, SOCK_DGRAM, &sa); len = -1;
if (len == -1) len = eb_posix_ip_resolve("udp6/", address, PF_INET6, SOCK_DGRAM, &sa);
if (len == -1) len = eb_posix_ip_resolve("udp4/", address, PF_INET, SOCK_DGRAM, &sa);
if (len == -1) len = eb_posix_ip_resolve("udp/", address, PF_INET6, SOCK_DGRAM, &sa);
if (len == -1) len = eb_posix_ip_resolve("udp/", address, PF_INET, SOCK_DGRAM, &sa);
if (len == -1) return EB_ADDRESS; if (len == -1) return EB_ADDRESS;
link = (struct eb_posix_udp_link*)linkp; link = (struct eb_posix_udp_link*)linkp;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment