c - Using inet_ntop from libevent -


i implement echo server given in libevent book.

i modify accept_conn_cb function server prints ipv4 address of newly created connection (in decimal dot notation). following callback

static void accept_conn_cb(   struct evconnlistener *listener,   evutil_socket_t fd,    struct sockaddr *address,    int socklen,   void *ctx) {    char ipaddress[inet_addrstrlen];     struct sockaddr_in * saddr_in = (struct sockaddr_in *) &address;     if (!inet_ntop(af_inet, &(saddr_in->sin_addr), ipaddress, inet_addrstrlen))       puts("couldn't retrieve ipv4 address");     printf("a new connection established %s\n", ipaddress);     /* ... */ 

when compile , run it prints follwoing strange addresses:

a new connection established 252.127.0.0 or

a new connection established 253.127.0.0 or

a new connection established 255.127.0.0

no matter machine connect. use telnet testing connections.

i have written version of echo server written in pure c (without libevent).when run it returns right address.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -