(E-Mail Removed) wrote:
> My idea is like this:
> struct sockaddr_in cli_addr;
> .........
>
> clilen = sizeof(cli_addr);
> newsockfd = accept(sockfd,(struct sockaddr *) &cli_addr,
> &clilen);
> char addr_buf[16];
>
> addr_buf= inet_ntop (AF_INET, ( const void
> *)&cli_addr.sin_addr.s_addr,addr_buf,16);
>
> Then I thought client's ip address is stored in addr_buf , but it
> doesnn't work due to complie error ,"incompatible types in assignment"
> , Is there anything wrong? I'm confused...
>
You can't assign to an array (it isn't an lvalue). The best way to
express it is:
if (inet_ntop (AF_INET, &cli_addr.sin_addr, addr_buf,16)) {
/* Here inet_ntop has been successful */
}
else {
/* Here inet_ntop has been unsuccessful */
}
Robert