- #1
James889
- 192
- 1
Hi,
I'm currently trying to implement a simple client server program in C.
Needless to say i ran into troubles, and being a novice, i turned here for some advice.
I have a function to print the connecting peers address. I don't even know if this is the right way of doing it.
For some reason this function dumps core.
I'm currently trying to implement a simple client server program in C.
Needless to say i ran into troubles, and being a novice, i turned here for some advice.
I have a function to print the connecting peers address. I don't even know if this is the right way of doing it.
For some reason this function dumps core.
Code:
char * print_peer(struct addrinfo *client) {
if(client == NULL)
exit();
void *ptr = malloc(INET_ADDRSTRLEN);
struct addrinfo *p = client;
for (; p != NULL; p = p->ai_next) {
if(p->ai_family == AF_INET){
inet_ntop(AF_INET,&(p->ai_addr),ptr,INET_ADDRSTRLEN);
break;
}
}
return ptr;
}