Reputation: 286
data_size = recvfrom(sock_raw , buffer , 1024, 0 , &saddr ,
(socklen_t*)&saddr_size);
here is a recvfrom function, where i want to create a struct to 'saddr' and 'saddr_size' which is declared in the main() as follows
struct sockaddr saddr;
int saddr_size;
saddr_size = sizeof saddr;
and instead of buffer mentioned in the below write() api i have to use the struct variable.
int cont= write(logfile,buffer,data_size);
My question is: Below i have used structure.Is this the way to define struct for the following fields? Is it declared correctly? if not please somebody guide me to correct it.
struct data{
unsigned char buffer[1024];
unsigned long int saddr;
// struct sockaddr saddr;
int saddr_size;
};
Upvotes: 6
Views: 183
Reputation: 2282
struct data {
unsigned char buffer[1024];
struct sockaddr saddr;
socklen_t saddr_size;
};
Upvotes: 1