int main (int argc, char *argv[]) { int soc = -1, acc; uint8_t buf[65536]; ssize_t len; if (microps_init(¶m) == -1) { goto ERROR; } soc = tcp_api_open(); if (soc == -1) { goto ERROR; } if (tcp_api_bind(soc, hton16(7)) == -1) { goto ERROR; } tcp_api_listen(soc); acc = tcp_api_accept(soc); if (acc == -1) { goto ERROR; } fprintf(stderr, "accept success, soc=%d, acc=%d\n", soc, acc); while (1) { len = tcp_api_recv(acc, buf, sizeof(buf)); if (len <= 0) { break; } hexdump(stderr, buf, len); tcp_api_send(acc, buf, len); } tcp_api_close(acc); /* ip_addr_t peer_addr; uint16_t peer_port; ip_addr_pton("72.21.215.232", &peer_addr); peer_port = hton16(80); tcp_api_connect(soc, &peer_addr, peer_port); strcpy(buf, "GET / HTTP/1.1\r\nHost: localhost\r\nConnection: Close\r\n\r\n"); tcp_api_send(soc, (uint8_t *)buf, strlen(buf)); while (1) { len = tcp_api_recv(soc, (uint8_t *)buf, sizeof(buf)); //fprintf(stderr, "len: %ld\n", len); if (len <= 0) { break; } //hexdump(stderr, buf, len); } */ tcp_api_close(soc); microps_cleanup(); return 0; ERROR: if (soc != -1) { tcp_api_close(soc); } microps_cleanup(); return -1; }
int microps_init (void) { if (ethernet_init() == -1) { goto ERROR; } if (slip_init() == -1) { goto ERROR; } if (arp_init() == -1) { goto ERROR; } if (ip_init() == -1) { goto ERROR; } if (icmp_init() == -1) { goto ERROR; } if (udp_init() == -1) { goto ERROR; } if (tcp_init() == -1) { goto ERROR; } return 0; ERROR: microps_cleanup(); return -1; }