Hello everyone,
I'm trying to connect to my UDP server with only the hostname.
I have validate my connection to my UDP server with an IP static and know i want to use an hostname to find my IP and establish a connection to my UDP server.
My issue occur when i try to get this IP address.
I have try an example to establish a connection between my board and my UDP server. To do that i have use this example : Modem Shell
I have test this command : sock connect -a "address"' -p 1800 -f inet -t dgram -> All OK
After the first command, i have test this one: sock send -i 0 -d testing -> my UDP server correctly receive the message
So i have study the code of this example to be able to get the IP address of a specific address.
This is my code for the moment :
int server_init(void) { int err = -EINVAL; struct sock_info *socket_info; // = reserve_socket_id(); if (socket_info == NULL) { printk("socket creation failed; MAX SOCKETS exceeeded"); } /* Get address */ err = sock_getaddrinfo(socket_info, 1, 2, "myaddress.net", 1800, 0); if (err) { printk("err get address : %d \r\n",err); //goto connect_error; } printk("OK\r\n"); return 0; }
static int sock_getaddrinfo( struct sock_info *socket_info, int family, int type, char *address, int port, int pdn_cid) { int err; struct addrinfo hints = { .ai_family = 1, .ai_socktype = 2, }; char pdn_serv[12]; char *service = NULL; err = getaddrinfo(address, service, &hints, &socket_info->addrinfo); if (err) { if (err == DNS_EAI_SYSTEM) { printk("getaddrinfo() failed, err %d errno %d", err, errno); } else { printk("getaddrinfo() failed, err %d", err); } return -EADDRNOTAVAIL; } /* Set port to address info */ ((struct sockaddr_in *)socket_info->addrinfo->ai_addr)->sin_port =htons(1800); return 0; }
My code compile with no problem and after a flash when i debug initialisation of my module, i have this :
1) socket creation failed; MAX SOCKETS exceeeded
2) getaddrinfo() failed, err -11 errno 115
3) err get address : -125"
I understand the first error, it's because my socket_info is NULL, that not a problem because for the moment i need only 1 socket
The line where the problem come from is : err = getaddrinfo(address, service, &hints, &socket_info->addrinfo);
And i have no idea how to solve this problem,
Do you have advice for me ?
Best regards,
Lam