Sendto failed'; Error when using sendto-function, using a UDP-socket in C?

Up vote 0 down vote favorite share g+ share fb share tw.

I have a program which is FEC-encoding data, sending the data; receiving the data at another socket, and decoding the data. I get an error when the sendto-function is executed in the code attached below. More information about the sendto-function here: Link The return code of the error is '-1'.

What is the cause of this error and what should I change in the code in order to resolve it? Print-outs from the 'receiver': *** Sender -- socket created ***we have a client, and will sent message to server_addr ...server.. will receive messages.. sss *** Created server socket good. Server socket is 4 ***We have a server socket; and now we will try to bind it with the IP_ADDR-local host -- that we sent.. port nr 4783 & ip 127.0.0.1***Bind succeed.. Thread 1 Some lines of eperftool.

H #define PORT_NUM 4783 // Arbitrary port number for the server #define IP_ADDR "127.0.0.1" // IP address of server1 (*** HARDWIRED ***) #define SYMBOL_SIZE 1024 //todo..on a different position also #define MAX_K 1000 #define MAX_N 1500 Code of sender. C: /* $Id: sender. C 3 2011-03-03 10:48:54Z detchart $ */ /* * OpenFEC.org AL-FEC Library.

* (c) Copyright 2009-2011 INRIA - All rights reserved * Contact: vincent. [email protected] * * This software is governed by the CeCILL-C license under French law and * abiding by the rules of distribution of free software. You can use, * modify and/ or redistribute the software under the terms of the CeCILL-C * license as circulated by CEA, CNRS and INRIA at the following URL * "http://www.cecill.

Info". * * As a counterpart to the access to the source code and rights to copy, * modify and redistribute granted by the license, users are provided only * with a limited warranty and the software's author, the holder of the * economic rights, and the successive licensors have only limited * liability. * * In this respect, the user's attention is drawn to the risks associated * with loading, using, modifying and/or developing or reproducing the * software by the user in light of its specific status of free software, * that may mean that it is complicated to manipulate, and that also * therefore means that it is reserved for developers and experienced * professionals having in-depth computer knowledge.

Users are therefore * encouraged to load and test the software's suitability as regards their * requirements in conditions enabling the security of their systems and/or * data to be ensured and, more generally, to use and operate it in the * same conditions as regards security. * * The fact that you are presently reading this means that you have had * knowledge of the CeCILL-C license and that you accept its terms. */ /* AL-FEC extended performance evaluation tool */ #include "eperftool.

H" /* * local variables */ static void **encoding_symbols_tab; /* temporary symbol array needed by the FEC encoder */ of_status_t init_sender (void) { of_session_t *ses; /* pointer to a codec instance */ block_cb_t *blk; /* temporary pointer within the blk_cb_tab */ UINT32 sbn; /* block sequence number */ UINT32 k; /* k parameter for a given block. Warning, the last block might be shorter */ UINT32 n; /* n parameter for a given block. Warning, the last block might be shorter */ UINT32 esi; /* Encoding Symbol ID */ UINT32 src_idx; /* index for a source symbol in the orig_symb table */ UINT32 rep_idx; /* index for a repair symbol in the orig_symb table */ symbol_cb_t *src_symb_cb; /* pointer to a source symbol in the orig_symb table */ symbol_cb_t *rep_symb_cb; /* pointer to a repair symbol in the orig_symb table */ UINT32 tmp_max_k; /* temporary value for max_k */ UINT32 max_n_4_any_blk;/* maximum n value for any block */ #ifdef WIN32 QueryPerformanceCounter(&tv0); OF_PRINT(("init_start=%lI64f\n", (double)tv0.

QuadPart/(double)freq. QuadPart)) #else gettimeofday(&tv0, NULL); OF_PRINT(("init_start=%ld. %ld\n", tv0.

Tv_sec, tv0. Tv_usec)) #endif /* * determine the blocking structure, which requires to create a temporary FEC session. */ if (of_create_codec_instance(&ses, codec_id, OF_ENCODER, of_verbosity)!

= OF_STATUS_OK) { OF_PRINT_ERROR(("init_sender: ERROR: of_create_codec_instance() failed\n")) goto error; } if (codec_id == OF_CODEC_REED_SOLOMON_GF_2_M_STABLE) { if (of_set_control_parameter(ses, OF_RS_CTRL_SET_FIELD_SIZE, (void*)&rs_m_param, sizeof(rs_m_param))! = OF_STATUS_OK) { OF_PRINT_ERROR(("init_sender: ERROR: of_set_control_parameter() failed\n")) goto error; } } if (of_get_control_parameter(ses, OF_CTRL_GET_MAX_K, (void*)&max_k, sizeof(max_k))! = OF_STATUS_OK) { OF_PRINT_ERROR(("init_sender: ERROR: of_get_control_parameter() failed\n")) goto error; } if (of_get_control_parameter(ses, OF_CTRL_GET_MAX_N, (void*)&max_n, sizeof(max_n))!

= OF_STATUS_OK) { OF_PRINT_ERROR(("init_sender: ERROR: of_get_control_parameter() failed\n")) goto error; } if (of_release_codec_instance(ses)! = OF_STATUS_OK) { OF_PRINT_ERROR(("init_sender: ERROR: of_release_codec_instance() failed\n")) goto error; } /* * determine the practical maximum k and n parameters, taking into * account the code/codec limitations and the desired code_rate. * The idea is to have max_k maximum, given max_n and code_rate, for * optimal erasure recovery performances.

*/ tmp_max_k = (UINT32)floor((double)max_n * code_rate); max_k = min(tmp_max_k, max_k); max_n = min((UINT32)((double)max_k / code_rate), max_n); /* we can now compute the required blocking structure */ of_compute_blocking_struct(max_k, object_size, symbol_size, &bs); tot_nb_blocks = bs. Nb_blocks; /* * adjust tot_nb_encoding_symbols and tot_nb_encoding_symbols variables, now we know * the exact blocking structure. */ tot_nb_encoding_symbols = (bs.

I * (int)floor((double)(bs. A_large) / code_rate)) + ((bs. Nb_blocks - bs.

I) * (int)floor((double)(bs. A_small) / code_rate)); ASSERT(tot_nb_encoding_symbols sbn = sbn; blk->k = k; blk->n = n; blk->first_src_symbol_idx = src_idx; blk->first_repair_symbol_idx = rep_idx; blk->is_decoded = false; blk->nb_symbols_received = 0; OF_TRACE_LVL(1, ("init_sender: block: sbn=%d, k=%d, n=%d, first_src_symbol_idx=%d, 1st_rep_symbol_idx=%d\n", sbn, blk->k, blk->n, blk->first_src_symbol_idx, blk->first_repair_symbol_idx)) /* init source symbols control block */ for (esi = 0; esi esi = esi; src_symb_cb->sbn = sbn; } /* and init repair symbols control block */ for (esi = k; esi esi = esi; rep_symb_cb->sbn = sbn; } } /* * allocate the table containing the various symbols of a block. This table * is allocated once and reused by all blocks of the object, with pointers to * different symbols of course, for encoding purposes.

*/ if (!(encoding_symbols_tab = (void**)calloc(max_n_4_any_blk, sizeof(void*)))) { OF_PRINT_ERROR(("init_sender: ERROR: out of memory\n")) goto no_mem; } #ifdef WIN32 QueryPerformanceCounter(&tv1); OF_PRINT(("init_end=%I64f init_time=%I64f\n", (double)tv1. QuadPart / (double)freq. QuadPart, (double)(tv1.

QuadPart-tv0. QuadPart) / (double)freq. QuadPart )) #else gettimeofday(&tv1, NULL); timersub(&tv1, &tv0, &tv_delta); OF_PRINT(("init_end=%ld.

%ld init_time=%ld. %06ld\n", tv1. Tv_sec, tv1.

Tv_usec, tv_delta. Tv_sec, tv_delta. Tv_usec)) #endif //INIT SENDER SOCKET // >>> Step #1 >> Step #2 k; n = blk->n; /* don't forget to initialize the encoding symbol tab, used by the * FEC codec during encoding, since we cannot use the orig_symb table * where the source/repair symbols of a block are not sequential :-( */ for (esi = 0; esi first_src_symbol_idx + esi); } for (; esi first_repair_symbol_idx + (esi - k)); } /* * create the codec instance and initialize it accordingly.

* The case of a parity check matrix given in a file is handled * differently... */ #ifdef OF_USE_LDPC_FROM_FILE_CODEC if (codec_id == OF_CODEC_LDPC_FROM_FILE_ADVANCED) { if (of_create_codec_instance(&ses, codec_id, OF_ENCODER, of_verbosity)! = OF_STATUS_OK) { OF_PRINT_ERROR(("ERROR: of_create_codec_instance() failed for codec_id %d\n", codec_id)) goto error; } of_ldpc_ff_parameters_t params; params. Encoding_symbol_length = symbol_size; params.

Pchk_file = ldpc_matrix_file_name; if (of_set_fec_parameters(ses, (of_parameters_t*)¶ms)! = OF_STATUS_OK) { OF_PRINT_ERROR(("ERROR: of_set_fec_parameters() failed for codec_id %d\n", codec_id)) goto error; } k = params. Nb_source_symbols; n = params.

Nb_source_symbols + params. Nb_repair_symbols; } else #endif { ses = create_and_init_codec_instance(codec_id, OF_ENCODER, k, n, blk); if (ses == NULL) { OF_PRINT_ERROR(("ERROR: create_and_init_codec_instance() failed for codec_id %d/OF_ENCODER\n", codec_id)) goto error; } } /* * perform encoding and finally release the FEC codec instance. */ for (esi = k; esi >> Step #3 >> Step #1 >> Step #2 >> Step #3.

If retcode == -1: check errno. – wildplasser Mar 25 at 15:20 Thanks! I also found out that suggestion elsewhere after posting.

Now, I get 'errno is Address family not supported by protocol'; and will Google that error. It should be quite easy to solve. – Anders Branderud Mar 25 at 15:28 Using errno I found 'Address family not supported by protocol'' .

The code in the top of sender. C related to server_addr wasn't used -it was only local'. The variable server_addr was mistakenly initialized again without setting 'sin_family', etc => error I moved the following code in the file and now it is working: // Fill-in server1 socket's address information server_addr.sin_family = AF_INET; // Address family to use server_addr.sin_port = htons(PORT_NUM); // Port num to use server_addr.sin_addr.s_addr = inet_addr(IP_ADDR); // IP address to use – Anders Branderud Mar 25 at 15:38.

Include #include #include ... retcode = some_system_call(...); if (retcode == -1) { int err = errno; fprintf(stderr, "*** ERROR - bind() failed:%d(%s)\n" , err, strerror(err) ); exit(EXIT_FAILURE); } BTW: there is also perror().

Thanks! As seen in my reply to the comment above I did that recently, and got ''Address family not supported by protocol'. After receiving this diagnos I easily solved the problem.

– Anders Branderud Mar 25 at 15:40 1 A few comments 1) don't cast the return value of malloc() et.al. 2) don't use exit(-1) 3) print diagnostic output to stderr, not stdout. 4) If you have stdint.

H: use it. When not: the UINT32 will probably do fine for the time being. – wildplasser Mar 25 at 15:51.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions