Reputation: 320
I'm using UNIX port, the TAP net interface and the BSD-alike Socket API that LwIP provides.
The getaddrinfo
from lwip is returning error ERR_VAL (value -6 if I activate debugging mode), I think I'm initializing everything correctly, I already set up a HTTP server with no problem.
I think the problem is with the TAP interface, it can't make TCP connections to external DNS servers.
I'm going to attach my code and my lwipots.h
file
Here is my code:
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include "lwip/tcpip.h"
#include "lwip/netifapi.h"
#include "netif/tapif.h"
#define PERROR(errcode) printf("error on line %d: error %d\n", __LINE__, errcode)
int main(void) {
tcpip_init(NULL, NULL);
struct netif my_netif = {0};
ip4_addr_t ip, netmask, gw;
IP4_ADDR(&ip, 192, 168, 1, 20);
IP4_ADDR(&netmask, 255, 255, 255, 0);
IP4_ADDR(&gw, 192, 168, 1, 1);
err_t err = netifapi_netif_add(&my_netif, &ip, &netmask, &gw, NULL, tapif_init, tcpip_input);
if (err != 0) {
PERROR(err);
return 1;
}
if (err = netifapi_netif_set_default(&my_netif)) {
PERROR(err);
return 1;
}
if (err = netifapi_netif_set_up(&my_netif)) {
PERROR(err);
return 1;
}
struct addrinfo *google_addr = NULL;
int ret = getaddrinfo("google.com", "80", NULL, &google_addr);
if (ret != 0) {
PERROR(ret);
return 1;
}
// After getting google.com IP address, I want to call socket, connect, send, recv, close.
}
And my lwipopts.h
:
#ifndef LWIP_LWIPOPTS_H
#define LWIP_LWIPOPTS_H
#define LWIP_DEBUG 0 // Debug mode activated
#define SOCKETS_DEBUG LWIP_DBG_ON
#define DHCP_DEBUG LWIP_DBG_ON
#define NETIF_DEBUG LWIP_DBG_ON
#define TAPIF_DEBUG LWIP_DBG_ON
#define DNS_DEBUG LWIP_DBG_ON
/* Modules that I'm using */
#define LWIP_NETIF_API 1
#define LWIP_DNS 1
#endif
Upvotes: 0
Views: 53