blob: 542a88dd34486031d2ec7bc678dfdbb97dfc67e0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#include <stdio.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
int main(int argc,char *argv[]) {
struct sockaddr_in6 sa6;
unsigned int sl=sizeof(sa6);
char h[NI_MAXHOST], s[NI_MAXSERV];
if(getsockname(0,(struct sockaddr *)&sa6,&sl) == -1) return 1;
if(getnameinfo((struct sockaddr *)&sa6,sl,h,sizeof(h),s,sizeof(s),NI_NUMERICHOST|NI_NUMERICSERV)) return 2;
puts(h);
puts(s);
return 0;
}
|