summaryrefslogtreecommitdiff
path: root/src/libexec/sockip.c
blob: f1f048084560d810eb4aa83689cf6d5491fb0ada (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <stdlib.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(argc>1?atoi(argv[1]):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;
}