int main(void) { // link_head_init(&link_head); int a[5] = {1,2,3,4,5}; int i; node_t *tmp = NULL; for (i = 0; i < 5; i++) link_head = link_insert_e(link_head, a[i]); link_print(link_head); //tmp = link_search(link_head, 4); //printf("%d\n", tmp->val); tmp = link_remove(link_head, 3); link_node_free(tmp); link_print(link_head); link_destroy(link_head); return 0; }
int main(void) { int len = 0, i; node_t str[3] = {{1, NULL}, {2, NULL}, {3, NULL}}; node_t *link_head = NULL; init_head(&link_head); len = sizeof(str)/sizeof(str[0]); for (i = 0; i < len; i++) { if ((link_head = link_insert_one_b(link_head, str[i].num)) == NULL) { puts("error: main at link_insert_one_b"); exit(-1); } } link_print(link_head); //printf("asdf\n"); if ((link_head = link_reverse(link_head)) == NULL) { puts("error: main at link_insert_one_b"); exit(-1); } link_print(link_head); return 0; }
//exits - problem sending //0 - flow outside range, no link //dst_num - sent all ff int module_send_flow(struct fins_module *module, struct finsFrame *ff, uint32_t flow) { PRINT_DEBUG("Entered: module=%p, ff=%p, flow=%u", module, ff, flow); struct fins_module_table *mt = (struct fins_module_table *) module->data; PRINT_DEBUG("table: flows_num=%u", mt->flows_num); if (flow >= mt->flows_num) { PRINT_DEBUG("Exited: module=%p, ff=%p, flow=%u, ret=%d", module, ff, flow, 0); return 0; } PRINT_DEBUG("flow=%u, link_id=%u, link=%p", flow, mt->flows[flow].link_id, mt->flows[flow].link); if (mt->flows[flow].link_id == LINK_NULL) { PRINT_DEBUG("Exited: module=%p, ff=%p, flow=%u, ret=%d", module, ff, flow, 0); return 0; } if (mt->flows[flow].link == NULL) { PRINT_DEBUG("Exited: module=%p, ff=%p, flow=%u, ret=%d", module, ff, flow, 0); return 0; } #ifdef DEBUG link_print(mt->flows[flow].link); #endif if (mt->flows[flow].link->dsts_num == 0) { PRINT_DEBUG("Exited: module=%p, ff=%p, flow=%u, ret=%d", module, ff, flow, 0); return 0; } else { struct finsFrame *ff_clone; int i; for (i = 1; i < mt->flows[flow].link->dsts_num; i++) { ff_clone = cloneFinsFrame(ff); ff_clone->destinationID = mt->flows[flow].link->dsts_index[i]; module_to_switch(module, ff_clone); } ff->destinationID = mt->flows[flow].link->dsts_index[0]; module_to_switch(module, ff); PRINT_DEBUG("Exited: module=%p, ff=%p, flow=%u, ret=%d", module, ff, flow, mt->flows[flow].link->dsts_num); return mt->flows[flow].link->dsts_num; } }
static struct dhcp_context * dhcp_context_create(struct ifnet * ifp, int max_try, struct proc * procp, int * error_p) { struct dhcp_context * context = NULL; struct sockaddr_dl * dl_p; struct in_addr lo_addr; struct in_addr lo_mask; int error; struct sockaddr_in sin; /* get the hardware address from the interface */ dl_p = link_from_ifnet(ifp); if (dl_p == NULL) { printf("dhcp: can't get link address\n"); error = ENXIO; goto failed; } printf("dhcp: h/w addr "); link_print(dl_p); if (dl_p->sdl_type != IFT_ETHER) { printf("dhcp: hardware type %d not supported\n", dl_p->sdl_type); error = ENXIO; goto failed; } context = (struct dhcp_context *)kalloc(sizeof(*context)); if (context == NULL) { printf("dhcp: failed to allocate context\n"); error = ENOMEM; goto failed; } bzero(context, sizeof(*context)); /* get a socket */ error = socreate(AF_INET, &context->so, SOCK_DGRAM, 0); if (error != 0) { printf("dhcp: socreate failed %d\n", error); goto failed; } /* assign 127.0.0.1 to lo0 so that the bind will succeed */ lo_addr.s_addr = htonl(INADDR_LOOPBACK); lo_mask.s_addr = htonl(IN_CLASSA_NET); error = inet_aifaddr(context->so, "lo0", &lo_addr, &lo_mask, NULL); if (error != 0) { printf("dhcp: assigning loopback address failed %d\n", error); } /* enable reception of DHCP packets before an address is assigned */ snprintf(context->ifr.ifr_name, sizeof(context->ifr.ifr_name), "%s%d", ifp->if_name, ifp->if_unit); context->ifr.ifr_intval = 1; error = ifioctl(context->so, SIOCAUTOADDR, (caddr_t)&context->ifr, procp); if (error) { printf("dhcp: SIOCAUTOADDR failed: %d\n", error); goto failed; } dprintf(("dhcp: SIOCAUTOADDR done\n")); error = ifioctl(context->so, SIOCPROTOATTACH, (caddr_t)&context->ifr, procp); if (error) { printf("dhcp: SIOCPROTOATTACH failed: %d\n", error); goto failed; } dprintf(("dhcp: SIOCPROTOATTACH done\n")); /* bind the socket */ sin.sin_len = sizeof(sin); sin.sin_family = AF_INET; sin.sin_port = htons(IPPORT_BOOTPC); sin.sin_addr.s_addr = INADDR_ANY; error = sobind(context->so, (struct sockaddr *)&sin); if (error) { printf("dhcp: sobind failed, %d\n", error); goto failed; } /* make it non-blocking I/O */ socket_lock(context->so, 1); context->so->so_state |= SS_NBIO; socket_unlock(context->so, 1); /* save passed-in information */ context->max_try = max_try; context->dl_p = dl_p; context->ifp = ifp; /* get a random transaction id */ context->xid = random(); return (context); failed: dhcp_context_free(context, procp); *error_p = error; return (NULL); }