documentation

This commit is contained in:
2024-10-17 14:56:32 +02:00
parent 35b951597a
commit 7e0d346962
3 changed files with 33 additions and 66 deletions

View File

@ -44,40 +44,6 @@ int hw_device_open(const char *path, size_t path_len) {
return -1;
}
// struct sockaddr_in6 sin6;
// memset(&sin6, 0, sizeof(sin6));
// sin6.sin6_family = AF_INET6;
// sin6.sin6_port = htons(port_number);
// struct sockaddr_in sin4;
// memset(&sin4, 0, sizeof(sin4));
// sin4.sin_family = AF_INET;
// sin4.sin_port = htons(port_number);
// int result = inet_pton(AF_INET, sim_ip, &sin4.sin_addr);
// int sock;
// const struct sockaddr *addr = NULL;
// socklen_t addrlen = 0;
// if (result == 1) {
// if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
// perror("hw_device_open, creating socket failed");
// exit(-1);
// }
// addr = (struct sockaddr *)&sin4;
// addrlen = sizeof(sin4);
// }
// result = inet_pton(AF_INET6, sim_ip, &sin6.sin6_addr);
// if ((result == 1) && (addr == NULL)) {
// if ((sock = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
// perror("hw_device_open, creating socket failed");
// exit(-1);
// }
// addr = (struct sockaddr *)&sin6;
// addrlen = sizeof(sin6);
// }
struct addrinfo addrinfo_hint;
addrinfo_hint.ai_flags = AI_ADDRCONFIG;
addrinfo_hint.ai_family = ai_family;
@ -102,20 +68,24 @@ int hw_device_open(const char *path, size_t path_len) {
for (current_candidate = addr_candidates; current_candidate != NULL;
current_candidate = current_candidate->ai_next) {
sock = socket(current_candidate->ai_family, current_candidate->ai_socktype,
current_candidate->ai_protocol);
if (sock == -1)
continue;
current_candidate->ai_protocol);
if (sock == -1) {
continue;
}
if (connect(sock, current_candidate->ai_addr, current_candidate->ai_addrlen) != -1)
break; /* Success */
if (connect(sock, current_candidate->ai_addr,
current_candidate->ai_addrlen) != -1) {
break; /* Success */
}
close(sock);
// Connect failed, close socket
close(sock);
}
if (current_candidate == NULL) { /* No address succeeded */
fprintf(stderr, "hw_device_open, invalid sim address\n");
exit(EXIT_FAILURE);
}
if (current_candidate == NULL) { /* No address succeeded */
fprintf(stderr, "hw_device_open, invalid sim address\n");
exit(EXIT_FAILURE);
}
return sock;
}