secondary cache feature in vm.
[minix.git] / lib / libc / ip / getsockname.c
blobd3c9d7d71e245610b01ceb90046d62b44192575b
1 /*
3 getsockname()
5 from socket emulation library for Minix 2.0.x
7 */
10 #include <errno.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <sys/ioctl.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
17 #include <net/gen/in.h>
18 #include <net/gen/tcp.h>
19 #include <net/gen/tcp_io.h>
20 #include <net/gen/udp.h>
24 #define DEBUG 0
28 getsockname...
30 int getsockname(int fd, struct sockaddr *_RESTRICT address,
31 socklen_t *_RESTRICT address_len)
33 nwio_tcpconf_t tcpconf;
34 socklen_t len;
35 struct sockaddr_in sin;
37 #ifdef DEBUG
38 fprintf(stderr,"mnx_getsockname: ioctl fd %d.\n", fd);
39 #endif
40 if (ioctl(fd, NWIOGTCPCONF, &tcpconf)==-1) {
41 #ifdef DEBUG
42 fprintf(stderr,"mnx_getsockname: error %d\n", errno);
43 #endif
44 return (-1);
46 #ifdef DEBUG1
47 fprintf(stderr, "mnx_getsockname: from %s, %u",
48 inet_ntoa(tcpconf.nwtc_remaddr),
49 ntohs(tcpconf.nwtc_remport));
50 fprintf(stderr," for %s, %u\n",
51 inet_ntoa(tcpconf.nwtc_locaddr),
52 ntohs(tcpconf.nwtc_locport));
53 #endif
55 addr->sin_addr.s_addr = tcpconf.nwtc_remaddr ;
56 addr->sin_port = tcpconf.nwtc_locport;
58 memset(&sin, '\0', sizeof(sin));
59 sin.sin_family= AF_INET;
60 sin.sin_addr.s_addr= tcpconf.nwtc_locaddr ;
61 sin.sin_port= tcpconf.nwtc_locport;
63 len= *address_len;
64 if (len > sizeof(sin))
65 len= sizeof(sin);
66 memcpy(address, &sin, len);
67 *address_len= len;
69 return 0;