Defining a structure in a c socket program

data_size = recvfrom(sock_raw , buffer , 1024, 0 , &saddr , (socklen_t*)&saddr_size); 

here is the recvfrom function where I want to create a struct to 'saddr' and 'saddr_size', which is declared in main () as follows

 struct sockaddr saddr; int saddr_size; saddr_size = sizeof saddr; 

and instead of the buffer mentioned in the api () entry below, I have to use a structural variable.

 int cont= write(logfile,buffer,data_size); 

My question is: below I used struct.Is is this a way to define a structure for the following fields? Is this announced correctly? if not, please someone help me fix this.

 struct data{ unsigned char buffer[1024]; unsigned long int saddr; // struct sockaddr saddr; int saddr_size; }; 
+6
source share
1 answer
 struct data { unsigned char buffer[1024]; struct sockaddr saddr; socklen_t saddr_size; }; 
+1
source

Source: https://habr.com/ru/post/958443/


All Articles