summaryrefslogtreecommitdiff
path: root/src/libexec/peerip.c
blob: 88b8fd40255d0c550d945aaf744b126a0ed1af3b (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(getpeername(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;
}