int main(int argc, char **argv) { if(argc != 2){ printf("Must pass 1 argument!\n"); return -1; } char* test_array; test_array = argv[1]; printf("test_array is: %s\n", test_array); char* test_array_2; printf("length: %i\n", strlen(test_array)); test_array_2 = (char *) malloc(strlen(argv[1])); strncpy(test_array_2, argv[1], strlen(argv[1])); printf("test_array_2 is: %s\n", test_array_2); pack_char_array(&test_array_2); return 0; }
/* depending upon the connection type, assemble a service_reply_pkt and send it to the other side */ int send_service_reply_pkt(service_reply_pkt *srp, FDContext *fdc) { /* This will be the service_reply_pkt */ char netpkt[SREP_PKTSIZE_MAX]; /* The fields of the packet */ uint16_t req_status; struct in_addr server_addr; uint16_t port; uint32_t num_files_32 = 0; uint64_t num_files_64 = 0; char capacity_free_ACD[MAX_ASCII_CODED_DECIMAL_LENGTH]; int ret = -1; ASSERT(fdc->type != FDC_UNKNOWN); memset(netpkt, 0, SREP_PKTSIZE_MAX); /* get the right sized quantities I need depending upon what the client needs. Ensure to convert it to network byte order here too. */ req_status = srp->req_status; req_status = host_uint16_t_order_to_network_uint16_t_order(req_status); server_addr = srp->server_addr; server_addr.s_addr = host_uint32_t_order_to_network_uint32_t_order(server_addr.s_addr); port = srp->port; port = host_uint16_t_order_to_network_uint16_t_order(port); switch(fdc->type) { case FDC_32: num_files_32 = srp->num_files; num_files_32 = host_uint32_t_order_to_network_uint32_t_order(num_files_32); break; case FDC_64: num_files_64 = srp->num_files; num_files_64 = host_uint64_t_order_to_network_uint64_t_order(num_files_64); break; default: Server::Log("service_reply_pkt type conversion error!"); return NET_WRITE_FAIL; break; } memmove(capacity_free_ACD, srp->capacity_free_ACD, MAX_ASCII_CODED_DECIMAL_LENGTH); /* Assemble the packet according to what type of connection it is. Then send it. */ switch(fdc->type) { case FDC_32: pack_uint16_t(netpkt, SREP32_req_status, req_status); pack_in_addr(netpkt, SREP32_server_addr, server_addr); pack_uint16_t(netpkt, SREP32_port, port); pack_uint32_t(netpkt, SREP32_num_files, num_files_32); pack_char_array(netpkt, SREP32_capacity_free_ACD, capacity_free_ACD, MAX_ASCII_CODED_DECIMAL_LENGTH); ret = net_write(fdc->fd, netpkt, SREP_PKTSIZE_32); break; case FDC_64: pack_uint16_t(netpkt, SREP64_req_status, req_status); pack_in_addr(netpkt, SREP64_server_addr, server_addr); pack_uint16_t(netpkt, SREP64_port, port); pack_uint64_t(netpkt, SREP64_num_files, num_files_64); pack_char_array(netpkt, SREP64_capacity_free_ACD, capacity_free_ACD, MAX_ASCII_CODED_DECIMAL_LENGTH); ret = net_write(fdc->fd, netpkt, SREP_PKTSIZE_64); break; default: Server::Log("service_reply_pkt type packing error!"); return NET_WRITE_FAIL; break; } if (ret < 0) { return NET_WRITE_FAIL; } return NET_WRITE_OK; }