|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Mar 2009
Messaggi: 753
|
[c] socket Linux - getpeername()
scusate ma ho una roba che non capisco stasera....
io ho un client che si connette e il mio server, il quale mi ritorna da accept() con un socket connesso al client con IP 192.168.0.2. Ora io voglio un stringa char con l'indirizzo del client. Per far questo solitamente uso getpeername(sock,clientaddr,&clientaddr_len) dove clientaddr è *struct sockaddr, ok? questa viene riempita con le info sul client, poi dato che sto usando AF_INET come dominio... faccio così: Codice:
s = (struct sockaddr_in*)clientaddr; // AF_INET domain strncpy(ipstr,inet_ntoa(s->sin_addr),INET4_ADDRSTRLEN); grazie dei suggerimenti. |
![]() |
![]() |
![]() |
#2 | |
Senior Member
Iscritto dal: Dec 2005
Città: Istanbul
Messaggi: 1817
|
Quote:
__________________
One of the conclusions that we reached was that the "object" need not be a primitive notion in a programming language; one can build objects and their behaviour from little more than assignable value cells and good old lambda expressions. —Guy Steele |
|
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Mar 2009
Messaggi: 753
|
![]() Codice:
clientaddr = sizeof(clientaddr); grazie. ![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 09:52.