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.
21 #include "netif/etharp.h"
22 #include <lwip-util.h>
23 #include "lwip/dhcp.h"
25 #define GETOPT_LIST_END { 0, 0, 0, 0 }
33 /* Network interface variables */
34 ip_addr_t ipaddr, netmask, gw;
36 /* Set network address variables */
38 IP4_ADDR(&gw, 192,168,0,1);
39 IP4_ADDR(&ipaddr, 192,168,0,2);
40 IP4_ADDR(&netmask, 255,255,255,0);
43 struct netif my_netif;
44 extern err_t ankhif_init(struct netif*);
46 static ankh_config_info cfg = { 1024, L4_INVALID_CAP, L4_INVALID_CAP, "" };
49 static void do_lookup(char *hostname)
52 struct hostent *h = gethostbyname(hostname);
54 printf("gethostbyname(%s): %s\n", hostname, h ? "SUCCESS" : "FAILED");
56 i.addr = *(u32_t*)h->h_addr_list[0];
57 printf(" h_name: '%s'\n", h->h_name);
58 printf(" --> "); lwip_util_print_ip(&i); printf("\n");
63 static void dns_test(void)
65 do_lookup("os.inf.tu-dresden.de");
66 do_lookup("www.heise.de");
67 do_lookup("www.twitter.com");
68 do_lookup("www.tudos.org");
69 do_lookup("www.ifsr.de");
70 do_lookup("www.dynamo-dresden.de");
71 do_lookup("www.spiegel.de");
72 do_lookup("www.smoking-gnu.de");
73 do_lookup("www.fail.fx");
77 static void server(void)
80 struct sockaddr_in in, clnt;
81 in.sin_family = AF_INET;
82 in.sin_port = htons(3000);
83 in.sin_addr.s_addr = my_netif.ip_addr.addr;
85 int sock = socket(PF_INET, SOCK_STREAM, 0);
86 printf("socket created: %d\n", sock);
88 err = bind(sock, (struct sockaddr*)&in, sizeof(in));
89 printf("bound to addr: %d\n", err);
91 err = listen(sock, 10);
92 printf("listen(): %d\n", err);
96 socklen_t clnt_size = sizeof(clnt);
97 fd = accept(sock, (struct sockaddr*)&clnt, &clnt_size);
99 printf("Got connection from ");
100 lwip_util_print_ip((ip_addr_t*)&clnt.sin_addr); printf("\n");
102 err = read(fd, buf, sizeof(buf));
103 printf("Read from fd %d (err %d)\n", fd, err);
109 int main(int argc, char **argv)
114 l4_cap_idx_t c = pthread_getl4cap(pthread_self());
117 static struct option long_opts[] = {
118 {"bufsize", 1, 0, BUF_SIZE },
119 {"shm", 1, 0, SHM_NAME },
125 int opt = getopt_long(argc, argv, "b:s:", long_opts, &optind);
126 printf("getopt: %d\n", opt);
133 printf("buf size: %d\n", atoi(optarg));
134 cfg.bufsize = atoi(optarg);
137 printf("shm name: %s\n", optarg);
138 snprintf(cfg.shm_name, CFG_SHM_NAME_SIZE, "%s", optarg);
145 // Start the TCP/IP thread & init stuff
146 tcpip_init(NULL, NULL);
147 struct netif *n = netif_add(&my_netif,
148 &ipaddr, &netmask, &gw,
149 &cfg, // configuration state
150 ankhif_init, ethernet_input);
152 printf("netif_add: %p (%p)\n", n, &my_netif);
153 assert(n == &my_netif);
155 printf("dhcp_start()\n");
156 dhcp_start(&my_netif);
157 printf("dhcp started\n");
159 while (!netif_is_up(&my_netif))
161 printf("Network interface is up.\n");
163 printf("IP: "); lwip_util_print_ip(&my_netif.ip_addr); printf("\n");
164 printf("GW: "); lwip_util_print_ip(&my_netif.gw); printf("\n");