6 #include <pthread-l4.h>
8 #include <l4/util/util.h>
9 #include <l4/ankh/client-c.h>
10 #include <l4/ankh/lwip-ankh.h>
11 #include <l4/ankh/session.h>
13 * Need to include this file before others.
18 #include "netif/etharp.h"
19 #include "lwip/tcpip.h"
20 #include "lwip/inet.h"
21 #include "lwip/dhcp.h"
22 #include "lwip/sockets.h"
24 #include "lwip/netdb.h"
26 #define GETOPT_LIST_END { 0, 0, 0, 0 }
34 /* Network interface variables */
35 ip_addr_t ipaddr, netmask, gw;
37 /* Set network address variables */
39 IP4_ADDR(&gw, 192,168,0,1);
40 IP4_ADDR(&ipaddr, 192,168,0,2);
41 IP4_ADDR(&netmask, 255,255,255,0);
44 struct netif my_netif;
45 extern err_t ankhif_init(struct netif*);
47 static ankh_config_info cfg = { 1024, L4_INVALID_CAP, L4_INVALID_CAP, "" };
50 static void do_lookup(char *hostname)
53 struct hostent *h = gethostbyname(hostname);
55 printf("gethostbyname(%s): %s\n", hostname, h ? "SUCCESS" : "FAILED");
57 i.addr = *(u32_t*)h->h_addr_list[0];
58 printf(" h_name: '%s'\n", h->h_name);
59 printf(" --> "); print_ip(&i); printf("\n");
64 static void dns_test(void)
66 do_lookup("os.inf.tu-dresden.de");
67 do_lookup("www.heise.de");
68 do_lookup("www.twitter.com");
69 do_lookup("www.tudos.org");
70 do_lookup("www.ifsr.de");
71 do_lookup("www.dynamo-dresden.de");
72 do_lookup("www.spiegel.de");
73 do_lookup("www.smoking-gnu.de");
74 do_lookup("www.fail.fx");
78 static void server(void)
81 struct sockaddr_in in, clnt;
83 in.sin_family = AF_INET;
84 in.sin_port = htons(3000);
85 in.sin_addr.s_addr = my_netif.ip_addr.addr;
87 int sock = socket(PF_INET, SOCK_STREAM, 0);
88 printf("socket created: %d\n", sock);
90 err = bind(sock, (struct sockaddr*)&in, sizeof(in));
91 printf("bound to addr: %d\n", err);
93 err = listen(sock, 10);
94 printf("listen(): %d\n", err);
98 socklen_t clnt_size = sizeof(clnt);
99 fd = accept(sock, (struct sockaddr*)&clnt, &clnt_size);
101 printf("Got connection from ");
102 print_ip((ip_addr_t*)&clnt.sin_addr); printf("\n");
104 err = read(fd, buf, sizeof(buf));
105 printf("Read from fd %d (err %d)\n", fd, err);
111 int main(int argc, char **argv)
116 l4_cap_idx_t c = pthread_getl4cap(pthread_self());
119 static struct option long_opts[] = {
120 {"bufsize", 1, 0, BUF_SIZE },
121 {"shm", 1, 0, SHM_NAME },
127 int opt = getopt_long(argc, argv, "b:s:", long_opts, &optind);
128 printf("getopt: %d\n", opt);
135 printf("buf size: %d\n", atoi(optarg));
136 cfg.bufsize = atoi(optarg);
139 printf("shm name: %s\n", optarg);
140 snprintf(cfg.shm_name, CFG_SHM_NAME_SIZE, "%s", optarg);
147 // Start the TCP/IP thread & init stuff
148 tcpip_init(NULL, NULL);
149 struct netif *n = netif_add(&my_netif,
150 &ipaddr, &netmask, &gw,
151 &cfg, // configuration state
152 ankhif_init, ethernet_input);
154 printf("netif_add: %p (%p)\n", n, &my_netif);
155 assert(n == &my_netif);
157 printf("dhcp_start()\n");
158 dhcp_start(&my_netif);
159 printf("dhcp started\n");
161 while (!netif_is_up(&my_netif))
163 printf("Network interface is up.\n");
165 printf("IP: "); print_ip(&my_netif.ip_addr); printf("\n");
166 printf("GW: "); print_ip(&my_netif.gw); printf("\n");